-
-
Notifications
You must be signed in to change notification settings - Fork 26k
FIX Add stride to y
in _ger_memview
#25323
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
Conversation
There was a missing `1` in the striding of `y` in `_ger_memview`. This adds it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Fortunately, tt seems that we don't use _ger_memview
in any code, only in test_cython_blas.py
.
Thanks for the quick review, Christian! 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you, @jakirkham
Note that in the case of one dimensional array, this stride information does not change anything as Fortran- and C-contiguity is identical. Still, it is nice for uniformity.
Thanks all! 🙏 For more context, perhaps this example makes the bug clearer? from libc.stdint cimport uint8_t
cpdef Py_ssize_t test1(uint8_t[::] a) nogil:
return a.strides[0]
cpdef Py_ssize_t test2(uint8_t[::1] a) nogil:
return a.strides[0] import numpy as np
a1 = np.arange(9, dtype="u1")
a2 = np.arange(27, dtype="u1")[::3]
test1(a1) # 1
test1(a2) # 3
test2(a1) # 1
test2(a2) # ValueError: ndarray is not C-contiguous So leaving the |
Good catch! I was unconscious of possibilities for no -continuous arrays! There are plenty of memoryviews' definitions and declarations (including but not limited to functions and methods' signatures) that aren't specific enough in scikit-learn's codebase then. I think we can open a meta-issue for referencing the problems and list such definitions and declarations. |
Note that scikit-learn's codebase will use non-contiguous memoryviews when the input is not guaranteed to be contiguous. |
There was a missing `1` in the striding of `y` in `_ger_memview`. This adds it.
There was a missing `1` in the striding of `y` in `_ger_memview`. This adds it.
There was a missing
1
in the striding ofy
in_ger_memview
. This adds it.For more context the increment of
y
(incy
) is1
belowscikit-learn/sklearn/utils/_cython_blas.pyx
Line 176 in b0e6ee4
Note
incy
followsy
in the signature definitionscikit-learn/sklearn/utils/_cython_blas.pyx
Lines 153 to 154 in b0e6ee4