Skip to content

Commit

Permalink
gh-38365: add access to printlevel in libsingular
Browse files Browse the repository at this point in the history
    
this is adding and using a simplified access to libsingular
``printlevel`` state variable

useful in turning down the comments easily

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: #38365
Reported by: Frédéric Chapoton
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Aug 2, 2024
2 parents 6bc3b9c + 1a387d8 commit cbe23c7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/sage/libs/singular/decl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ cdef extern from "singular/Singular/libsingular.h":
cdef int si_opt_2 # previously 'verbose'
cdef void * currentVoice
cdef int myynest
cdef int printlevel

ctypedef char * const_char_ptr "const char *"
cdef extern void (*WerrorS_callback)(const_char_ptr)
Expand Down
39 changes: 39 additions & 0 deletions src/sage/libs/singular/function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,45 @@ def lib(name):
raise NameError("Singular library {!r} not found".format(name))


def get_printlevel():
"""
Return the value of the variable ``printlevel``.
This is useful to switch off and back the comments.
EXAMPLES::
sage: from sage.libs.singular.function import get_printlevel, set_printlevel
sage: l = get_printlevel()
sage: set_printlevel(-1)
sage: get_printlevel()
-1
sage: set_printlevel(l)
"""
global printlevel
cdef int pl = printlevel
return pl


def set_printlevel(l):
"""
Set the value of the variable ``printlevel``.
This is useful to switch off and back the comments.
EXAMPLES::
sage: from sage.libs.singular.function import get_printlevel, set_printlevel
sage: l = get_printlevel()
sage: set_printlevel(2)
sage: get_printlevel()
2
sage: set_printlevel(l)
"""
global printlevel
printlevel = <int>l


def list_of_functions(packages=False):
"""
Return a list of all function names currently available.
Expand Down
19 changes: 7 additions & 12 deletions src/sage/rings/function_field/function_field_polymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2380,22 +2380,17 @@ def _singular_normal(ideal):
sage: _singular_normal(ideal(f))
[[1]]
"""
from sage.libs.singular.function import singular_function, lib
lib('normal.lib')
from sage.libs.singular.function import (singular_function,
lib as singular_lib,
get_printlevel, set_printlevel)
singular_lib('normal.lib')
normal = singular_function('normal')
execute = singular_function('execute')

try:
get_printlevel = singular_function('get_printlevel')
except NameError:
execute('proc get_printlevel {return (printlevel);}')
get_printlevel = singular_function('get_printlevel')

# It's fairly verbose unless printlevel is -1.
# verbose unless printlevel is -1.
saved_printlevel = get_printlevel()
execute('printlevel=-1')
set_printlevel(-1)
nor = normal(ideal)
execute('printlevel={}'.format(saved_printlevel))
set_printlevel(saved_printlevel)

return nor[1]

Expand Down
17 changes: 7 additions & 10 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5837,20 +5837,17 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
"""
R = self.parent()
algorithm = algorithm.lower()
from sage.libs.singular.function import singular_function, lib as singular_lib
from sage.libs.singular.function import (singular_function,
get_printlevel,
set_printlevel,
lib as singular_lib)
singular_lib('algebra.lib')
if algorithm == "algebra_containment":
execute = singular_function('execute')
try:
get_printlevel = singular_function('get_printlevel')
except NameError:
execute('proc get_printlevel {return (printlevel);}')
get_printlevel = singular_function('get_printlevel')
# It's fairly verbose unless printlevel is -1.
# verbose unless printlevel is -1.
saved_printlevel = get_printlevel()
execute('printlevel=-1')
set_printlevel(-1)
contains = singular_function('algebra_containment')(self, R.ideal(J)) == 1
execute('printlevel={}'.format(saved_printlevel))
set_printlevel(saved_printlevel)
return contains
elif algorithm == "insubring":
return singular_function('inSubring')(self, R.ideal(J))[0] == 1
Expand Down
29 changes: 20 additions & 9 deletions src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
from sage.categories.fields import Fields
from sage.categories.homset import hom, Hom, End
from sage.categories.number_fields import NumberFields
from sage.libs.singular.function import singular_function, lib as singular_lib, get_printlevel, set_printlevel
from sage.matrix.constructor import matrix
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_attribute import lazy_attribute
Expand Down Expand Up @@ -1662,10 +1663,18 @@ def is_complete_intersection(self):
sage: C.is_complete_intersection()
False
"""
singular.lib("sing.lib")
id = singular.simplify(self.defining_ideal(), 10)
L = singular.is_ci(id).sage()
return len(self.ambient_space().gens()) - len(id.sage().gens()) == L[-1]
singular_lib("sing.lib")
simplify = singular_function("simplify")
is_ci = singular_function("is_ci")

# verbose unless printlevel is -1.
saved_printlevel = get_printlevel()
set_printlevel(-1)
id = simplify(self.defining_ideal(), 10)
L = is_ci(id)[-1]
set_printlevel(saved_printlevel)

return len(self.ambient_space().gens()) - len(id) == L

def tangent_line(self, p):
"""
Expand Down Expand Up @@ -1860,11 +1869,13 @@ def rational_parameterization(self):
raise TypeError("this curve must have geometric genus zero")
if not isinstance(self.base_ring(), RationalField):
raise TypeError("this curve must be defined over the rational field")

singular.lib("paraplanecurves.lib")
R = singular.paraPlaneCurve(self.defining_polynomial())
singular.setring(R)
param = singular('PARA').sage().gens()
R = singular.paraPlaneCurve(self.defining_polynomial()) # ring
R.set_ring()
param = singular('PARA').sage().gens() # ideal
R = R.sage()

C = self.change_ring(R.base_ring())
H = Hom(ProjectiveSpace(R.base_ring(), 1, R.gens()), C)
return H(param)
Expand Down Expand Up @@ -2043,7 +2054,7 @@ def _points_via_singular(self, sort=True):

X2 = singular.NSplaces(1, X1)
R = X2[5][1][1]
singular.set_ring(R)
R.set_ring()

# We use sage_flattened_str_list since iterating through
# the entire list through the sage/singular interface directly
Expand Down Expand Up @@ -2127,7 +2138,7 @@ def riemann_roch_basis(self, D):
pnts = [(int(v[i][0]), int(v[i][2])-1) for i in range(len(v))]
# retrieve coordinates of rational points
R = X2[5][1][1]
singular.set_ring(R)
R.set_ring()
v = singular('POINTS').sage_flattened_str_list()
coords = [self(int(v[3*i]), int(v[3*i+1]), int(v[3*i+2])) for i in range(len(v)//3)]
# build correct representation of D for singular
Expand Down

0 comments on commit cbe23c7

Please sign in to comment.