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

Improve type inference for adjoint/transpose of nested matrices #1181

Merged
merged 2 commits into from
Jul 19, 2023

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jul 17, 2023

This PR special-cases the return-types of the adjoint and transpose for SMatrix and MMatrix. This isn't ideal, but currently Julia doesn't infer the return types of certain recursive calls with changing types, and this PR helps with type-inference in such cases.

An example (using this PR):

julia> S = SMatrix{3,2,SMatrix{1,2,Int,2},6}(fill(SMatrix{1,2,Int,2}(1:2), 6))
3×2 SMatrix{3, 2, SMatrix{1, 2, Int64, 2}, 6} with indices SOneTo(3)×SOneTo(2):
 [1 2]  [1 2]
 [1 2]  [1 2]
 [1 2]  [1 2]

julia> @inferred adjoint(S)
2×3 SMatrix{2, 3, SMatrix{2, 1, Int64, 2}, 6} with indices SOneTo(2)×SOneTo(3):
 [1; 2;;]  [1; 2;;]  [1; 2;;]
 [1; 2;;]  [1; 2;;]  [1; 2;;]

Whereas, on master,

julia> @inferred adjoint(S)
ERROR: return type SMatrix{2, 3, SMatrix{2, 1, Int64, 2}, 6} does not match inferred return type SMatrix{2, 3, _A, 6} where _A

@mateuszbaran mateuszbaran merged commit 89813ee into JuliaArrays:master Jul 19, 2023
20 of 27 checks passed
@jishnub jishnub deleted the adjtransnested branch July 20, 2023 08:51
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.

2 participants