https://github.com/sagemath/sage/issues/39648
I am no guru but I think I can tackle it. On Friday, March 7, 2025 at 11:47:31 AM UTC-6 Nils Bruin wrote: > I can confirm that changing in > sage.matrix.matrix_generic_dense.Matrix_generic_dense._multiply_classical > the line from left._entries[m+k]._mul_ to just > left._entries[m+k]* , the code works as expected. So the problem is > probably the _mul_. > > I think this is a general problem that was not discovered before: as far > as I can see, it's legal for element types to have a cdef _mul_. However, > in the matrix code, I think it ends up being looked up as a python method. > I'm not sure that matrix elements always have to inherit from Element, so > I'm not sure a cython typecast to it is warranted. Changing to "*" and just > let the coercion framework figure it out is definitely valid, but it should > be checked if that brings a performance penalty. > > Someone should make a ticket and alert the coercion gurus to it. > > On Thursday, 6 March 2025 at 16:30:27 UTC-8 Nils Bruin wrote: > >> It's probably a matter that ExteriorAlgebraElement has a "cdef _mul_" >> now. That means in cython code it can access the method if it has enough >> type information. That's probably why `p*p` works. It looks like in >> sage.matrix.matrix_generic_dense.Matrix_generic_dense._multiply_classical >> not enough type info is available on left._entries[m+k] to look up this >> _mul_ . It may be that the correct typecast, something like "(<Element> >> left._entries[m+k])" perhaps, does the trick. Or perhaps _mul_ is supposed >> to be "def" or "cpdef". I doubt the latter, though, since for the most >> part, multiplication seems to work: the coercion framework can figure out >> how to do it: >> >> sage: coercion_model.bin_op(p,p,operator.mul) >> 0 >> >> it makes sense that matrix multiplication takes a shortcut to avoid the >> overhead of the coercion framework. But perhaps it doesn't have enough type >> info. >> >> On Thursday, 6 March 2025 at 15:43:02 UTC-8 Seth Chaiken wrote: >> >>> In Sage 10.4, >>> Ext=ExteriorAlgebra(QQ,['p']) >>> Ext.inject_variables() >>> Mp = matrix(1,1,[[p]]) >>> Mp[0,0]*Mp[0,0] >>> -> 0 >>> Mp*Mp >>> FAILS! >>> (This did work in an older version.) >>> >>> --------------------------------------------------------------------------- >>> TypeError Traceback (most recent call last) Cell In[10], line 1 ----> 1 >>> Mp*Mp File /data/Software/Sage/sage/src/sage/structure/element.pyx:4116, >>> in sage.structure.element.Matrix.__mul__() 4114 # better be square for >>> the product to be defined. 4115 if (<Matrix>left)._nrows == >>> (<Matrix>left)._ncols: -> 4116 return >>> (<Matrix>left)._matrix_times_matrix_(<Matrix>right) 4117 else: 4118 >>> parent = (<Matrix>left)._parent File >>> /data/Software/Sage/sage/src/sage/matrix/matrix0.pyx:5675, in >>> sage.matrix.matrix0.Matrix._matrix_times_matrix_() 5673 return >>> self._multiply_strassen(right) 5674 else: -> 5675 return >>> self._multiply_classical(right) 5676 5677 cdef bint >>> _will_use_strassen(self, Matrix right) except -2: File >>> /data/Software/Sage/sage/src/sage/matrix/matrix_generic_dense.pyx:323, >>> in >>> sage.matrix.matrix_generic_dense.Matrix_generic_dense._multiply_classical >>> () 321 m = i*snc 322 for k in range(snc): --> 323 z += >>> left._entries[m+k]._mul_(right._entries[k*nc+j]) 324 v[p] = z 325 p += >>> 1 TypeError: 'NotImplementedType' object is not callable >>> >> -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/sage-support/d9653d67-437b-4d99-bc4c-44ad8da1e635n%40googlegroups.com.