-
-
Notifications
You must be signed in to change notification settings - Fork 629
Add flatter support #40274
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
base: develop
Are you sure you want to change the base?
Add flatter support #40274
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
r""" | ||
Features for testing the presence of ``flatter`` | ||
""" | ||
|
||
from . import Executable | ||
|
||
|
||
class flatter(Executable): | ||
""" | ||
A :class:`~sage.features.Feature` describing the presence of ``flatter``. | ||
|
||
EXAMPLES:: | ||
|
||
sage: from sage.features.flatter import flatter | ||
sage: flatter().is_present() # optional - flatter | ||
FeatureTestResult('flatter', True) | ||
""" | ||
def __init__(self): | ||
r""" | ||
TESTS:: | ||
|
||
sage: from sage.features.flatter import flatter | ||
sage: isinstance(flatter(), flatter) | ||
True | ||
""" | ||
Executable.__init__(self, "flatter", executable="flatter") | ||
|
||
|
||
def all_features(): | ||
return [flatter()] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3024,6 +3024,10 @@ cdef class Matrix_integer_dense(Matrix_dense): | |
|
||
- ``'pari'`` -- pari's qflll | ||
|
||
- ``'flatter'`` -- external executable ``flatter``, requires manual install (see caveats below). | ||
Note that sufficiently new version of ``pari`` also supports FLATTER algorithm, see | ||
https://pari.math.u-bordeaux.fr/dochtml/html/Vectors__matrices__linear_algebra_and_sets.html#qflll. | ||
|
||
OUTPUT: a matrix over the integers | ||
|
||
EXAMPLES:: | ||
|
@@ -3097,6 +3101,16 @@ cdef class Matrix_integer_dense(Matrix_dense): | |
[0 0 0] | ||
[0 0 0] | ||
|
||
When ``algorithm='flatter'``, some matrices are not supported depends | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the sentence is broken.
|
||
on ``flatter``. For example:: | ||
|
||
sage: # needs flatter | ||
sage: m = matrix.zero(3, 2) | ||
sage: m.LLL(algorithm='flatter') | ||
Traceback (most recent call last): | ||
... | ||
ValueError: ... | ||
|
||
TESTS:: | ||
|
||
sage: matrix(ZZ, 0, 0).LLL() | ||
|
@@ -3153,6 +3167,17 @@ cdef class Matrix_integer_dense(Matrix_dense): | |
Although LLL is a deterministic algorithm, the output for | ||
different implementations and CPUs (32-bit vs. 64-bit) may | ||
vary, while still being correct. | ||
|
||
Check ``flatter``:: | ||
|
||
sage: # needs flatter | ||
sage: M = matrix(ZZ, 2, 2, [-1,1,1,1]) | ||
sage: L = M.LLL(algorithm="flatter") | ||
sage: abs(M.det()) == abs(L.det()) | ||
True | ||
sage: L = M.LLL(algorithm="flatter", delta=0.99) | ||
sage: abs(M.det()) == abs(L.det()) | ||
True | ||
""" | ||
if self.ncols() == 0 or self.nrows() == 0: | ||
verbose("Trivial matrix, nothing to do") | ||
|
@@ -3177,6 +3202,21 @@ cdef class Matrix_integer_dense(Matrix_dense): | |
raise TypeError("precision prec must be >= 0") | ||
prec = int(prec) | ||
|
||
if algorithm == 'flatter': | ||
import subprocess | ||
cmd = ["flatter"] | ||
if fp is not None or early_red or use_givens or transformation or eta is not None or use_siegel: | ||
raise TypeError("flatter does not support fp, early_red, use_givens, transformation, eta or use_siegel") | ||
if kwds: | ||
raise TypeError("flatter does not support additional keywords") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be more consistent to just ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better practice to complain to the user about invalid data than to silently ignore them. |
||
if delta is not None: | ||
cmd += ["-delta", str(delta)] | ||
stdout = subprocess.run( | ||
cmd, input="[" + "\n".join('[' + ' '.join(str(x) for x in row) + ']' for row in self) + "]", | ||
text=True, encoding="utf-8", stdout=subprocess.PIPE).stdout | ||
return self.new_matrix(entries=[[ZZ(x) for x in row.strip('[] ').split()] | ||
for row in stdout.strip('[] \n').split('\n')]) | ||
|
||
if algorithm == 'NTL:LLL': | ||
if fp is None: | ||
algorithm = 'NTL:LLL' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please provide Pari version info where this appeared. Also, do you know if this already is available from
cypari2
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from https://pari.math.u-bordeaux.fr/archives/pari-announce-24/msg00003.html
so, 2.17.0.
supposedly it's available
but pari is still slower than flatter on my machine. Demo where LLL is used to compute (integral) kernel of a matrix:
more: