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 access to printlevel in libsingular #38365

Merged
merged 3 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -1824,6 +1824,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 @@ -2390,22 +2390,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 @@ -5858,20 +5858,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 @@ -1660,10 +1661,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 @@ -1861,11 +1870,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 @@ -2050,7 +2061,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 @@ -2134,7 +2145,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
Loading