Skip to content

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Sep 20, 2025

For banded matrices such as Diagonal, we may skip the non-stored elements in computing the norm, as the contribution of these would be zero.

This improves performance.
On master

julia> D1 = Diagonal(rand(1000));

julia> D2 = Diagonal(rand(1000));

julia> @btime norm($D1);
  2.668 ms (0 allocations: 0 bytes)

julia> @btime isapprox($D1, $D2);
  8.007 ms (3 allocations: 7.88 KiB)

vs this PR

julia> @btime norm($D1);
  247.196 ns (0 allocations: 0 bytes)

julia> @btime isapprox($D1, $D2);
  1.696 μs (0 allocations: 0 bytes)

@jishnub jishnub added the arrays [a, r, r, a, y, s] label Sep 20, 2025
Copy link

codecov bot commented Sep 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.90%. Comparing base (7b21cab) to head (e74bdb4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1457      +/-   ##
==========================================
+ Coverage   93.89%   93.90%   +0.01%     
==========================================
  Files          34       34              
  Lines       15926    15936      +10     
==========================================
+ Hits        14953    14964      +11     
+ Misses        973      972       -1     

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

end

@testset "norm" begin
D = Diagonal(float.(1:3))
Copy link
Member

@stevengj stevengj Sep 23, 2025

Choose a reason for hiding this comment

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

Maybe

for D in ( Diagonal(1:3), Diagonal(1:1), Diagonal(1:0) )

to test the 1x1 and 0x0 cases?

Also, skip the float conversion to make sure the result is floating-point, maybe add a ::Float64 assert to the result

@jishnub jishnub force-pushed the jishnub/norm_diagonal branch from 44ebe95 to e74bdb4 Compare September 26, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants