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

ArrayContraction.split_multiple_contractions() should not split in case of diagonal matrix #21961

Open
Tracked by #22321
Upabjojr opened this issue Aug 27, 2021 · 0 comments
Labels

Comments

@Upabjojr
Copy link
Contributor

Consider the following code

from sympy.tensor.array.expressions.array_expressions import ArrayDiagonal, ArrayTensorProduct, ArrayContraction
from sympy.tensor.array.expressions.conv_array_to_matrix import convert_array_to_matrix

I = Identity(3)
A = MatrixSymbol("A", 3, 3)
B = MatrixSymbol("B", 3, 3)

expr1 = ArrayContraction(ArrayTensorProduct(A, B, I), (0, 2, 4))
expr2 = expr1.split_multiple_contractions()
# ===> ArrayContraction(ArrayTensorProduct(I, A, B), (0, 2), (1, 4))
expected = ArrayDiagonal(ArrayTensorProduct(A, B), (0, 2))
assert expr1.as_explicit() == expr2.as_explicit()
assert expr1.as_explicit() == expected.as_explicit()

The first assertion fails because expr2 is not equal to expr1 (on dimension has been contracted).

The expected result is given in the expected variable. Triple contraction with the identity matrix is equivalent to diagonalization (remember that PermuteDims may be necessary).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants