-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support for Unitful sparse arrays? [feature request] #78
Comments
@geoffroyleconte Would anything break if we changed |
Probably not, but the factorization would not be accurate for complex matrices. I opened #79. I left However, with the example you provided I have this error ERROR: DimensionError: 0.0f0 s^2 and 1.0f0 s^4 are not dimensionally compatible.
Stacktrace:
[1] +(x::Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}} , y::Unitful.Quantity{Float32, 𝐓^4, U
nitful.FreeUnits{(s^4,), 𝐓^4, nothing}} )
@ Unitful C:\Users\Geoffroy Leconte\.julia\packages\Unitful\wRgqZ\src\quantities.jl:133
[2] macro expansion
@ C:\Users\Geoffroy Leconte\.julia\dev\LimitedLDLFactorizations\src\LimitedLDLFactorizations.jl:303 [inlined]
[3] macro expansion
@ .\simdloop.jl:77 [inlined]
[4] lldl_factorize!(S::LimitedLDLFactorizations.LimitedLDLFactorization{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnit
s{(s^2,), 𝐓^2, nothing}}, Int64, Vector{Int64}, Vector{Int64}} , T::SparseArrays.SparseMatrixCSC{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}, Int64} ; droptol::Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^
2,), 𝐓^2, nothing}} )
@ LimitedLDLFactorizations C:\Users\Geoffroy Leconte\.julia\dev\LimitedLDLFactorizations\src\LimitedLDLFactorizations.jl:301
[5] lldl(A::SparseArrays.SparseMatrixCSC{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}, Int6
4}, ::Type{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}} ; P::Vector{Int64}, memory::Int64, droptol::Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}} , α::Int64, α_increase_factor::Int64, check_tril::Bool)
@ LimitedLDLFactorizations C:\Users\Geoffroy Leconte\.julia\dev\LimitedLDLFactorizations\src\LimitedLDLFactorizations.jl:490
[6] lldl(A::SparseArrays.SparseMatrixCSC{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}, Int6
4}, ::Type{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}} )
@ LimitedLDLFactorizations C:\Users\Geoffroy Leconte\.julia\dev\LimitedLDLFactorizations\src\LimitedLDLFactorizations.jl:471
[7] lldl(A::SparseArrays.SparseMatrixCSC{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}, Int6
4}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ LimitedLDLFactorizations C:\Users\Geoffroy Leconte\.julia\dev\LimitedLDLFactorizations\src\LimitedLDLFactorizations.jl:493
[8] lldl(A::SparseArrays.SparseMatrixCSC{Unitful.Quantity{Float32, 𝐓^2, Unitful.FreeUnits{(s^2,), 𝐓^2, nothing}}, Int6
4})
@ LimitedLDLFactorizations C:\Users\Geoffroy Leconte\.julia\dev\LimitedLDLFactorizations\src\LimitedLDLFactorizations.jl:493
[9] top-level scope
@ REPL[17]:1 |
Thanks for this start! The MWE in #78 gets further with the code in this PR, but as you noted it fails on this line:
That code sequence is perplexing for data with units because the same location If I modified my MWE as follows to use the using SparseArrays: spdiagm
using LimitedLDLFactorizations: lldl
using Unitful: s
A = spdiagm(Float32.(1:3)*s^2) # unitful sparse array
Ta = eltype(A)
Tl = eltype(sqrt(oneunit(Ta)))
lldl(A, Tl) # fails That version fails on this line: I suspect that small modifications of the types in the struct might do it... |
The current code for
lldl
fails for Unitful sparse (or dense) arrays. MWE:Some of the
lldl
code usesNumber
which is general enough to include unitful values, such as here:LimitedLDLFactorizations.jl/src/LimitedLDLFactorizations.jl
Line 493 in 51eec8d
but then just a bit deeper into the code the types get restricted to
Real
, like here:LimitedLDLFactorizations.jl/src/LimitedLDLFactorizations.jl
Line 480 in 51eec8d
I realize that
Number
is general enough to include complex number types and perhaps you don't want to support those? (Though that could be useful too, right?) My Unitful values arereinterpret
able as real numbers, but currently not when stored in a sparse matrix: JuliaSparse/SparseArrays.jl#289I figure it's a long shot, but I thought I'd ask to see if there is any possibility of supporting more general
Number
types, especially Unitful values and maybe eventually complex values too? Since you have a pure Julia version, it seems like it would be possible!The text was updated successfully, but these errors were encountered: