#16306: Replace =0 by is_zero() in test for matrix being alternating
-------------------------------------+-------------------------------------
Reporter: darij | Owner:
Type: defect | Status: needs_review
Priority: trivial | Milestone: sage-6.2
Component: linear algebra | Resolution:
Keywords: | Merged in:
Authors: Darij Grinberg | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
public/combinat/matrix0-fix | 4d4cbe0664c62dce9780d82e8eb948ee420ce521
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by darij):
I hope you will agree that "all rings" and "all rings in Sage" are two
rather different things... :)
Some timings on zero elements:
{{{
sage: %timeit ZZ(1) == 0
1000000 loops, best of 3: 419 ns per loop
sage: %timeit ZZ(1).is_zero()
1000000 loops, best of 3: 389 ns per loop
sage: %timeit QQ(1) == 0
100000 loops, best of 3: 2.15 µs per loop
sage: %timeit QQ(1).is_zero()
1000000 loops, best of 3: 853 ns per loop
sage: P.<x> = PolynomialRing(QQ)
sage: %timeit x == 0
100000 loops, best of 3: 2.76 µs per loop
sage: %timeit x.is_zero()
1000000 loops, best of 3: 223 ns per loop
sage: Sym = SymmetricFunctions(QQ); e = Sym.e(); ez = e.zero()
sage: %timeit ez == 0
10000 loops, best of 3: 27.9 µs per loop
sage: %timeit ez.is_zero()
100000 loops, best of 3: 4.45 µs per loop
}}}
and on nonzero elements:
sage: %timeit ZZ(2) == 0
1000000 loops, best of 3: 416 ns per loop
sage: %timeit ZZ(2).is_zero()
1000000 loops, best of 3: 383 ns per loop
sage: %timeit QQ(2) == 0
100000 loops, best of 3: 2.15 µs per loop
sage: %timeit QQ(2).is_zero()
1000000 loops, best of 3: 877 ns per loop
sage: e2 = e[2]
sage: %timeit e2 == 0
10000 loops, best of 3: 27.8 µs per loop
sage: %timeit e2.is_zero()
100000 loops, best of 3: 5.91 µs per loop
sage: %timeit Integer(2) == 0
1000000 loops, best of 3: 417 ns per loop
sage: %timeit Integer(2).is_zero()
1000000 loops, best of 3: 360 ns per loop
}}}
I don't know how much of the coercion overhead can be removed by improving
the coercion system, but for now it looks like `is_zero` wins against
coercion.
--
Ticket URL: <http://trac.sagemath.org/ticket/16306#comment:6>
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.