Skip to content

MAINT Remove -Wcpp warnings when compiling arrayfuncs #25415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"sklearn.utils._typedefs",
"sklearn.utils._vector_sentinel",
"sklearn.utils._weight_vector",
"sklearn.utils.arrayfuncs",
"sklearn.utils.murmurhash",
)

Expand Down Expand Up @@ -439,7 +440,7 @@ def check_package_status(package, min_version):
"utils": [
{"sources": ["sparsefuncs_fast.pyx"], "include_np": True},
{"sources": ["_cython_blas.pyx"]},
{"sources": ["arrayfuncs.pyx"], "include_np": True},
{"sources": ["arrayfuncs.pyx"]},
{
"sources": ["murmurhash.pyx", join("src", "MurmurHash3.cpp")],
"include_dirs": ["src"],
Expand Down
22 changes: 3 additions & 19 deletions sklearn/utils/arrayfuncs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,22 @@ Small collection of auxiliary functions that operate on arrays

"""

cimport numpy as cnp
import numpy as np
from cython cimport floating
from libc.math cimport fabs
from libc.float cimport DBL_MAX, FLT_MAX

from ._cython_blas cimport _copy, _rotg, _rot

ctypedef cnp.float64_t DOUBLE


cnp.import_array()


def min_pos(cnp.ndarray X):
def min_pos(const floating[:] X):
"""Find the minimum value of an array over positive values

Returns the maximum representable value of the input dtype if none of the
values are positive.
"""
if X.dtype == np.float32:
return _min_pos[float](<float *> X.data, X.size)
elif X.dtype == np.float64:
return _min_pos[double](<double *> X.data, X.size)
else:
raise ValueError('Unsupported dtype for array X')


cdef floating _min_pos(floating* X, Py_ssize_t size):
cdef Py_ssize_t i
cdef floating min_val = FLT_MAX if floating is float else DBL_MAX
for i in range(size):
for i in range(X.size):
if 0. < X[i] < min_val:
min_val = X[i]
return min_val
Expand All @@ -46,7 +30,7 @@ cdef floating _min_pos(floating* X, Py_ssize_t size):
# n = rows
#
# TODO: put transpose as an option
def cholesky_delete(cnp.ndarray[floating, ndim=2] L, int go_out):
def cholesky_delete(const floating[:, :] L, int go_out):
cdef:
int n = L.shape[0]
int m = L.strides[0]
Expand Down