#18979: avoid Maxima on creation of symbolic matrices
-------------------------+-------------------------------------------------
Reporter: rws | Owner:
Type: | Status: needs_work
defect | Milestone: sage-6.9
Priority: major | Resolution:
Component: | Merged in:
linear algebra | Reviewers:
Keywords: | Work issues:
Authors: Nils | Commit:
Bruin | 257c0df6820e80995cc7be08f7d9c64e8fdfbca7
Report Upstream: N/A | Stopgaps:
Branch: |
u/nbruin/18979 |
Dependencies: |
-------------------------+-------------------------------------------------
Comment (by nbruin):
Replying to [comment:17 vdelecroix]:
> As I said in [comment:5 comment:5], the solution should be non intrusive
and your solution is what I suggested at the very end of this comment.
>
> Though, using a list extension is twice slower. With
> {{{
> def m1():
> cdef Py_ssize_t i
> cdef list l = [0] * 100
> for i in range(10): l[10*i + i] = 12
> return l
> def m2():
> cdef Py_ssize_t i,j
> return [12 if i == j else 0 for i in range(10) for j in range(10)]
> }}}
> I got
> {{{
> sage: %runfile test.pyx
> sage: %timeit l = m1()
> 1000000 loops, best of 3: 456 ns per loop
> sage: %timeit l = m2()
> 1000000 loops, best of 3: 1.09 µs per loop
> }}}
OK, go ahead and replace the loop by whatever works better. I hoped cython
would be able to optimize this loop, but apparently it cannot. As your
example shows, we're likely better off writing the diagonal twice. If this
absolutely needs to be fast, we can kick down to a `PyList_New` and
`PyList_SET_ITEM` inside a c-style loop. Do we need that? Probably if you
need a diagonal matrix *fast* you should some something sparse.
The only thing that testing for zero got us in the square case is that for
a zero matrix, we can avoid reinitializing the diagonal. I think we can do
without that optimization, so then at least the problem for SR and other
rings without (easily) testable equality are mostly fine except for
situations that will most likely be an error anyway.
--
Ticket URL: <http://trac.sagemath.org/ticket/18979#comment:18>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.