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

Specialize triu/tril for StaticMatrix #1241

Merged
merged 1 commit into from
Oct 2, 2024
Merged

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jan 29, 2024

This provides a performance boost for small matrices:
On master

julia> S = SMatrix{3,3}(1:9)
3×3 SMatrix{3, 3, Int64, 9} with indices SOneTo(3)×SOneTo(3):
 1  4  7
 2  5  8
 3  6  9

julia> @btime triu($S)
  245.797 ns (1 allocation: 80 bytes)
3×3 MMatrix{3, 3, Int64, 9} with indices SOneTo(3)×SOneTo(3):
 1  4  7
 0  5  8
 0  0  9

This PR

julia> @btime triu($S)
  17.183 ns (0 allocations: 0 bytes)
3×3 SMatrix{3, 3, Int64, 9} with indices SOneTo(3)×SOneTo(3):
 1  4  7
 0  5  8
 0  0  9

I've hard-coded the maximum length of 32 until which working on Tuples directly is faster, but it'll probably be better to read this limit from Base. Any suggestions on how to approach this?

@jishnub jishnub merged commit 7708986 into JuliaArrays:master Oct 2, 2024
26 checks passed
@jishnub jishnub deleted the triul branch October 2, 2024 13:05
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