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
@codecov
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 (73aee00).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1457      +/-   ##
==========================================
+ Coverage   93.89%   93.90%   +0.01%     
==========================================
  Files          34       34              
  Lines       15926    15934       +8     
==========================================
+ Hits        14953    14963      +10     
+ Misses        973      971       -2     

☔ 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 force-pushed the jishnub/norm_diagonal branch from 44ebe95 to e74bdb4 Compare September 26, 2025 18:47
@jishnub jishnub merged commit 47d02b7 into master Oct 28, 2025
4 checks passed
@jishnub jishnub deleted the jishnub/norm_diagonal branch October 28, 2025 16:15
GianmarcoCuppari pushed a commit to GianmarcoCuppari/LinearAlgebra.jl that referenced this pull request Nov 2, 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
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
julia> @Btime norm($D1);
  247.196 ns (0 allocations: 0 bytes)

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

---------

Co-authored-by: Steven G. Johnson <[email protected]>
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