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

LinAlg: fzeropreserving unit triangular broadcast preserves structure #53648

Merged
merged 2 commits into from
Mar 11, 2024

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Mar 8, 2024

On master

julia> UU = UnitUpperTriangular(reshape([1:9;],3,3))
3×3 UnitUpperTriangular{Int64, Matrix{Int64}}:
 1  4  7
   1  8
     1

julia> UU .* 2
3×3 Matrix{Int64}:
 2  8  14
 0  2  16
 0  0   2

This PR

julia> UU .* 2
3×3 UpperTriangular{Int64, Matrix{Int64}}:
 2  8  14
   2  16
      2

This also improves performance, as the materialize skips the structured zeros.

julia> UU = UnitUpperTriangular(rand(100, 100));

julia> @btime $UU .* 2;
  12.788 μs (3 allocations: 78.20 KiB) # master
  7.821 μs (3 allocations: 78.20 KiB) # PR

@jishnub jishnub added domain:linear algebra Linear algebra domain:arrays [a, r, r, a, y, s] labels Mar 8, 2024
@jishnub jishnub requested a review from N5N3 March 9, 2024 08:11
@jishnub jishnub merged commit 1ba83f0 into master Mar 11, 2024
7 of 9 checks passed
@jishnub jishnub deleted the jishnub/unituppertribroadcast branch March 11, 2024 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] domain:linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants