From 0ca7158c0aca231180c973972ca38d952fa63e03 Mon Sep 17 00:00:00 2001 From: Hans Schoenemann Date: Fri, 28 Jun 2024 09:12:05 +0200 Subject: [PATCH] fix order of ring change and option setting --- deps/src/ideals.cpp | 39 +++++++++++++++++++-------------------- src/MessyHacks.jl | 22 ++++++++++++++++++++++ test/ideal/sideal-test.jl | 2 +- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/deps/src/ideals.cpp b/deps/src/ideals.cpp index 00f084b3b..bb96a12a2 100644 --- a/deps/src/ideals.cpp +++ b/deps/src/ideals.cpp @@ -134,7 +134,7 @@ auto id_Slimgb_helper(ideal a, ring b, bool complete_reduction = false) // bool complete_reduction= false; unsigned int crbit; if (complete_reduction) - auto crbit = Sy_bit(OPT_REDSB); + crbit = Sy_bit(OPT_REDSB); else crbit = 0; ideal id = NULL; @@ -144,11 +144,11 @@ auto id_Slimgb_helper(ideal a, ring b, bool complete_reduction = false) tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = t_rep_gb(b, a, a->rank); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -187,11 +187,11 @@ auto id_Std_helper(ideal a, ring b, bool complete_reduction = false) tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kStd(a, b->qideal, h, &n); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -238,11 +238,11 @@ auto id_MinStd_helper(ideal a, ring b, bool complete_reduction = false) tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kMin_std(a, b->qideal, h, NULL, m); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; return std::make_tuple(id, m); } @@ -275,11 +275,11 @@ auto id_StdHilb_helper(ideal a, tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kStd(a, b->qideal, h, &n, hilb); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -310,15 +310,15 @@ auto id_StdHilbWeighted_helper(ideal a, tHomog h = testHomog; const ring origin = currRing; unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; rChangeCurrRing(b); + si_opt_1 |= crbit; id = kStd(a, currRing->qideal, h, &n, // module weights hilb, // hilbert series 0, 0, // syzComp, newIdeal varweights); // weights of vars - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; if (n != NULL) delete n; } @@ -528,37 +528,36 @@ void singular_define_ideals(jlcxx::Module & Singular) Singular.method("id_LiftStd", [](ideal m, ring o, bool complete_reduction = false) { const ring origin = currRing; - rChangeCurrRing(o); - matrix ma = mpNew(1, 1); unsigned int crbit; if (complete_reduction) crbit = Sy_bit(OPT_REDSB); else crbit = 0; unsigned int save_opt = si_opt_1; + rChangeCurrRing(o); + matrix ma = mpNew(1, 1); si_opt_1 |= crbit; ideal res = idLiftStd(m, &ma, testHomog, NULL); - si_opt_1 = save_opt; rChangeCurrRing(origin); + si_opt_1 = save_opt; return std::make_tuple(res, ma); }); Singular.method("id_LiftStdSyz", [](ideal m, ring o, bool complete_reduction = false) { - const ring origin = currRing; - rChangeCurrRing(o); - matrix ma = mpNew(1, 1); - ideal syz = idInit(1, 1); unsigned int crbit; if (complete_reduction) crbit = Sy_bit(OPT_REDSB); else crbit = 0; unsigned int save_opt = si_opt_1; + const ring origin = currRing; + rChangeCurrRing(o); + matrix ma = mpNew(1, 1); + ideal syz = idInit(1, 1); si_opt_1 |= crbit; ideal res = idLiftStd(m, &ma, testHomog, &syz); - si_opt_1 = save_opt; - rChangeCurrRing(origin); + si_opt_1 = save_opt; return std::make_tuple(res, ma, syz); }); diff --git a/src/MessyHacks.jl b/src/MessyHacks.jl index ef5ca3b99..f3290b3e9 100644 --- a/src/MessyHacks.jl +++ b/src/MessyHacks.jl @@ -69,6 +69,28 @@ for (name, str) in [(:with_fastHC, "OPT_FASTHC") end end +function with_redTail(f, flag::Bool, R::PolyRingUnion) + old_flag = libSingular.set_option("OPT_REDTAIL", flag, R.ptr) + local g = nothing + try + g = f() + finally + libSingular.set_option("OPT_REDTAIL", old_flag, R.ptr) + end + return g +end + +function with_redThrough(f, flag::Bool, R::PolyRingUnion) + old_flag = libSingular.set_option("OPT_REDTHROUGH", flag, R.ptr) + local g = nothing + try + g = f() + finally + libSingular.set_option("OPT_REDTHROUGH", old_flag, R.ptr) + end + return g +end + #= messy hack #1: diff --git a/test/ideal/sideal-test.jl b/test/ideal/sideal-test.jl index d5417894e..3721bcf1c 100644 --- a/test/ideal/sideal-test.jl +++ b/test/ideal/sideal-test.jl @@ -396,7 +396,7 @@ end B = slimgb(I, complete_reduction=true) @test isequal(B, Ideal(R, 2y^2 + 3, x^2 + x*y + 1)) || - isequal(B, Ideal(x^2 + x*y + 1, 2y^2 + 3)) + isequal(B, Ideal(R, x^2 + x*y + 1, 2y^2 + 3)) @test B.isGB == true end