-
Notifications
You must be signed in to change notification settings - Fork 2
Fix bipermutations in contract
#75
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #75 +/- ##
==========================================
- Coverage 94.90% 94.39% -0.51%
==========================================
Files 14 14
Lines 451 464 +13
==========================================
+ Hits 428 438 +10
- Misses 23 26 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I missed a part of the discussion but this also came up when writing the extension to TensorOperations, so let me perhaps elaborate slightly on what TensorOperations does, which could be used as inspiration of what (not) to do. From the point of TensorOperations, we chose our permutations/inverses such that effectively a contraction for a dense array would be, if simplified: function tensorcontract!(C, A, (p1A, p2A), B, (p1B, p2B), (p1AB, p2AB), ...)
A_mat = reshape(permutedims(A, (p1A..., p2A...)), prod(i->size(A, i), p1A), prod(i -> size(A, i), p2A))
B_mat = reshape(permutedims(B, (p1B..., p2B...)), prod(i -> size(B, i), p1B), prod(i -> size(B, i), p2B))
AB = reshape(A_mat * B_mat, size.(Ref(A), p1A), size.(Ref(B), p2B))
C += permutedims(AB, (p1AB..., p2AB...))
return C
end Importantly, the partition for Now, in order to avoid forming The main idea being that where we use alfa and beta never really affects performance, and indeed we require both the inverse and regular blocked permutation to have both fast paths. I think I quite like the naming scheme (might just be habit) of having |
@lkdvos indeed We considered something similar to detecting a trivial |
Indeed, for symmetric tensors we actually only support the case where the final permutation is trivial. (Although with the caveat that you can sometimes alter |
Looks good. Are the tests you marked as broken fixed by JuliaArrays/BlockArrays.jl#485? |
Yes I use both I also updated the checks in With these changes, I am now able to use the generic Ready to merge. |
This PR fixes bipermutation inversion in
contract
. A given bipermutation alone does not carry enough information to be inverted: the bipartition of the output must be specified. It turns out both permutation are needed incontract
stack at different times. I managed to pass only one inside each function and to invert it using information from other arguments.The logic of the code is now correct and able to handle arrays with bipartitions. We need bipermutations for both directions and be explicit which is which. I would be happy to improve the names I used.
Note that
BlockArrays
tests fail due to JuliaArrays/BlockArrays.jl#295.