Skip to content

Make parentof_applytri fully type-stable #1243

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Mar 19, 2025

This should make each branch in applytri return the same type, as the UpperTriangular or LowerTriangular wrapper will be removed.

@jishnub jishnub force-pushed the jishnub/parentof_applytri_stable branch from 1544e56 to 85dbca3 Compare April 2, 2025 06:34
@jishnub jishnub requested a review from dkarrasch April 2, 2025 11:47
Copy link

codecov bot commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.99%. Comparing base (e53b50c) to head (85dbca3).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1243      +/-   ##
==========================================
- Coverage   92.03%   91.99%   -0.04%     
==========================================
  Files          34       34              
  Lines       15459    15459              
==========================================
- Hits        14227    14222       -5     
- Misses       1232     1237       +5     

☔ 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.

@ViralBShah
Copy link
Member

@dkarrasch Bumping for a quick look.

@dkarrasch
Copy link
Member

Honestly, I can't wrap my head around this. I could use some hints as to why this is currently type-unstable and why this makes it stable.

@jishnub
Copy link
Member Author

jishnub commented Jun 3, 2025

In

function applytri(f, A::HermOrSym)
if A.uplo == 'U'
f(uppertriangular(A.data))
else
f(lowertriangular(A.data))
end
end
, the first branch usually returns an UpperTriangular, and the second returns a LowerTriangular. The result therefore is inferred as a Union{UpperTriangular, LowerTriangular}.

We sometimes call parent(applytri(f, A::Symmetric)) to strip the triangular layer:

_parent_tri(U::UpperOrLowerTriangular) = parent(U)
_parent_tri(U) = U
parentof_applytri(f, args...) = _parent_tri(applytri(f, args...))

When we pass the result of applytri to parent, type-inference has to carry out a union-splitting. If all we want is the parent, though, then we can directly return the parent from each branch by removing the triangular wrapper. This way, both the branches end up returning the same type. In a way, this is inlining parent within the branches of applytri, instead of having a separate call to parent with the result.

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.

None yet

3 participants