-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
In BLAS overrides, remove restriction to StridedMatrix #25247
Comments
Why is your custom type not a |
Because it’s a |
That method you defined is going to give you wrong answers for quite a few matrices. For example, try it with |
One could a check that EDIT: I think I mean |
Unfortunately there's some confusion about what A = view(rand(5,5), [1,2,5], :)
b = vec(A)
julia> stride(b, 1)
1 |
@dlfivefifty, want to tackle that for 1.0? 😄 |
Sure, I'm happy to put together a pull request. When's the deadline? |
Last week, but we're still wrapping some things up. This is a fairly non-disruptive change as I understand it though, so it could probably sneak into the alpha period. |
OK. While I'm at it I might also include some of the missing routines ( https://github.com/JuliaMatrices/BandedMatrices.jl/blob/master/src/lapack.jl |
One issue here is with |
Made a comment about this in JuliaLinearAlgebra/IterativeSolvers.jl#184. For new array types, it is much more demanding to support general broadcasting so I think we should keep |
Yes I did a quick timing of |
Modulo benchmark details, |
Maybe it’s because |
|
Yes, but unless I'm missing something (e.g., being able to tell that a function is pure so can be evaluated only once for the zero entries) it can't know the sparsity pattern without evaluating the broadcast at every single entry. FYI here is my test: julia> x = SparseVector(1000, [1,2,3], [1.,2.,3.]);
julia> y = rand(1000);
julia> using BenchmarkTools
julia> function foo(x, y)
y .+= 2.0 .* x
end
foo (generic function with 1 method)
julia> @btime foo(x,y);
3.293 μs (0 allocations: 0 bytes)
julia> @btime BLAS.axpy!(2.0, x, y);
26.386 ns (0 allocations: 0 bytes)
EDIT: It also has the same behaviour when julia> y = zeros(1000);
julia> @btime foo(x,y);
3.343 μs (0 allocations: 0 bytes)
julia> @btime BLAS.axpy!(2.0, x, y);
24.042 ns (0 allocations: 0 bytes) |
Sparse broadcast roughly assumes purity, allowing (with a bit of additional magic for scalar arguments) operation only over the union of the patterns of broadcast's array arguments :). Solution to the benchmark mystery: The destination argument being dense, the broadcast benchmark hits the generic |
Huh, that’s interesting. If I’m allowed to assume purity that would be useful for broadcast for |
Essentially that assuming the necessary weak form of purity is extremely useful when working with higher order functions over sparse and structured objects, whereas use cases that break that assumption seem marginal.
Absolutely :). |
Definitions such as
gemv!
(https://github.com/JuliaLang/julia/blob/master/base/linalg/blas.jl#L553) restrict toStridedVecOrMat
. This prevents user-defined types from calling these functions.I think this restriction is unnecessary as a user
AbstractMatrix
which overrides the (as-of-yet not explicitly defined) strided matrix "interface" ofunsafe_convert(::Type{Ptr{T}},A)
, andstride
should be able to callgemv!
.To overcome this restriction, I end up having to copy and paste Base's code to make my own
gemv!
:https://github.com/JuliaMatrices/BlockBandedMatrices.jl/blob/master/src/lapack.jl#L19
This is not too burdensome but seems unnecessary.
The text was updated successfully, but these errors were encountered: