Skip to content

Bounds-checking in triangular indexing branches #1305

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

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

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Apr 23, 2025

After this PR, calls like the following would throw:

julia> U = UpperTriangular([1 2; 3 4])
2×2 UpperTriangular{Int64, Matrix{Int64}}:
 1  2
   4

julia> U[1,0]
0

Currently, there's no bounds-checking on the indices if they don't correspond to stored values.

Also, this PR checks for compatible types in assigning to the diagonal of unit triangular matrices. This fixes issues like, e.g.:

julia> A = @SMatrix [1 2; 3 4]
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
 1  2
 3  4

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

julia> U = UnitUpperTriangular(M)
2×2 UnitUpperTriangular{SMatrix{2, 2, Int64, 4}, Matrix{SMatrix{2, 2, Int64, 4}}}:
 [1 0; 0 1]  [1 2; 3 4]
            [1 0; 0 1]

julia> U[1,1] = 1
1

After this,

julia> U[1,1] = 1
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type SMatrix{2, 2, Int64, 4}

However, this depends on JuliaLang/julia#58209 for the SizedArrays tests to pass, as oneunit currently doesn't work with a SizedArray.

@jishnub jishnub force-pushed the jishnub/unit_tri_setindex branch from 0e2eac2 to 6648614 Compare April 26, 2025 05:45
@jishnub jishnub force-pushed the jishnub/unit_tri_setindex branch from 6648614 to 9159fbb Compare April 28, 2025 05:51
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

Attention: Patch coverage is 93.22034% with 4 lines in your changes missing coverage. Please review.

Project coverage is 93.72%. Comparing base (95703b5) to head (a7f2f80).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/triangular.jl 93.10% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1305      +/-   ##
==========================================
- Coverage   93.73%   93.72%   -0.02%     
==========================================
  Files          34       34              
  Lines       15743    15781      +38     
==========================================
+ Hits        14757    14790      +33     
- Misses        986      991       +5     

☔ 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.

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.

1 participant