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 indexing triangular matrices with BandIndex #55644

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Aug 30, 2024

With this, certain indexing operations involving a BandIndex may be evaluated as constants. This isn't used directly presently, but might allow for more performant broadcasting in the future.
With this,

julia> n = 3; T = Tridiagonal(rand(n-1), rand(n), rand(n-1));

julia> @code_warntype ((T,j) -> UpperTriangular(T)[LinearAlgebra.BandIndex(2,j)])(T, 1)
MethodInstance for (::var"#17#18")(::Tridiagonal{Float64, Vector{Float64}}, ::Int64)
  from (::var"#17#18")(T, j) @ Main REPL[12]:1
Arguments
  #self#::Core.Const(var"#17#18"())
  T::Tridiagonal{Float64, Vector{Float64}}
  j::Int64
Body::Float64
1%1 = Main.UpperTriangular(T)::UpperTriangular{Float64, Tridiagonal{Float64, Vector{Float64}}}%2 = LinearAlgebra.BandIndex::Core.Const(LinearAlgebra.BandIndex)
│   %3 = (%2)(2, j)::Core.PartialStruct(LinearAlgebra.BandIndex, Any[Core.Const(2), Int64])
│   %4 = Base.getindex(%1, %3)::Core.Const(0.0)
└──      return %4

The indexing operation may be evaluated at compile-time, as the band index is constant-propagated.

@jishnub jishnub added performance Must go faster linear algebra Linear algebra arrays [a, r, r, a, y, s] labels Aug 30, 2024
@jishnub jishnub merged commit f62a380 into master Sep 23, 2024
7 checks passed
@jishnub jishnub deleted the jishnub/bandindex_getindex branch September 23, 2024 13:02
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] linear algebra Linear algebra performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant