Skip to content

Commit 9e98425

Browse files
author
Release Manager
committed
gh-35135: `sage.geometry.integral_points`: Use generic impl if no `matrix_integer_dense` <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> This is for the distribution sagemath-polyhedra (#32432) so that it does not have to depend on the flint library. <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [ ] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35135 Reported by: Matthias Köppe Reviewer(s): Jonathan Kliem, Matthias Köppe
2 parents 63ab60d + 60e3509 commit 9e98425

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

src/sage/geometry/integral_points.pyx renamed to src/sage/geometry/integral_points.pxi

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#cython: wraparound=False, boundscheck=False
21
r"""
32
Cython helper methods to compute integral points in polyhedra.
43
"""
@@ -19,16 +18,11 @@ import itertools
1918

2019
from sage.matrix.constructor import matrix, column_matrix, vector, diagonal_matrix
2120
from sage.rings.integer_ring import ZZ
22-
from sage.rings.rational_field import QQ
23-
from sage.rings.real_mpfr import RR
2421
from sage.rings.integer cimport Integer
25-
from sage.arith.misc import GCD as gcd
22+
from sage.arith.misc import gcd
2623
from sage.arith.functions import lcm
27-
from sage.combinat.permutation import Permutation
2824
from sage.misc.misc_c import prod
2925
from sage.modules.free_module import FreeModule
30-
from sage.modules.vector_integer_dense cimport Vector_integer_dense
31-
from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
3226

3327
##############################################################################
3428
# The basic idea to enumerate the lattice points in the parallelotope
@@ -140,8 +134,8 @@ cpdef tuple parallelotope_points(spanning_points, lattice):
140134
sage: len(parallelotope_points(rays, ZZ^4))
141135
967
142136
"""
143-
cdef Matrix_integer_dense VDinv
144-
cdef Matrix_integer_dense R = matrix(spanning_points).transpose()
137+
cdef MatrixClass VDinv
138+
cdef MatrixClass R = matrix(spanning_points).transpose()
145139
e, d, VDinv = ray_matrix_normal_form(R)
146140
cdef tuple points = loop_over_parallelotope_points(e, d, VDinv, R, lattice)
147141
for p in points:
@@ -183,8 +177,8 @@ cpdef tuple ray_matrix_normal_form(R):
183177

184178

185179
# The optimized version avoids constructing new matrices, vectors, and lattice points
186-
cpdef tuple loop_over_parallelotope_points(e, d, Matrix_integer_dense VDinv,
187-
Matrix_integer_dense R, lattice,
180+
cpdef tuple loop_over_parallelotope_points(e, d, MatrixClass VDinv,
181+
MatrixClass R, lattice,
188182
A=None, b=None):
189183
r"""
190184
The inner loop of :func:`parallelotope_points`.
@@ -224,7 +218,7 @@ cpdef tuple loop_over_parallelotope_points(e, d, Matrix_integer_dense VDinv,
224218
s = ZZ.zero() # summation variable
225219
cdef list gens = []
226220
gen = lattice(ZZ.zero())
227-
cdef Vector_integer_dense q_times_d = vector(ZZ, dim)
221+
cdef VectorClass q_times_d = vector(ZZ, dim)
228222
for base in itertools.product(*[ range(i) for i in e ]):
229223
for i in range(dim):
230224
s = ZZ.zero()
@@ -308,15 +302,15 @@ cpdef tuple simplex_points(vertices):
308302
cdef list rays = [vector(ZZ, list(v)) for v in vertices]
309303
if not rays:
310304
return ()
311-
cdef Vector_integer_dense origin = rays.pop()
305+
cdef VectorClass origin = rays.pop()
312306
origin.set_immutable()
313307
if not rays:
314308
return (origin,)
315309
translate_points(rays, origin)
316310

317311
# Find equation Ax<=b that cuts out simplex from parallelotope
318-
cdef Matrix_integer_dense Rt = matrix(ZZ, rays)
319-
cdef Matrix_integer_dense R = Rt.transpose()
312+
cdef MatrixClass Rt = matrix(ZZ, rays)
313+
cdef MatrixClass R = Rt.transpose()
320314
cdef int nrays = len(rays)
321315
cdef Integer b
322316
M = FreeModule(ZZ, nrays)
@@ -335,7 +329,7 @@ cpdef tuple simplex_points(vertices):
335329
return points
336330

337331

338-
cdef translate_points(v_list, Vector_integer_dense delta):
332+
cdef translate_points(v_list, VectorClass delta):
339333
r"""
340334
Add ``delta`` to each vector in ``v_list``.
341335
"""
@@ -568,7 +562,7 @@ cpdef rectangular_box_points(list box_min, list box_max,
568562
return loop_over_rectangular_box_points(box_min, box_max, inequalities, d, count_only)
569563
570564
cdef list points = []
571-
cdef Vector_integer_dense v = vector(ZZ, d)
565+
cdef VectorClass v = vector(ZZ, d)
572566
if not return_saturated:
573567
for p in loop_over_rectangular_box_points(box_min, box_max, inequalities, d, count_only):
574568
# v = vector(ZZ, perm_action(orig_perm, p)) # too slow
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
try:
2+
from .integral_points_integer_dense import (
3+
parallelotope_points,
4+
ray_matrix_normal_form,
5+
loop_over_parallelotope_points,
6+
simplex_points,
7+
rectangular_box_points,
8+
print_cache,
9+
Inequality_generic,
10+
Inequality_int,
11+
InequalityCollection,
12+
)
13+
except ImportError:
14+
from .integral_points_generic_dense import (
15+
parallelotope_points,
16+
ray_matrix_normal_form,
17+
loop_over_parallelotope_points,
18+
simplex_points,
19+
rectangular_box_points,
20+
print_cache,
21+
Inequality_generic,
22+
Inequality_int,
23+
InequalityCollection,
24+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#cython: wraparound=False, boundscheck=False
2+
3+
from sage.modules.vector_integer_dense cimport Vector_integer_dense as VectorClass
4+
from sage.matrix.matrix_dense cimport Matrix_dense as MatrixClass
5+
6+
include "integral_points.pxi"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#cython: wraparound=False, boundscheck=False
2+
3+
from sage.modules.vector_integer_dense cimport Vector_integer_dense as VectorClass
4+
from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense as MatrixClass
5+
6+
include "integral_points.pxi"

src/sage/matrix/matrix_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
397397
else:
398398
return matrix_integer_sparse.Matrix_integer_sparse
399399

400-
if R is sage.rings.real_double.RDF or R is sage.rings.complex_double.CDF:
400+
if isinstance(R, (sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField)):
401401
from . import matrix_double_sparse
402402
return matrix_double_sparse.Matrix_double_sparse
403403

0 commit comments

Comments
 (0)