Opened 8 years ago

Closed 8 years ago

#12413 closed defect (fixed)

Sage crashes in matrix/vector multiplication with zero extents

Reported by: JStarx Owned by: jason, was
Priority: critical Milestone: sage-5.0
Component: linear algebra Keywords: sd36
Cc: malb Merged in: sage-5.0.beta7
Authors: Martin Albrecht Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by vbraun)

The following crashes Sage 4.8 on OS X 10.6.8 with a mysterious message:

sage: Y = (GF(3)^1)/(GF(3)^1)
sage: Y((1,))
lda must be >= MAX(N,1): lda=0 N=0Parameter 7 to routine cblas_sgemv was incorrect
Mac OS BLAS parameter error in cblas_sgemv, parameter #0, (unavailable), is 0
d-69-91-159-193:devel Starx$

I have not yet been able to find the error, the problem may be with a call to LinBox?, as discussed here: http://groups.google.com/group/sage-support/browse_thread/thread/30bfc9922b26f3d7 but I am not yet sure.

Apply trac_12413_linbox_crash.patch

Attachments (1)

trac_12413_linbox_crash.patch (4.0 KB) - added by malb 8 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 8 years ago by JStarx

  • Description modified (diff)

comment:2 Changed 8 years ago by JStarx

  • Description modified (diff)

comment:3 Changed 8 years ago by vbraun

  • Authors Jim Stark deleted
  • Cc malb added
  • Component changed from algebra to linear algebra
  • Keywords linbox removed
  • Owner changed from AlexGhitza to jason, was

I can reproduce it with sage-5.0.beta1 on Fedora 16. The problem is in vector-matrix multiplication:

sage: vector(GF(3),[1]) * matrix(GF(3),[[]]) 
lda must be >= MAX(N,1): lda=0 N=0Parameter 7 to routine cblas_sgemv was incorrect

Note that the matrix is of the wrong size, but the coercion model will try it out to see if any error is raised.

comment:4 Changed 8 years ago by malb

  • Authors set to Martin Albrecht
  • Status changed from new to needs_review

Prepared the patch while being very tired, so fingers crossed it does what it should :)

comment:5 Changed 8 years ago by vbraun

  • Status changed from needs_review to needs_work

We should definitely raise an error when multiplying matrix/vector of incompatible size, and not just return a zero matrix. Maybe after you got some sleep? :-)

comment:6 Changed 8 years ago by malb

Hi,

but A = matrix(GF(3),[[]]) is a 1 x 0 matrix and v = vector(GF(3),[1]) a vector of length 1. Hence, we do linear combination of the row of the matrix, which happens to have 0 columns. That seems correct to me?

comment:7 Changed 8 years ago by vbraun

Yes, you are right. Apparently I needed the sleep :-)

However, the following variation still crashes in matrix_modn_dense_float:

sage: vector(GF(3),[]) * matrix(GF(3),0,1,[]) 

comment:8 Changed 8 years ago by malb

Good catch. I updated the patch. It now returns:

sage: v = vector(GF(3),[]) * matrix(GF(3),0,1,[]); v
(0)

Is this what we want? I get confused with these zero row/column matrices.

comment:9 Changed 8 years ago by vbraun

I agree that the dimensions in the previous comment are correct.

Here is yet another crasher:

sage: matrix(GF(3),0,0,[]) * vector(GF(3),[])
lda must be >= MAX(N,1): lda=0 N=4194304Parameter 7 to routine cblas_sgemv was incorrect

I suggest we add the following to the doctests:

sage: v0 = vector(GF(3),[])
sage: v1 = vector(GF(3),[1])
sage: m00 = matrix(GF(3),0,0,[])
sage: m01 = matrix(GF(3),0,1,[])
sage: m10 = matrix(GF(3),1,0,[])
sage: m11 = matrix(GF(3),1,1,[1])
sage: good = [ (v0,m00), (v0,m01), (v1,m10), (v1,m11), (m00,v0), (m10,v0), (m01,v1), (m11,v1) ]
sage: for v,m in good:
...       print v, 'x', m, '=', v*m              
...
sage: bad  = [ (v1,m00), (v1,m01), (v0,m10), (v0,m11), (m00,v1), (m10,v1), (m01,v0), (m11,v0) ]
sage: for v,m in bad:
...       try:
...           v*m
...           print 'Uncaught dimension mismatch!'
...       except TypeError:
...           pass
...

comment:10 Changed 8 years ago by malb

Thanks for kicking my butt to do this properly. I've updated the patch accordingly.

However, I noticed that

sage: A = matrix(GF(3),1,0,[]) * matrix(GF(3),1,0,[])
sage: A.nrows()
1
sage: A.ncols()
0

which seems wrong. If you agree, I'll raise the issue on [sage-devel].

comment:11 Changed 8 years ago by vbraun

  • Summary changed from Sage crashes to prompt while creating quitient of vector spaces to Sage crashes in matrix/vector multiplication with zero extents

The shapes don't match in matrix(GF(3),1,0,[]) * matrix(GF(3),1,0,[]), so it is a bug that no error is raised.

comment:12 Changed 8 years ago by malb

  • Reviewers set to Volker Braun
  • Status changed from needs_work to needs_review

Right, so I though this was handled on a lower level and hence a bug on a lower level but it turns out it's my responsibility here to throw an error. I'm throwing an ArithmeticError which matches what e.g. Integer matrices do. It doesn't match the error thrown for matrix times vector products though which is a TypeError.

comment:13 Changed 8 years ago by vbraun

  • Description modified (diff)
  • Keywords sd36 added
  • Status changed from needs_review to positive_review

Looks good!

comment:14 Changed 8 years ago by jdemeyer

The documentation is misformatted:

TESTS:

    We test corner cases for multiplication

should be

TESTS: 
	 
We test corner cases for multiplication::

Changed 8 years ago by malb

comment:15 Changed 8 years ago by malb

fixed.

comment:16 Changed 8 years ago by jdemeyer

  • Merged in set to sage-5.0.beta7
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.