Skip to content

Make ProjectTo{AbstractArray} inferrable for wrappers with OneTo axes - #716

Open
devmotion wants to merge 2 commits into
mainfrom
dmw/triangular-projectto-inference
Open

devmotion wants to merge 2 commits into
mainfrom
dmw/triangular-projectto-inference

Conversation

@devmotion

Copy link
Copy Markdown
Member

Fixes #407.

ProjectTo{AbstractArray} chooses between dx and reshape(dx, project.axes) based on the values of the axes. For wrappers like Diagonal, UpperTriangular or Symmetric, reshape returns a ReshapedArray, so the inferred result is a Union:

julia> @inferred ProjectTo(rand(3, 3))(Diagonal(rand(3)))
ERROR: return type Diagonal{Float64, Vector{Float64}} does not match inferred return type Union{Base.ReshapedArray{...}, Diagonal{Float64, Vector{Float64}}}

If dx and the projector have the same number of OneTo axes but they are not identical, the sizes differ and the size check throws anyway. This PR checks that case on types, so inference no longer sees the reshape. Behaviour is unchanged: the same inputs throw the same error, and reshape is still used for trivial dimensions and OffsetArrays.

Note: #702 changes the same lines; whichever is merged second needs to add !isempty(dx) to the new condition.

🤖 Generated with Claude Code

If dx and the projector have the same number of OneTo axes but they are not
identical, the sizes differ and the size check would throw anyway. Doing this
check on types lets inference skip the type-unstable reshape, which returns a
ReshapedArray for wrappers like Diagonal, UpperTriangular or Symmetric.

Fixes #407

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

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.40%. Comparing base (0da460d) to head (a7e3338).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #716      +/-   ##
==========================================
+ Coverage   93.39%   93.40%   +0.01%     
==========================================
  Files          15       15              
  Lines         999     1001       +2     
==========================================
+ Hits          933      935       +2     
  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.

This branch has not been deployed

No deployments
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.

ProjectTo(::AbstractArray) does not infer

1 participant