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

Add benchmarks for pseudo quotient method #93

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions benchmarks/polys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sympy import symbols, prod, prem, rem, degree, LC
from sympy import symbols, prod, prem, rem, degree, LC, pquo, quo
from sympy.polys import QQ, Poly


Expand Down Expand Up @@ -50,7 +50,6 @@ def as_poly(self):
def as_ring(self):
return (self.to_ring(self.f), self.to_ring(self.g), self.to_ring(self.d), self.ring)


class _LinearDenseQuadraticGCD(_GCDExample):
"""A pair of linearly dense quartic inputs with quadratic GCDs"""

Expand All @@ -71,7 +70,6 @@ def make_poly(self, n):
g = d * (2 + x ** (n + 1) + sum([y[i] ** (n + 1) for i in range(n)]))
return f, g, d, syms


class _QuadraticNonMonicGCD(_GCDExample):
Comment on lines 71 to 73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these lines deleted? Usually there should be two lines between top level statements like def and class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there should be one line between subclasses, I will correct myself.

"""A pair of quadratic polynomials with a non-monic GCD."""

Expand All @@ -82,7 +80,6 @@ def make_poly(self, n):
g = d * (2 + x * y[0] + sum(y[1:n])) ** 2
return f, g, d, syms


class _SparseNonMonicQuadratic(_GCDExample):
"""A pair of sparse non-monic quadratic polynomials with linear GCDs."""

Expand Down Expand Up @@ -127,8 +124,8 @@ def time_op(self, n, impl):
def teardown(self, n, impl):
assert self.expected_result == self.returned_result


class _TimePREM(_TimeOP):
"""Benchmarks for pseudo-remainder method"""

def expected(self, f, g, d, syms):
x = syms[0]
Expand Down Expand Up @@ -162,5 +159,44 @@ class TimePREM_QuadraticNonMonicGCD(_TimePREM):


class TimePREM_SparseNonMonicQuadratic(_TimePREM):
GCDExampleCLS = _SparseNonMonicQuadratic
params = [(1, 3, 5, 8), ('expr', 'dense', 'sparse')]


class _TimePQUO(_TimeOP):
"""Benchmarks for pseudo-quotient method"""

def expected(self, f, g, d, syms):
x = syms[0]
pquo_f_g_x = quo(f * LC(g, x) ** (degree(f, x) - degree(g, x) + 1), g, x)
return pquo_f_g_x

def get_func_expr(self, f, g, d, syms):
x = syms[0]
return lambda: pquo(f, g, x)

def get_func_poly(self, f, g, d):
return lambda: f.pquo(g)

def get_func_sparse(self, f, g, d, ring):
return lambda: f.pquo(g)


class TimePQUO_LinearDenseQuadraticGCD(_TimePQUO):
GCDExampleCLS = _LinearDenseQuadraticGCD
params = [(1, 3, 5), ('expr', 'dense', 'sparse')] # This case is slow for n=8.


class TimePQUO_SparseGCDHighDegree(_TimePQUO):
GCDExampleCLS = _SparseGCDHighDegree
params = [(1, 3, 5, 8), ('expr', 'dense', 'sparse')]


class TimePQUO_QuadraticNonMonicGCD(_TimePQUO):
GCDExampleCLS = _QuadraticNonMonicGCD
params = [(1, 3, 5), ('expr', 'dense', 'sparse')] # This case is slow for n=8.


class TimePQUO_SparseNonMonicQuadratic(_TimePQUO):
GCDExampleCLS = _SparseNonMonicQuadratic
params = [(1, 3, 5, 8), ('expr', 'dense', 'sparse')]