On 2013-05-20, Stefan <
stefan...@gmail.com> wrote:
> For the impatient: the key methods are these (Xs has 10000 coordinate
> pairs, Vs has 10000 elements from GF(7)):
>
> {{{
> %cython
> from sage.matroids.lean_matrix cimport GenericMatrix
> from sage.matrix.matrix2 cimport Matrix
>
> cpdef setA(A, X, V, m):
> AA = <Matrix> A
> for i in xrange(m):
> AA.set_unsafe(X[i][0], X[i][1], AA.get_unsafe(X[i][0], X[i][1]) +
> V[i])
>
> cpdef setB(B, X, V, m):
> for i in xrange(m):
> B[X[i][0]][X[i][1]] = B[X[i][0]][X[i][1]] + V[i]
>
> cpdef setC(C, X, V, m):
> CC = <GenericMatrix> C
> for i in xrange(m):
> CC.set_unsafe(X[i][0], X[i][1], CC.get_unsafe(X[i][0], X[i][1]) +
> V[i])
> }}}
>
> ...
>
> 25 loops, best of 3: 34.3 ms per loop
> 625 loops, best of 3: 1.5 ms per loop
> 625 loops, best of 3: 1.12 ms per loop
>
> }}}
>
>
> Surely a 20-fold slowdown for Sage's matrix structure is unacceptable?
I think it would be a mistake to restrict the benchmarks to setting/getting
items of the matrix. Lists (your example B, isn't it?) do not provide matrix
multiplication, computation of kernels, etc. How does GenericMatrix compete
with Linbox (that's the backend Sage uses for matrices over GF(7), if I
recall correctly) in classical linear algebra problems?
That said, your timings indicate that the communication between Sage and
Linbox can probably be improved.
Best regards,
Simon