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

speedup integer division #6083

Closed
robertwb opened this issue May 19, 2009 · 11 comments
Closed

speedup integer division #6083

robertwb opened this issue May 19, 2009 · 11 comments

Comments

@robertwb
Copy link
Contributor

remove _sig_on and _sig_off for small operands, specialize for int divisor

Component: basic arithmetic

Author: Robert Bradshaw

Reviewer: Craig Citro

Merged: sage-4.1.rc0

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

@robertwb
Copy link
Contributor Author

Attachment: 6083-integer-div.patch.gz

@fredrik-johansson
Copy link
Contributor

comment:1

I now get one trivial test failure (changed exception message):

File "/home/fredrik/sage-4.0/devel/sage-mpmath/sage/rings/integer.pyx", line 2163:
    sage: z % 0
Expected:
    Traceback (most recent call last):
    ...
    ZeroDivisionError: Integer modulo by zero
Got:
    Traceback (most recent call last):
      File "/space/wstein/farm/sage-4.0/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/wstein/farm/sage-4.0/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/wstein/farm/sage-4.0/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_46[4]>", line 1, in <module>
        z % Integer(0)###line 2163:
    sage: z % 0
      File "integer.pyx", line 2189, in sage.rings.integer.Integer.__mod__ (sage/rings/integer.c:15033)
    ZeroDivisionError: other must be nonzero

Otherwise, this patch has my approval.

@robertwb
Copy link
Contributor Author

robertwb commented Jun 3, 2009

comment:2

Thanks for looking at these. I'll fix this (the original error seems better).

@craigcitro
Copy link
Member

comment:3

This patch looks good. I've added a referee patch that makes a few really minor changes:

  • removes the unused _floordiv function
  • changes the error messages: they all now say either "Integer division by zero" or "Integer modulo by zero." I think these are more informative, and they also now mirror the Python ones (which all say "integer division or modulus by zero"). The old ones were of the form "other (=%s) must be nonzero"%other, and by definition always had other equal to 0, so that just seemed silly.

Unless Robert or Fredrik has any objections to the second patch, I'd say this is good to go.

@craigcitro craigcitro changed the title speedup integer division [with patch, with positive review modulo referee's patch] speedup integer division Jun 5, 2009
@robertwb
Copy link
Contributor Author

robertwb commented Jun 5, 2009

comment:4

Yep, looks good.

@robertwb robertwb changed the title [with patch, with positive review modulo referee's patch] speedup integer division speedup integer division Jun 5, 2009
@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 13, 2009

comment:5

Unfortunately, this causes a segfault with the 4.0.2.alpha0 singular:

----------------------------------------------------------------------

The following tests failed:

        sage -t -long devel/sage/sage/rings/polynomial/multi_polynomial_ideal.py # Segfault
----------------------------------------------------------------------
Total time for all tests: 524.4 seconds
Tests failed!

@craigcitro
Copy link
Member

comment:6

Attachment: trac-6083-referee.patch.gz

It turns out the segfault was coming from an infinite loop in Cython. The issue was that after the first patch above, doing Integer % IntegerMod_gmp would call into the __mod__ on IntegerMod_gmp, which tried to check if something was zero by doing something of the form Integer % IntegerMod_gmp ... and repeat ad infinitum.

So the new patch adds a small snippet to fix this, and a doctest.

@JohnCremona
Copy link
Member

comment:7

Although I have not been following all the details of this one, I applied all patches successfully to 4.1.alpha2 and ran -testall successfully, so I'm giving it a positive review.

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jul 4, 2009

Author: Robert Bradshaw

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jul 4, 2009

Merged: sage-4.1.rc0

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jul 4, 2009

Reviewer: Craig Citro

@rlmill rlmill mannequin removed the s: positive review label Jul 4, 2009
@rlmill rlmill mannequin closed this as completed Jul 4, 2009
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