Skip to content
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

Matrix division for SMatrix{m, n, BigFloat} #1069

Closed
hyrodium opened this issue Aug 4, 2022 · 1 comment · Fixed by #1071
Closed

Matrix division for SMatrix{m, n, BigFloat} #1069

hyrodium opened this issue Aug 4, 2022 · 1 comment · Fixed by #1071

Comments

@hyrodium
Copy link
Collaborator

hyrodium commented Aug 4, 2022

MWE:

julia> using StaticArrays

julia> M = @SMatrix rand(3,3)
3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.0208401  0.45567   0.110421
 0.918376   0.652122  0.399424
 0.821561   0.418753  0.730901

julia> M / M
3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 1.0          -0.0          -0.0
 1.24963e-16   1.0          -0.0
 8.33088e-17  -3.33235e-16   1.0

julia> N = @SMatrix rand(BigFloat, 3,3)
3×3 SMatrix{3, 3, BigFloat, 9} with indices SOneTo(3)×SOneTo(3):
 0.925296  0.56646   0.496179
 0.483511  0.669458  0.31921
 0.759881  0.802041  0.957391

julia> N / N
ERROR: setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] setindex!
    @ ~/.julia/dev/StaticArrays/src/MArray.jl:39 [inlined]
  [3] macro expansion
    @ ~/.julia/dev/StaticArrays/src/indexing.jl:66 [inlined]
  [4] _setindex!_scalar
    @ ~/.julia/dev/StaticArrays/src/indexing.jl:46 [inlined]
  [5] setindex!
    @ ~/.julia/dev/StaticArrays/src/indexing.jl:42 [inlined]
  [6] macro expansion
    @ ~/.julia/dev/StaticArrays/src/indexing.jl:357 [inlined]
  [7] _setindex!
    @ ~/.julia/dev/StaticArrays/src/indexing.jl:320 [inlined]
  [8] setindex!
    @ ~/.julia/dev/StaticArrays/src/indexing.jl:274 [inlined]
  [9] _solve
    @ ~/.julia/dev/StaticArrays/src/solve.jl:36 [inlined]
 [10] \
    @ ~/.julia/dev/StaticArrays/src/solve.jl:1 [inlined]
 [11] /(A::SMatrix{3, 3, BigFloat, 9}, B::SMatrix{3, 3, BigFloat, 9})
    @ LinearAlgebra ~/julia/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/generic.jl:1152
 [12] top-level scope
    @ REPL[5]:1

This is because A/B uses setindex internally, and the method doesn't support non-isbitstypes. (x-ref: #883)
But is this error as expected?

I thought we can add a matrix division method for non-isbitstypes that does not use setindex.

@hyrodium
Copy link
Collaborator Author

hyrodium commented Aug 4, 2022

Note that the division works fine for larger matrices:

julia> N = @SMatrix rand(BigFloat, 5,5)
5×5 SMatrix{5, 5, BigFloat, 25} with indices SOneTo(5)×SOneTo(5):
 0.406201   0.903827   0.657419   0.662293   0.30493
 0.591375   0.428022   0.799033   0.981537   0.514157
 0.175083   0.158292   0.136774   0.0813557  0.418362
 0.0178148  0.626641   0.0613683  0.17103    0.256846
 0.0244566  0.0628076  0.537964   0.33129    0.115918

julia> N / N
5×5 SMatrix{5, 5, BigFloat, 25} with indices SOneTo(5)×SOneTo(5):
 1.0          0.0   0.0          -0.0          -0.0
 4.77755e-78  1.0  -8.34278e-78  -6.25746e-78  -2.67633e-78
 0.0          0.0   1.0          -0.0          -0.0
 0.0          0.0   0.0           1.0          -0.0
 0.0          0.0   0.0          -0.0           1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant