Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize zero test through the sage lib #12526

Open
hivert opened this issue Feb 17, 2012 · 0 comments
Open

Optimize zero test through the sage lib #12526

hivert opened this issue Feb 17, 2012 · 0 comments

Comments

@hivert
Copy link
Contributor

hivert commented Feb 17, 2012

The default implementation of __nonzero__ in element in far from optimal. Thanks #12510 we now can detect where __nonzero__ is not properly implemented. To experiment I tried with CDF here are the timing:

With the default implementation:

p = CDF(pi)
sage: %timeit bool(p)
625 loops, best of 3: 731 ns per loop
sage: %timeit p.is_zero()
625 loops, best of 3: 965 ns per loop

with the following trivial specific implementation:

def __nonzero__(self):
    return bool(self._complex.dat[0]) or bool(self._complex.dat[1])

here is the new timing

sage: %timeit bool(p)
625 loops, best of 3: 342 ns per loop
sage: %timeit p.is_zero()
625 loops, best of 3: 869 ns per loop

This is a so common question that it would be worth removing the default implementation and implement all the specific methods.

Depends on #12510

Component: basic arithmetic

Issue created by migration from https://trac.sagemath.org/ticket/12526

@hivert hivert added this to the sage-5.11 milestone Feb 17, 2012
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants