sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.33k stars 453 forks source link

Fix tensor product of dense matrix by sparse matrix #31086

Open slel opened 3 years ago

slel commented 3 years ago

The tensor product of a dense matrix by a sparse matrix fails for some base rings including cyclotomic fields. Everything works fine over ZZ or QQ.

Illustration in Sage 9.3.beta4:

sage: k = CyclotomicField(3)
sage: I = identity_matrix(k, 2)
sage: J = identity_matrix(k, 2, sparse=True)
sage: J.tensor_product(J)
[1 0|0 0]
[0 1|0 0]
[---+---]
[0 0|1 0]
[0 0|0 1]
sage: J.tensor_product(I)
[1 0|0 0]
[0 1|0 0]
[---+---]
[0 0|1 0]
[0 0|0 1]
sage: I.tensor_product(I)
[1 0|0 0]
[0 1|0 0]
[---+---]
[0 0|1 0]
[0 0|0 1]
sage: I.tensor_product(J)
Traceback (most recent call last)
...
AttributeError: 'sage.matrix.matrix_generic_sparse.Matrix_generic_sparse'
object has no attribute '_rational_matrix'

Initial report by Will Orrick at

CC: @slel

Component: linear algebra

Keywords: matrix, tensor_product, dense, sparse

Issue created by migration from https://trac.sagemath.org/ticket/31086

slel commented 3 years ago

Description changed:

--- 
+++ 
@@ -35,4 +35,4 @@

 Initial report by Will Orrick at

-- [Ask Sage question 54762](https://ask.sagemath.org/question/54762)
+- [Ask Sage question 54762: Tensor product of matrices over cyclotomic field](https://ask.sagemath.org/question/54762)
mkoeppe commented 3 years ago
comment:2

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.