On 6/21/07, David Harvey <[EMAIL PROTECTED]> wrote: > Ok I gdb'd this, and I can tell you exactly where the problem is, but > I can't tell you how to fix it, because I don't think anyone has > written down the rules for how this should work. Or maybe they have > and I don't know where to look.
Great, thanks... I was lazy to do it myself 8-) (in fact, I had been tinkering with the base_extend_canonical() stuff for a long time... I've nailed down a few more quirks in the code I submited, and I'll be sending a patch soon, I hope) > So my feeling is that: > (1) the vector_times_matrix_c() function should be able to assume > that the vector is over the same ring as the matrix, > (2) therefore there is a bug in Vector.__mul__(). It shouldn't just > be checking the types, it should also be checking the base rings, and > if they don't agree, some coercion should be kicking in. Ok, I'll base_extend_canonical() the vector before calling vector_times_matrix_c(), I think that will do, since stuff like vector(QQ[x],[1])*matrix(QQ,1,1,[1]) vector(QQ[x][y],[1])*matrix(QQ,1,1,[1]) vector(QQ[x][y],[1])*matrix(ZZ[x],1,1,[1]) vector(ZZ[x][y],[1])*matrix(ZZ[x],1,1,[1]) all seem to be working. In fact, this vector(ZZ[x],[1])*matrix(ZZ[y],1,1,[1]) is working now, and it shouldn't, so we definitely need to call base_extend_canonical() somewhere (hmmm, this should be caught by the ZZ[x]*ZZ[y] code, but maybe it's taking some fast path). I don't want to base_extend_canonical() in excess, since (A) it takes some time (hopefully not much more than before for the "simple" cases); and (B) I don't want to coerce, e.g. scalars to polynomials or matrices, etc, before doing a __mul__, so the poly/matrix code knows its dealing with scalars, etc. > My only concern is the whole question about multiple representation > formats... like what happens if a parent (say vectors over some ring) > has more than one way of representing elements. Is Vector.__mul__ > responsible for the conversion in this case, or is it the vector/ > matrix multiply operation? Maybe it's more sensible that vector-matrix multiply operation takes care. After all, when matrix * vector operation is called, it's the matrix class that does the conversion, and matrix(QQ,1,1,[1]) * vector(ZZ[x],[1]) indeed works (after my patch---but at least it doesn't crash in main) The Vector.__mul__ is very fast and dispatches very quickly based on the type of the right argument, we could be calling a function with correct checks and coercions (Matrix.__lmul__ ?? ) and it wouldn't be a duplication. Gonzalo --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---
