Have strides return nothing on non-strided arrays#61807
Conversation
|
feels like it should be |
|
The issue is that sometimes whether an array is strided or not cannot be determined by the type. Here is an example when combining reshape and view: A = rand(4, 4)
r1 = reshape(view(A, 1:2, 1:2), 4)
r2 = reshape(view(A, 1:4, 1:2), 8)
typeof(r1) === typeof(r2)
strides(r2)
strides(r1) |
|
still, there really aren't many (any?) APIs in Base like this. the much stronger convention is value-or-error (see also: |
|
@nanosoldier |
|
I wasn't there but this change was already approved by triage in 2022 #30432 (comment) I'm running pkgeval to see if this change will break any packages. |
|
I think it's worth at least getting fresh eyes on it to confirm, 4 years later. I wasn't there either but to me, this is not a "julian" API. |
|
Would adding a new julia> using PythonCall
julia> y = ones(1000000);
julia> x = PyArray(copy(y));
julia> @time write(mktemp()[2], y)
0.002410 seconds (23 allocations: 1.609 KiB)
8000000
julia> @time write(mktemp()[2], x)
0.023997 seconds (24 allocations: 1.625 KiB)
8000000
julia> strides(y)
(1,)
julia> strides(x)
(1,)
|
|
in my (subjective) opinion, yes |
|
or: |
|
The package evaluation job you requested has completed - possible new issues were detected. Report summary❗ Packages that crashed253 packages crashed on the previous version too. ✖ Packages that failed20 packages failed only on the current version.
1054 packages failed on the previous version too. ✔ Packages that passed tests9 packages passed tests only on the current version.
5881 packages passed tests on the previous version too. ~ Packages that at least loaded1 packages successfully loaded only on the current version.
3696 packages successfully loaded on the previous version too. ➖ Packages that were skipped altogether898 packages were skipped on the previous version too. |
|
@nanosoldier |
|
The package evaluation job you requested has completed - possible new issues were detected. Report summary✖ Packages that failed3 packages failed only on the current version.
4 packages failed on the previous version too. ✔ Packages that passed tests1 packages passed tests only on the current version.
10 packages passed tests on the previous version too. ~ Packages that at least loaded2 packages successfully loaded on the previous version too. |
|
JuliaLang/LinearAlgebra.jl#1610 should fix the failing tests in pkgeval |
|
I don't mean to claim any authority on the matter beyond asserting my own opinions, but yes, I think #60964 is a nicer approach |
This PR changes
stridesandstrideto returnnothingwhen used on non-strided arrays, instead of throwing an error.This PR is a continuation of #30432
An alternative is #60964 which adds a new
try_stridesfunction instead of changingstrides