-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Methods defined for StridedArrays vs. AbstractArrays #1276
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
Comments
This has to do with the efficiency of linear indexing. A loop like this is a disaster for sparse arrays (though |
It might be a disaster for sparse arrays, but it will work fine for many other types of arrays (like JuliaData's DataVec). For sparse arrays and other formats where indexing like this is inefficient, you'll want to define specific methods to cover these anyway. |
Also, another problem with a StridedArray is that you cannot have a type that inherits from it because it is a Union and not an abstract type. That's where issue #987 comes in. |
I think that's mostly correct, Viral. I did find a few more functions that (I think) could be generalized more: array.jl:1159:function find(testf::Function, A::StridedArray)
array.jl:1173:function find(A::StridedArray)
array.jl:1189:findn(A::StridedVector) = find(A)
array.jl:1191:function findn(A::StridedMatrix)
array.jl:1219:function findn{T}(A::StridedArray{T})
array.jl:1237:function findn_nzs{T}(A::StridedMatrix{T})
array.jl:1257:function nonzeros{T}(A::StridedArray{T})
array.jl:1443:function sum{T}(A::StridedArray{T})
array.jl:1454:function sum_kbn{T<:FloatingPoint}(A::StridedArray{T})
array.jl:1476:function cumsum_kbn{T<:FloatingPoint}(v::StridedVector{T})
array.jl:1498:function cumsum_kbn{T<:FloatingPoint}(A::StridedArray{T}, axis::Integer)
array.jl:1569:function amap(f::Function, A::StridedArray, axis::Integer)
linalg.jl:3:function scale!{T<:Number}(X::StridedArray{T}, s::Real)
linalg.jl:152:function linreg{T<:Number}(X::StridedVecOrMat{T}, y::Vector{T})
statistics.jl:76:function hist(v::StridedVector, nbins::Integer)
statistics.jl:98:function hist(A::StridedMatrix, nbins::Integer)
statistics.jl:107:function hist(v::StridedVector, edg::AbstractVector)
statistics.jl:124:function hist(A::StridedMatrix, edg::AbstractVector) |
Could you open a pull request with the ones that you think we can generalize? That should lead to a speedy resolution of this issue. |
Change several methods with StridedArray args to AbstractArray (#1276)
Closed by d443c81 |
) Stdlib: LinearAlgebra URL: https://github.com/JuliaLang/LinearAlgebra.jl.git Stdlib branch: master Julia branch: master Old commit: 1ce8426 New commit: 07725da Julia version: 1.13.0-DEV LinearAlgebra version: 1.12.0(Does not match) Bump invoked by: @jishnub Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaLang/LinearAlgebra.jl@1ce8426...07725da ``` $ git log --oneline 1ce8426..07725da 07725da Branch on `Bool` `alpha` in scaling `mul!` (#1286) 61e444d Fix exponentiation with immutable matrix (#1289) 77475c1 Fix `lmul!`/`rmul!` for 0-sized matrices (#1290) c3d35c0 Test for `versioninfo` with `ENV` variable (#1279) 830ea2f Fit broken matmul test (#1288) 222f7f2 Propagate inbounds in diagzero (#1285) e65e75c Clean up `herk_wrapper!` and add 5-arg tests (#1254) ece1962 `versioninfo`: simplify, improve type stability (#1274) 3e525a8 Speicalize `copy!` for triangular, and use `copy!` in `ldiv` (#1263) 763f19f Forward scaling `lmul!`/`rmul!` for `Tridiagonal` to bands (#1284) 2d27d1c Explicit loop in converting `Bidiagonal`/`Tridiagonal` to `Matrix` (#1283) 0671a7b Simplify small Bidiagonal-AbstractVecOrMat multiplication (#1278) a8fd121 Test for empty `Symmetric` and `BlasFlag.NONE` (#1280) 6e2de14 Remove bounds-checking in `Bidiagonal` `rdiv!` (#1281) 4a8fc62 Test for 5-arg `mul!` c437beb Test for empty `Symmetric` and `BlasFlag.NONE` 7a891e9 Test for `versioninfo` with `ENV` variable 84fd21b Test for `versioninfo` (#1276) 243efdb `AbstractQ` bugfix: define `Base.IteratorSize` (#1277) 6073f28 Ease inference in `Bidiagonal` divmul tests (#1273) 30cb5d6 Avoid copy in empty bidiag `ldiv!` (#1275) 5d3ef46 Skip symmetry check in converting Symmetric to SymTridiagonal (#1269) ae5385b Specialize `isreal` for banded matrices (#1271) 0a253be Explicit loop in `_iszero` for strided views (#1264) 3f46f5f `istril`/`istriu` for opposite triangularity (#1265) cd048eb Tests for `mul!` scaling with mismatched axes (#1266) 26db4c8 Restrict tests to `Number` eltypes 8b21ca6 Tests for `mul!` scaling with mismatched axes 9675c38 Fix minimum band for `UpperTriangular`/`Lowertriangular` aeeed7d Add unit triangular tests 3e1aaac Add banded tests 7fdfb3b Add tests d866014 istril/istriu for opposite triangularity 925acef Return view in `_diag` for `Bidiagonal` (#1258) b1bcca1 Branch on `Bool` `alpha` in diagonal matmul (#1256) e3e9987 `peakflops`: make `eltype` a static parameter of the method (#1253) 781eb5d `peakflops`: make the element type a static parameter of the method e53b50c use smaller matrix size in `peakflops` on 32-bit (#1255) 0c87d0d use smaller matrix size in `peakflops` on 32-bit 0cbf85f Check approx equality in bunchkaufman docstring (#1251) 5e53d12 Avoid accessing unset indices in symmetric copyto! (#1244) e64a3df fix dispatch to herk (#1247) bfdb742 Destination zeros from eltype in zero-length generic_matvecmul (#1241) 16dedb5 Remove redundant adjoint/transpose methods for Symmetric/Hermitian (#1245) 7f1dfe4 stop assuming that you can mutate data structures in other packages at precompile time (#1252) ``` Co-authored-by: jishnub <[email protected]>
…iaLang#58180) Stdlib: LinearAlgebra URL: https://github.com/JuliaLang/LinearAlgebra.jl.git Stdlib branch: master Julia branch: master Old commit: 1ce8426 New commit: 07725da Julia version: 1.13.0-DEV LinearAlgebra version: 1.12.0(Does not match) Bump invoked by: @jishnub Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaLang/LinearAlgebra.jl@1ce8426...07725da ``` $ git log --oneline 1ce8426..07725da 07725da Branch on `Bool` `alpha` in scaling `mul!` (JuliaLang#1286) 61e444d Fix exponentiation with immutable matrix (JuliaLang#1289) 77475c1 Fix `lmul!`/`rmul!` for 0-sized matrices (JuliaLang#1290) c3d35c0 Test for `versioninfo` with `ENV` variable (JuliaLang#1279) 830ea2f Fit broken matmul test (JuliaLang#1288) 222f7f2 Propagate inbounds in diagzero (JuliaLang#1285) e65e75c Clean up `herk_wrapper!` and add 5-arg tests (JuliaLang#1254) ece1962 `versioninfo`: simplify, improve type stability (JuliaLang#1274) 3e525a8 Speicalize `copy!` for triangular, and use `copy!` in `ldiv` (JuliaLang#1263) 763f19f Forward scaling `lmul!`/`rmul!` for `Tridiagonal` to bands (JuliaLang#1284) 2d27d1c Explicit loop in converting `Bidiagonal`/`Tridiagonal` to `Matrix` (JuliaLang#1283) 0671a7b Simplify small Bidiagonal-AbstractVecOrMat multiplication (JuliaLang#1278) a8fd121 Test for empty `Symmetric` and `BlasFlag.NONE` (JuliaLang#1280) 6e2de14 Remove bounds-checking in `Bidiagonal` `rdiv!` (JuliaLang#1281) 4a8fc62 Test for 5-arg `mul!` c437beb Test for empty `Symmetric` and `BlasFlag.NONE` 7a891e9 Test for `versioninfo` with `ENV` variable 84fd21b Test for `versioninfo` (JuliaLang#1276) 243efdb `AbstractQ` bugfix: define `Base.IteratorSize` (JuliaLang#1277) 6073f28 Ease inference in `Bidiagonal` divmul tests (JuliaLang#1273) 30cb5d6 Avoid copy in empty bidiag `ldiv!` (JuliaLang#1275) 5d3ef46 Skip symmetry check in converting Symmetric to SymTridiagonal (JuliaLang#1269) ae5385b Specialize `isreal` for banded matrices (JuliaLang#1271) 0a253be Explicit loop in `_iszero` for strided views (JuliaLang#1264) 3f46f5f `istril`/`istriu` for opposite triangularity (JuliaLang#1265) cd048eb Tests for `mul!` scaling with mismatched axes (JuliaLang#1266) 26db4c8 Restrict tests to `Number` eltypes 8b21ca6 Tests for `mul!` scaling with mismatched axes 9675c38 Fix minimum band for `UpperTriangular`/`Lowertriangular` aeeed7d Add unit triangular tests 3e1aaac Add banded tests 7fdfb3b Add tests d866014 istril/istriu for opposite triangularity 925acef Return view in `_diag` for `Bidiagonal` (JuliaLang#1258) b1bcca1 Branch on `Bool` `alpha` in diagonal matmul (JuliaLang#1256) e3e9987 `peakflops`: make `eltype` a static parameter of the method (JuliaLang#1253) 781eb5d `peakflops`: make the element type a static parameter of the method e53b50c use smaller matrix size in `peakflops` on 32-bit (JuliaLang#1255) 0c87d0d use smaller matrix size in `peakflops` on 32-bit 0cbf85f Check approx equality in bunchkaufman docstring (JuliaLang#1251) 5e53d12 Avoid accessing unset indices in symmetric copyto! (JuliaLang#1244) e64a3df fix dispatch to herk (JuliaLang#1247) bfdb742 Destination zeros from eltype in zero-length generic_matvecmul (JuliaLang#1241) 16dedb5 Remove redundant adjoint/transpose methods for Symmetric/Hermitian (JuliaLang#1245) 7f1dfe4 stop assuming that you can mutate data structures in other packages at precompile time (JuliaLang#1252) ``` Co-authored-by: jishnub <[email protected]>
There are many methods in array.jl and statistics.jl that are defined based on StridedArrays. It seems like most of these could be defined based on AbstractArrays instead. Here's one example:
This doesn't call any C code that requires an Array. It just does indexing. Is there a reason this can't be for an AbstractArray instead?
Issue #987 somewhat relates.
The text was updated successfully, but these errors were encountered: