-
Notifications
You must be signed in to change notification settings - Fork 38
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
Handle Statistics and SparseArrays as extensions #286
Conversation
The Aqua formatting error on v1.6 should be fixed by #287 |
Locally, I can get around the abstract type KronStyle end
struct SparseKronStyle <: KronStyle end
struct UnknownKronStyle <: KronStyle end
KronStyle(A) = UnknownKronStyle()
kron(A::RectDiagonalFill, B::RectDiagonalFill) =
maybesparsekron(KronStyle(A), KronStyle(B), A, B)
function maybesparsekron(::UnknownKronStyle, ::UnknownKronStyle, A::AbstractMatrix, B::AbstractMatrix)
invoke(kron, Tuple{AbstractMatrix, AbstractMatrix}, A, B)
end
FillArrays.KronStyle(A::RectDiagonalFill) = FillArrays.SparseKronStyle()
function FillArrays.maybesparsekron(::SparseKronStyle, ::SparseKronStyle, A, B)
kron(sparse(A), sparse(B))
end I've updated the code in https://github.com/jishnub/FillArrays.jl/tree/kronextension But, this is a more serious variant of type-piracy, where behavior is altered based on whether a library is loaded (and is potentially also a regression, as currently working code may lead to OOM errors if one doesn't load |
The |
In fact, one should really go with a lazy Kronecker product, as in |
Codecov Report
@@ Coverage Diff @@
## master #286 +/- ##
==========================================
- Coverage 99.88% 0.00% -99.89%
==========================================
Files 5 7 +2
Lines 851 868 +17
==========================================
- Hits 850 0 -850
- Misses 1 868 +867
... and 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
How do we proceed here? Did you mean to release one version with a deprecation only, and then a subsequent version with the Pkg extension stuff like here? An alternative would be to release v2, which may take a while to propagate through the ecosystem. |
Technically for SEMVAR: if we wanted to drop support we could deprecate in a BUT: I take the view that a change is non-breaking if it doesn't break anything. @jishnub why was |
How about this: just have # in FillArrays.jl
kron(A::RectDiagonalFill, B::RectDiagonalFill) = kron_fill(A, B)
kron_fill(A, B) = error("Load SparseArrays.jl")
# in FillArraysSparseArraysExt.jl
kron_fill(A::RectDiagonalFill, B::RectDiagonalFill) = kron(sparse(A), sparse(B)) |
This would be breaking, though. The hack-y solution that I had presented above was trying to work around this breakage. |
It's not really "breaking" as downstream one just has to do |
Edit: the current design in this PR seems fine to me. julia> kron(E, E)
4×4 Matrix{Float64}:
1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0
julia> using SparseArrays
julia> kron(E, E)
4×4 SparseMatrixCSC{Float64, Int64} with 4 stored entries:
1.0 ⋅ ⋅ ⋅
⋅ 1.0 ⋅ ⋅
⋅ ⋅ 1.0 ⋅
⋅ ⋅ ⋅ 1.0 The method is deprecated anyway, and if this impacts anyone, they may be warned against using this. |
Oh, I missed your update @jishnub. If everyone is happy with the last but one commit, I can revert the "error or load" commit. |
This reverts commit 7c7a333.
I think this should be good to merge? |
Do I understand right that |
Yes, that's the status quo |
I went ahead and just did it. The only "disturbing" thing is that
kron
method which is not an extension, strictly speaking. So it would be great to resolve it and make the dependencies weak.