#19870: Cythonize matrix group elements
-------------------------------------+-------------------------------------
Reporter: tscrim | Owner: tscrim
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-7.0
Component: cython | Resolution:
Keywords: matrix group, | Merged in:
elements | Reviewers:
Authors: Travis Scrimshaw | Work issues:
Report Upstream: N/A | Commit:
Branch: | 29f72539754e8efba97deb07a93d735af559a552
public/groups/cythonize_matrix_group_element-19870| Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by tscrim):
The exception handling is slower when it has to occur:
{{{#!python
def foo(M):
try:
return M._invert_unit()
except AttributeError:
return ~M
def bar(M):
if M.base_ring() is ZZ and M.is_dense():
return M._invert_unit()
else:
return ~M
}}}
{{{
sage: M = random_matrix(ZZ, 3, 3, sparse=True)
sage: M.det()
-1
sage: %timeit foo(M)
The slowest run took 15.06 times longer than the fastest. This could mean
that an intermediate result is being cached
1000 loops, best of 3: 643 µs per loop
sage: %timeit bar(M)
1000 loops, best of 3: 639 µs per loop
sage: M = random_matrix(QQ, 3, 3)
sage: M.det()
1
sage: %timeit foo(M)
The slowest run took 20.62 times longer than the fastest. This could mean
that an intermediate result is being cached
100000 loops, best of 3: 10.4 µs per loop
sage: %timeit bar(M)
The slowest run took 17.06 times longer than the fastest. This could mean
that an intermediate result is being cached
100000 loops, best of 3: 7.5 µs per loop
}}}
However, it is faster when no exception is generated:
{{{
sage: M = random_matrix(ZZ, 3, 3)
sage: M.det()
1
sage: %timeit foo(M)
The slowest run took 16.19 times longer than the fastest. This could mean
that an intermediate result is being cached
100000 loops, best of 3: 4.39 µs per loop
sage: %timeit bar(M)
The slowest run took 11.94 times longer than the fastest. This could mean
that an intermediate result is being cached
100000 loops, best of 3: 4.61 µs per loop
}}}
Yet, I don't think that is enough of a speedup to justify the other cases
(in particular, the `\QQ` example).
--
Ticket URL: <http://trac.sagemath.org/ticket/19870#comment:9>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.