Skip to content

Fix inferrability of size(::AdjTrans)#403

Merged
amontoison merged 1 commit intoJuliaSmoothOptimizers:mainfrom
timholy:teh/perfsize
Feb 22, 2026
Merged

Fix inferrability of size(::AdjTrans)#403
amontoison merged 1 commit intoJuliaSmoothOptimizers:mainfrom
timholy:teh/perfsize

Conversation

@timholy
Copy link
Copy Markdown
Contributor

@timholy timholy commented Feb 22, 2026

For tuples, the compiler can't infer the size of t[[2; 1]]:

julia> revsize1(A::AbstractMatrix) = size(A)[[2; 1]]
revsize1 (generic function with 1 method)

julia> revsize2(A::AbstractMatrix) = reverse(size(A))
revsize2 (generic function with 1 method)

julia> A = rand(3, 5);

julia> @code_warntype revsize1(A)
MethodInstance for revsize1(::Matrix{Float64})
  from revsize1(A::AbstractMatrix) @ Main REPL[1]:1
Arguments
  #self#::Core.Const(revsize1)
  A::Matrix{Float64}
Body::Tuple{Vararg{Int64}}
1%1 = Main.size(A)::Tuple{Int64, Int64}%2 = Base.vcat(2, 1)::Vector{Int64}%3 = Base.getindex(%1, %2)::Tuple{Vararg{Int64}}
└──      return %3


julia> @code_warntype revsize2(A)
MethodInstance for revsize2(::Matrix{Float64})
  from revsize2(A::AbstractMatrix) @ Main REPL[2]:1
Arguments
  #self#::Core.Const(revsize2)
  A::Matrix{Float64}
Body::Tuple{Int64, Int64}
1%1 = Main.size(A)::Tuple{Int64, Int64}%2 = Main.reverse(%1)::Tuple{Int64, Int64}
└──      return %2

Copilot AI review requested due to automatic review settings February 22, 2026 07:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a type inference issue in the size method for adjoint and transpose linear operators by replacing tuple indexing with the reverse function.

Changes:

  • Replace size(A)[[2; 1]] with reverse(size(A)) for AdjTrans operators to enable better type inference by the Julia compiler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.44%. Comparing base (32dbc5e) to head (0174e69).
⚠️ Report is 68 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #403      +/-   ##
==========================================
+ Coverage   95.00%   95.44%   +0.44%     
==========================================
  Files          17       21       +4     
  Lines        1100     1186      +86     
==========================================
+ Hits         1045     1132      +87     
+ Misses         55       54       -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.

@amontoison amontoison merged commit 0f71d74 into JuliaSmoothOptimizers:main Feb 22, 2026
60 of 61 checks passed
@timholy timholy deleted the teh/perfsize branch February 22, 2026 19: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.

3 participants