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

Fix addition of symmetric NamedDimsArray and UniformScaling #213

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mjp98
Copy link
Member

@mjp98 mjp98 commented Nov 16, 2022

Closes #212

@codecov
Copy link

codecov bot commented Nov 16, 2022

Codecov Report

Merging #213 (34c688d) into master (10a2c7e) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #213      +/-   ##
==========================================
+ Coverage   94.76%   94.78%   +0.01%     
==========================================
  Files          14       14              
  Lines         688      690       +2     
==========================================
+ Hits          652      654       +2     
  Misses         36       36              
Impacted Files Coverage Δ
src/functions_linearalgebra.jl 96.47% <100.00%> (+0.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@mjp98 mjp98 changed the title Extend LinearAlgebra.copy_oftype Fix addition of symmetric NamedDimsArray and UniformScaling Nov 16, 2022
@mjp98
Copy link
Member Author

mjp98 commented Nov 16, 2022

Underlying error appears to be with copyto!

julia> S = NamedDimsArray(Symmetric(rand(2,2));cols =[:A,:B], rows=[:C, :D])
2-dimensional NamedDimsArray(KeyedArray(...)) with keys:
   cols  2-element Vector{Symbol}
   rows  2-element Vector{Symbol}
And data, 2×2 Symmetric{Float64, Matrix{Float64}}:
        (:C)       (:D)
  (:A)   0.224083   0.84936
  (:B)   0.84936    0.335228

julia> copyto!(S,copy(S))
ERROR: ArgumentError: Cannot set a non-diagonal index in a symmetric matrix
Stacktrace:
 [1] setindex!
   @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/symmetric.jl:227 [inlined]
 [2] setindex!
   @ ~/.julia/packages/AxisKeys/DiXQB/src/struct.jl:132 [inlined]
 [3] setindex!
   @ ~/.julia/packages/NamedDims/pu9Bn/src/wrapper_array.jl:185 [inlined]
 [4] copyto_unaliased!(deststyle::IndexCartesian, dest::NamedDimsArray{(:cols, :rows), Float64, 2, KeyedArray{Float64, 2, Symmetric{Float64, Matrix{Float64}}, Tuple{Vector{Symbol}, Vector{Symbol}}}}, srcstyle::IndexCartesian, src::NamedDimsArray{(:cols, :rows), Float64, 2, KeyedArray{Float64, 2, Symmetric{Float64, Matrix{Float64}}, Tuple{Vector{Symbol}, Vector{Symbol}}}})
   @ Base ./abstractarray.jl:1052
 [5] copyto!(dest::NamedDimsArray{(:cols, :rows), Float64, 2, KeyedArray{Float64, 2, Symmetric{Float64, Matrix{Float64}}, Tuple{Vector{Symbol}, Vector{Symbol}}}}, src::NamedDimsArray{(:cols, :rows), Float64, 2, KeyedArray{Float64, 2, Symmetric{Float64, Matrix{Float64}}, Tuple{Vector{Symbol}, Vector{Symbol}}}})
   @ Base ./abstractarray.jl:1018
 [6] top-level scope
   @ REPL[19]:1

# https://github.com/invenia/NamedDims.jl/issues/212
nda = NamedDimsArray{(:foo, :bar)}(Symmetric([1 2 3; 4 5 4; 3 2 1])) # Int eltype
@test LinearAlgebra.copy_oftype(nda, Float64) == nda
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also (in a seperate test set) add a test for the MWE of nda + I to avoid regression

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 this pull request may close these issues.

Error in addition of symmetric NamedDimsArray and UniformScaling
2 participants