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 GCD when input is Gaussian Integer #97

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions benchmarks/polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def to_poly(self, expr):
return Poly(expr, self.syms)

def to_ring(self, expr):
return self.ring(expr)
try:
return self.ring(expr)
except:
return expr
1e9abhi1e10 marked this conversation as resolved.
Show resolved Hide resolved

def as_expr(self):
return (self.f, self.g, self.d, self.syms)
Expand Down Expand Up @@ -181,7 +184,7 @@ class _GaussianInteger(_GCDExample):
def make_poly(self, n):
x, y1, y2, y3, y4, y5, y6 = syms = symbols("x y1 y2 y3 y4 y5 y6")

d = (-x**3 + I*x**2 + x)**n
d = (-x + I*y1)**n

f = ((-I*(x)**4 - (x)**3 + I*(x)**2 + (x) + -I*(y2 + 1) - y1*(y3 + 1) -
2*y1*y2 - 5*y1*(y2 + 1) - y1*(y3 + 1) -
Expand Down Expand Up @@ -235,7 +238,10 @@ def setup(self, n, impl):
expected = examples.to_poly(expected)

elif impl == 'sparse':
func = self.get_func_sparse(*examples.as_ring())
try:
func = self.get_func_sparse(*examples.as_ring())
except:
func = self.get_func_expr(*examples.as_expr())
if isinstance(expected, list):
expected = [examples.to_ring(p) for p in expected]
else:
Expand All @@ -248,7 +254,7 @@ def time_op(self, n, impl):
self.returned_result = self.func()

def teardown(self, n, impl):
assert self.expected_result == self.returned_result
assert self.expected_result.as_expr() == self.returned_result.as_expr()


class _TimePREM(_TimeOP):
Expand Down Expand Up @@ -390,7 +396,9 @@ def get_func_poly(self, f, g, d):
return lambda: f.gcd(g)

def get_func_sparse(self, f, g, d, syms):
return lambda: f.gcd(g)
fpe = ZZ_I[syms](f)
gpe = ZZ_I[syms](g)
return lambda: fpe.gcd(gpe)

class TimeGCD_GaussInt(_TimeGaussianInt):
GCDExampleCLS = _GaussianInteger
Expand Down