Bug in modp sparse matrix multiply

已查看 37 次
跳至第一个未读帖子

Daniel Roche

未读,
2017年8月20日 21:04:232017/8/20
收件人 sage-devel
Hi sagers,

First let me say thanks for the great piece of software that is sage. You all do a tremendous job and maybe don't get thanked enough.

There appears to be a bug in sparse matrix multiplication over small finite fields:

sage: p = next_prime(2**15); p
32771
sage
: M = Matrix(GF(p), 1,3, lambda i,j: -1, sparse=True); M
[32770 32770 32770]
sage
: M*M.transpose()
[32738] # INCORRECT, should be 3
sage
: M*M.transpose() + 2**32
[3] # it was off by 2^32, hmmm...

Being off by 2^32 hints that there is an integer overflow or signedness issue, and indeed I believe the culprit is in the _matrix_times_matrix_ method on line 387 of matrix_modn_sparse.pyx, where a cdef int s is added up without reducing modulo p.

I am currently running release 8.0 on a 64-bit Debian machine. I had some old versions of sage lying around and the bug seems to be present in versions going back at least to 5.6; it's not a recent change.

Thanks for taking a look!

-Dan

Vincent Delecroix

未读,
2017年8月20日 21:11:082017/8/20
收件人 sage-...@googlegroups.com、dsr...@gmail.com
Dear Dan,

Thanks for the report! This is indeed a bug. If you want to go further
and fix the bug yourself, the procedure is described here

http://doc.sagemath.org/html/en/developer/

Otherwise I will open the relevant ticket.

Vincent

On 20/08/2017 19:59, Daniel Roche wrote:
> Hi sagers,
>
> First let me say thanks for the great piece of software that is sage. You
> all do a tremendous job and maybe don't get thanked enough.
>
> There appears to be a bug in sparse matrix multiplication over small finite
> fields:
>
> sage: p = next_prime(2**15); p
> 32771
> sage: M = Matrix(GF(p), 1,3, lambda i,j: -1, sparse=True); M
> [32770 32770 32770]
> sage: M*M.transpose()
> [32738] # INCORRECT, should be 3
> sage: M*M.transpose() + 2**32
> [3] # it was off by 2^32, hmmm...
>
> Being off by 2^32 hints that there is an integer overflow or signedness
> issue, and indeed I believe the culprit is in the _matrix_times_matrix_
> method on line 387 of matrix_modn_sparse.pyx
> <https://github.com/sagemath/sage/blob/master/src/sage/matrix/matrix_modn_sparse.pyx#L387>,

Daniel Roche

未读,
2017年8月22日 01:03:492017/8/22
收件人 sage-devel、dsr...@gmail.com
Thanks, I submitted and fixed the bug here (in case anyone wants to review it):
回复全部
回复作者
转发
0 个新帖子