Skip to content

Apply array shape rules in Diagonal/Bidiagonal/SymTridiagonal projectors - #720

Merged
devmotion merged 1 commit into
mainfrom
dmw/structured-projectto-trailing-dims
Oct 26, 2026
Merged

devmotion merged 1 commit into
mainfrom
dmw/structured-projectto-trailing-dims

Conversation

@devmotion

Copy link
Copy Markdown
Member

The ProjectTo methods for Diagonal, Bidiagonal and SymTridiagonal now apply the same shape rules as ProjectTo{AbstractArray}, through a shared helper _projection_reshape that is moved out unchanged from the AbstractArray method:

  • Gradients with trailing singleton dimensions, such as dx = ones(3, 3, 1), are now accepted. They used to throw a MethodError, unlike the Symmetric/Hermitian/triangular/Tridiagonal projectors.
  • Wrongly sized matrices now throw a DimensionMismatch. Before, Diagonal silently took the diagonal of 3×4 and 4×3 matrices, and Bidiagonal of 4×3 ones.

Matrices of the right size take the existing axes(dx) === axes(x) fast path, so neither speed nor allocations change.

This is needed for JuliaDiff/ChainRules.jl#783, where rrule(+, ::Matrix, ::Diagonal, ::Array{3}) projects a 3×3×1 cotangent onto a Diagonal.

Bumps the version to 1.26.5.

🤖 Generated with Claude Code

The projectors for Diagonal, Bidiagonal and SymTridiagonal now use the same
shape rules as ProjectTo{AbstractArray}, via a shared _projection_reshape helper:
- gradients with trailing singleton dimensions, e.g. dx = ones(3, 3, 1), are
  accepted (previously a MethodError);
- wrongly sized matrices throw a DimensionMismatch (previously Diagonal silently
  took the diagonal of e.g. 3×4 and 4×3 matrices, and Bidiagonal of 4×3 ones).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.47%. Comparing base (44772e9) to head (54d7d81).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #720      +/-   ##
==========================================
+ Coverage   93.41%   93.47%   +0.05%     
==========================================
  Files          15       15              
  Lines        1002     1011       +9     
==========================================
+ Hits          936      945       +9     
  Misses         66       66              

☔ View full report in Codecov by Harness.
📢 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.

@devmotion
devmotion merged commit 0d375e8 into main Oct 26, 2026
27 checks passed
@devmotion
devmotion deleted the dmw/structured-projectto-trailing-dims branch October 26, 2026 18:31
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.

1 participant