Skip to content

Symmetry check in setindex! for Symmetric/Hermitian #1317

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

Merged
merged 2 commits into from
Apr 27, 2025

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Apr 27, 2025

Currently, the following works unexpectedly:

julia> A = Symmetric(fill([1 2; 3 4], 3, 3))
3×3 Symmetric{AbstractMatrix, Matrix{Matrix{Int64}}}:
 [1 2; 2 4]  [1 2; 3 4]  [1 2; 3 4]
 [1 3; 2 4]  [1 2; 2 4]  [1 2; 3 4]
 [1 3; 2 4]  [1 3; 2 4]  [1 2; 2 4]

julia> A[1,1] = [1 2; 3 4]
2×2 Matrix{Int64}:
 1  2
 3  4

julia> A[1,1]
2×2 Symmetric{Int64, Matrix{Int64}}:
 1  2
 2  4

After this PR, the setindex! throws an error if the exact value cannot be used:

julia> A[1,1] = [1 2; 3 4]
ERROR: ArgumentError: cannot set a diagonal element of a symmetric matrix to an asymmetric value

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.70%. Comparing base (5d3d02a) to head (65b8538).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1317      +/-   ##
==========================================
- Coverage   93.72%   93.70%   -0.02%     
==========================================
  Files          34       34              
  Lines       15733    15734       +1     
==========================================
- Hits        14746    14744       -2     
- Misses        987      990       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jishnub jishnub merged commit 6e8f9a1 into master Apr 27, 2025
3 of 4 checks passed
@jishnub jishnub deleted the jishnub/symhermsetindex branch April 27, 2025 15:19
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.

2 participants