diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..83c6209e4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,18 @@ +AlignConsecutiveDeclarations: true +AlignTrailingComments: true +AllowShortBlocksOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +BinPackArguments: true +BinPackParameters: false +BreakBeforeBraces: Stroustrup +ColumnLimit: 78 +Cpp11BracedListStyle: true +IndentCaseLabels: true +IndentWidth: 4 +MaxEmptyLinesToKeep: 2 +PointerBindsToType: Middle +SpacesBeforeTrailingComments: 4 +UseTab: Never +SortIncludes: false diff --git a/deps/src/coeffs.cpp b/deps/src/coeffs.cpp index 93cc4270c..7d1ded8ae 100644 --- a/deps/src/coeffs.cpp +++ b/deps/src/coeffs.cpp @@ -1,107 +1,199 @@ #include "coeffs.h" -void singular_define_coeffs(jlcxx::Module& Singular) +void singular_define_coeffs(jlcxx::Module & Singular) { - /* initialise a coefficient ring */ - Singular.method("nInitChar",&nInitChar); - - /* get the characteristic of a coefficient domain */ - Singular.method("n_GetChar",[]( coeffs n ){ return n_GetChar(n);}); - - /* make a copy of a coefficient domain (actually just increments a reference count) */ - Singular.method("nCopyCoeff",&nCopyCoeff); - - /* kill a coefficient ring */ - Singular.method("nKillChar",&nKillChar); - - /* return a function to convert between rings */ - Singular.method("n_SetMap",[]( const coeffs x, const coeffs y){ return reinterpret_cast(n_SetMap(x,y)); }); - - Singular.method("nApplyMapFunc",[]( void* map, snumber* x, coeffs a, coeffs b ){ return reinterpret_cast(map)(x,a,b); }); - - Singular.method("n_Init",[]( long x, coeffs n){ return n_Init(x,n); }); - - Singular.method("n_Copy",[]( snumber* x, const coeffs n){ return n_Copy(x,n); }); - - Singular.method("nCoeff_has_simple_Alloc",[]( coeffs x ){ return nCoeff_has_simple_Alloc( x ) > 0; }); - - Singular.method("n_InitMPZ_internal",[]( void * ptr, coeffs x ){ return n_InitMPZ( reinterpret_cast<__mpz_struct *>(ptr), x); }); - - Singular.method("n_Delete",[]( snumber* n, coeffs cf) { number* t = &n; if( n != NULL ){ n_Delete(t, cf); } }); - - Singular.method("n_Delete_Q",[]( void* n, coeffs cf ) { number tt = reinterpret_cast(n); number* t = &tt; if( n != NULL ){ n_Delete(t, cf); } }); - - Singular.method("n_Write_internal",[]( snumber* x, coeffs cf, const int d ){ return n_Write(x,cf,d); }); - - Singular.method("n_Add",[]( snumber* a, snumber* b, coeffs c ){ return n_Add(a,b,c); }); - - Singular.method("n_Sub",[]( snumber* a, snumber* b, coeffs c ){ return n_Sub(a,b,c); }); - - Singular.method("n_Mult",[]( snumber* a, snumber* b, coeffs c ){ return n_Mult(a,b,c); }); - - Singular.method("n_Neg",[]( snumber* a, coeffs c ){ number nn = n_Copy(a, c); nn = n_InpNeg(nn, c); return nn; }); - - Singular.method("n_Invers",[]( snumber* a, coeffs c ){ return n_Invers(a,c); }); - - Singular.method("n_ExactDiv",[]( snumber* a, snumber* b, coeffs c ){ return n_ExactDiv(a,b,c); }); - - Singular.method("n_Div",[]( snumber* a, snumber* b, coeffs c ){ number z = n_Div(a, b, c); n_Normalize(z, c); return z; }); - - Singular.method("n_GetNumerator",[]( snumber* a, coeffs c){ return n_GetNumerator(a,c); }); - - Singular.method("n_GetDenom",[]( snumber* a, coeffs c){ return n_GetDenom(a,c); }); - - Singular.method("n_Power",[]( snumber* a, int b, coeffs c ){ number res; n_Power(a, b, &res, c); return res; }); - - Singular.method("n_Gcd",[]( snumber* a, snumber* b, coeffs c ){ return n_Gcd(a,b,c); }); - - Singular.method("n_SubringGcd",[]( snumber* a, snumber* b, coeffs c ){ return n_SubringGcd(a,b,c); }); - - Singular.method("n_Lcm",[]( snumber* a, snumber* b, coeffs c ){ return n_Lcm(a,b,c); }); - - Singular.method("n_ExtGcd_internal",[]( snumber* a, snumber* b, void* s, void* t, coeffs c ){ - return n_ExtGcd(a,b, - reinterpret_cast(s), - reinterpret_cast(t),c); }); - - Singular.method("n_IsZero",[]( snumber* x, const coeffs n ){ return n_IsZero( x,n ) > 0; }); - - Singular.method("n_IsOne",[]( snumber* x, const coeffs n ){ return n_IsOne( x,n ) > 0; }); - - Singular.method("n_Greater",[]( snumber* x, snumber* y, const coeffs n ){ return n_Greater( x,y,n ) > 0; }); - - Singular.method("n_GreaterZero",[]( snumber* x, const coeffs n ){ return n_GreaterZero( x,n ) > 0; }); - - Singular.method("n_Equal",[]( snumber* x, snumber* y, const coeffs n ){ return n_Equal( x,y,n ) > 0; }); - - Singular.method("n_InpAdd",[]( snumber* x, snumber* y, const coeffs n ){ snumber* xx = x; n_InpAdd( xx,y,n ); return xx; }); - - Singular.method("n_InpMult",[]( snumber* x, snumber* y, const coeffs n ){ return n_InpMult( x,y,n ); }); - - Singular.method("n_QuotRem_internal",[]( snumber* x, snumber* y, void* p, const coeffs n ){ return n_QuotRem( x,y,reinterpret_cast(p),n ); }); - - Singular.method("n_Rem",[]( snumber* x, snumber* y, const coeffs n ){ number qq; return n_QuotRem( x,y, &qq, n ); }); - - Singular.method("n_IntMod",&n_IntMod); - - Singular.method("n_Farey",&n_Farey); - - Singular.method("n_ChineseRemainderSym",[]( void* x, void* y, int n, int sign_flag, coeffs c ){ CFArray inv_cache(n); - return n_ChineseRemainderSym( reinterpret_cast(x),reinterpret_cast(y), n, sign_flag, inv_cache, c ); }); - - Singular.method("n_Param",[]( int x, const coeffs n ){ return n_Param(x,n); }); - - Singular.method("StringSetS_internal",[]( std::string m ){ return StringSetS(m.c_str()); }); - - Singular.method("StringEndS",[](){ char* m = StringEndS(); std::string s(m); omFree(m); return s; }); - - Singular.method("omAlloc0",[]( size_t siz ){ return (void*) omAlloc0(siz); }); - - Singular.method("omFree_internal",[]( void* m ){ omFree(m); }); - - /* Setting a Ptr{number} to a number */ - - Singular.method("setindex_internal",[]( void* x, snumber* y ){ *reinterpret_cast(x) = y; }); - - + /* initialise a coefficient ring */ + Singular.method("nInitChar", &nInitChar); + + /* get the characteristic of a coefficient domain */ + Singular.method("n_GetChar", [](coeffs n) { return n_GetChar(n); }); + + /* make a copy of a coefficient domain (actually just increments a + * reference count) */ + Singular.method("nCopyCoeff", &nCopyCoeff); + + /* kill a coefficient ring */ + Singular.method("nKillChar", &nKillChar); + + /* return a function to convert between rings */ + Singular.method("n_SetMap", [](const coeffs x, const coeffs y) { + return reinterpret_cast(n_SetMap(x, y)); + }); + + Singular.method("nApplyMapFunc", + [](void * map, snumber * x, coeffs a, coeffs b) { + return reinterpret_cast(map)(x, a, b); + }); + + Singular.method("n_Init", [](long x, coeffs n) { return n_Init(x, n); }); + + Singular.method("n_Copy", + [](snumber * x, const coeffs n) { return n_Copy(x, n); }); + + Singular.method("nCoeff_has_simple_Alloc", + [](coeffs x) { return nCoeff_has_simple_Alloc(x) > 0; }); + + Singular.method("n_InitMPZ_internal", [](void * ptr, coeffs x) { + return n_InitMPZ(reinterpret_cast<__mpz_struct *>(ptr), x); + }); + + Singular.method("n_Delete", [](snumber * n, coeffs cf) { + number * t = &n; + if (n != NULL) { + n_Delete(t, cf); + } + }); + + Singular.method("n_Delete_Q", [](void * n, coeffs cf) { + number tt = reinterpret_cast(n); + number * t = &tt; + if (n != NULL) { + n_Delete(t, cf); + } + }); + + Singular.method("n_Write_internal", + [](snumber * x, coeffs cf, const int d) { + return n_Write(x, cf, d); + }); + + Singular.method("n_Add", [](snumber * a, snumber * b, coeffs c) { + return n_Add(a, b, c); + }); + + Singular.method("n_Sub", [](snumber * a, snumber * b, coeffs c) { + return n_Sub(a, b, c); + }); + + Singular.method("n_Mult", [](snumber * a, snumber * b, coeffs c) { + return n_Mult(a, b, c); + }); + + Singular.method("n_Neg", [](snumber * a, coeffs c) { + number nn = n_Copy(a, c); + nn = n_InpNeg(nn, c); + return nn; + }); + + Singular.method("n_Invers", + [](snumber * a, coeffs c) { return n_Invers(a, c); }); + + Singular.method("n_ExactDiv", [](snumber * a, snumber * b, coeffs c) { + return n_ExactDiv(a, b, c); + }); + + Singular.method("n_Div", [](snumber * a, snumber * b, coeffs c) { + number z = n_Div(a, b, c); + n_Normalize(z, c); + return z; + }); + + Singular.method("n_GetNumerator", [](snumber * a, coeffs c) { + return n_GetNumerator(a, c); + }); + + Singular.method("n_GetDenom", + [](snumber * a, coeffs c) { return n_GetDenom(a, c); }); + + Singular.method("n_Power", [](snumber * a, int b, coeffs c) { + number res; + n_Power(a, b, &res, c); + return res; + }); + + Singular.method("n_Gcd", [](snumber * a, snumber * b, coeffs c) { + return n_Gcd(a, b, c); + }); + + Singular.method("n_SubringGcd", [](snumber * a, snumber * b, coeffs c) { + return n_SubringGcd(a, b, c); + }); + + Singular.method("n_Lcm", [](snumber * a, snumber * b, coeffs c) { + return n_Lcm(a, b, c); + }); + + Singular.method("n_ExtGcd_internal", [](snumber * a, snumber * b, + void * s, void * t, coeffs c) { + return n_ExtGcd(a, b, reinterpret_cast(s), + reinterpret_cast(t), c); + }); + + Singular.method("n_IsZero", [](snumber * x, const coeffs n) { + return n_IsZero(x, n) > 0; + }); + + Singular.method("n_IsOne", [](snumber * x, const coeffs n) { + return n_IsOne(x, n) > 0; + }); + + Singular.method("n_Greater", + [](snumber * x, snumber * y, const coeffs n) { + return n_Greater(x, y, n) > 0; + }); + + Singular.method("n_GreaterZero", [](snumber * x, const coeffs n) { + return n_GreaterZero(x, n) > 0; + }); + + Singular.method("n_Equal", [](snumber * x, snumber * y, const coeffs n) { + return n_Equal(x, y, n) > 0; + }); + + Singular.method("n_InpAdd", [](snumber * x, snumber * y, const coeffs n) { + snumber * xx = x; + n_InpAdd(xx, y, n); + return xx; + }); + + Singular.method("n_InpMult", + [](snumber * x, snumber * y, const coeffs n) { + return n_InpMult(x, y, n); + }); + + Singular.method("n_QuotRem_internal", [](snumber * x, snumber * y, + void * p, const coeffs n) { + return n_QuotRem(x, y, reinterpret_cast(p), n); + }); + + Singular.method("n_Rem", [](snumber * x, snumber * y, const coeffs n) { + number qq; + return n_QuotRem(x, y, &qq, n); + }); + + Singular.method("n_IntMod", &n_IntMod); + + Singular.method("n_Farey", &n_Farey); + + Singular.method("n_ChineseRemainderSym", [](void * x, void * y, int n, + int sign_flag, coeffs c) { + CFArray inv_cache(n); + return n_ChineseRemainderSym(reinterpret_cast(x), + reinterpret_cast(y), n, + sign_flag, inv_cache, c); + }); + + Singular.method("n_Param", + [](int x, const coeffs n) { return n_Param(x, n); }); + + Singular.method("StringSetS_internal", + [](std::string m) { return StringSetS(m.c_str()); }); + + Singular.method("StringEndS", []() { + char * m = StringEndS(); + std::string s(m); + omFree(m); + return s; + }); + + Singular.method("omAlloc0", + [](size_t siz) { return (void *)omAlloc0(siz); }); + + Singular.method("omFree_internal", [](void * m) { omFree(m); }); + + /* Setting a Ptr{number} to a number */ + + Singular.method("setindex_internal", [](void * x, snumber * y) { + *reinterpret_cast(x) = y; + }); } diff --git a/deps/src/coeffs.h b/deps/src/coeffs.h index 75a949f38..58c40cea2 100644 --- a/deps/src/coeffs.h +++ b/deps/src/coeffs.h @@ -3,7 +3,6 @@ #include "includes.h" -void singular_define_coeffs(jlcxx::Module&); +void singular_define_coeffs(jlcxx::Module &); #endif - diff --git a/deps/src/ideals.cpp b/deps/src/ideals.cpp index 41fe2bc29..60196c146 100644 --- a/deps/src/ideals.cpp +++ b/deps/src/ideals.cpp @@ -1,189 +1,206 @@ #include "ideals.h" -auto id_sres_helper(sip_sideal* m, int n, ring R) { - auto origin = currRing; - rChangeCurrRing(R); - syStrategy s = sySchreyer(m, n); - rChangeCurrRing(origin); - auto r = s->minres; - bool minimal = true; - if (r == NULL){ - r = s->fullres; +auto id_sres_helper(sip_sideal * m, int n, ring R) +{ + auto origin = currRing; + rChangeCurrRing(R); + syStrategy s = sySchreyer(m, n); + rChangeCurrRing(origin); + auto r = s->minres; + bool minimal = true; + if (r == NULL) { + r = s->fullres; minimal = false; - } - return std::make_tuple(reinterpret_cast(r),s->length,minimal); - + } + return std::make_tuple(reinterpret_cast(r), s->length, minimal); } -auto id_fres_helper(sip_sideal* I, int n, std::string method, ring R){ +auto id_fres_helper(sip_sideal * I, int n, std::string method, ring R) +{ auto origin = currRing; rChangeCurrRing(R); syStrategy s = syFrank(I, n, method.c_str()); rChangeCurrRing(origin); auto r = s->minres; bool minimal = true; - if(r==NULL){ + if (r == NULL) { r = s->fullres; minimal = false; } - return std::make_tuple(reinterpret_cast(r),s->length,minimal); + return std::make_tuple(reinterpret_cast(r), s->length, minimal); } -ideal id_Syzygies_internal(ideal m, ring o) -{ - ideal id = NULL; - intvec * n = NULL; - tHomog h = testHomog; - const ring origin = currRing; - rChangeCurrRing(o); - id = idSyzygies(m, h, &n); - rChangeCurrRing(origin); - if (n != NULL) - delete n; - return id; +ideal id_Syzygies_internal(ideal m, ring o) +{ + ideal id = NULL; + intvec * n = NULL; + tHomog h = testHomog; + const ring origin = currRing; + rChangeCurrRing(o); + id = idSyzygies(m, h, &n); + rChangeCurrRing(origin); + if (n != NULL) + delete n; + return id; +} + +auto id_Slimgb_helper(ideal a, ring b, bool complete_reduction = false) +{ + // bool complete_reduction= false; + unsigned int crbit; + if (complete_reduction == false) + auto crbit = Sy_bit(OPT_REDSB); + else + crbit = 0; + ideal id = NULL; + if (!idIs0(a)) { + intvec * n = NULL; + tHomog h = testHomog; + const ring origin = currRing; + unsigned int save_opt = si_opt_1; + si_opt_1 |= crbit; + rChangeCurrRing(b); + id = t_rep_gb(b, a, a->rank); + si_opt_1 = save_opt; + rChangeCurrRing(origin); + if (n != NULL) + delete n; + } + else + id = idInit(0, a->rank); + return id; } -auto id_Slimgb_helper(ideal a, ring b,bool complete_reduction=false) { -// bool complete_reduction= false; - unsigned int crbit; - if (complete_reduction == false) - auto crbit = Sy_bit(OPT_REDSB); - else - crbit = 0; - ideal id = NULL; - if (!idIs0(a)) - { - intvec * n = NULL; - tHomog h = testHomog; - const ring origin = currRing; - unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; - rChangeCurrRing(b); - id = t_rep_gb(b, a, a->rank); - si_opt_1 = save_opt; - rChangeCurrRing(origin); - if (n != NULL) - delete n; - } else - id = idInit(0, a->rank); - return id; -} - -auto id_Std_helper(ideal a, ring b, bool complete_reduction=false) { - //bool complete_reduction= false; - unsigned int crbit; - if (complete_reduction == false) - crbit = Sy_bit(OPT_REDSB); - else - crbit = 0; - ideal id = NULL; - if (!idIs0(a)) - { - intvec * n = NULL; - tHomog h = testHomog; - const ring origin = currRing; - unsigned int save_opt = si_opt_1; - si_opt_1 |= crbit; - rChangeCurrRing(b); - id = kStd(a, b->qideal, h, &n); - si_opt_1 = save_opt; - rChangeCurrRing(origin); - if (n != NULL) - delete n; - } else - id = idInit(0, a->rank); - return id; +auto id_Std_helper(ideal a, ring b, bool complete_reduction = false) +{ + // bool complete_reduction= false; + unsigned int crbit; + if (complete_reduction == false) + crbit = Sy_bit(OPT_REDSB); + else + crbit = 0; + ideal id = NULL; + if (!idIs0(a)) { + intvec * n = NULL; + tHomog h = testHomog; + const ring origin = currRing; + unsigned int save_opt = si_opt_1; + si_opt_1 |= crbit; + rChangeCurrRing(b); + id = kStd(a, b->qideal, h, &n); + si_opt_1 = save_opt; + rChangeCurrRing(origin); + if (n != NULL) + delete n; + } + else + id = idInit(0, a->rank); + return id; } -void singular_define_ideals(jlcxx::Module& Singular){ - Singular.method("id_Delete",[]( ideal m, ring n ) { return id_Delete(&m,n); }); +void singular_define_ideals(jlcxx::Module & Singular) +{ + Singular.method("id_Delete", + [](ideal m, ring n) { return id_Delete(&m, n); }); - Singular.method("id_Copy",&id_Copy); + Singular.method("id_Copy", &id_Copy); - Singular.method("idInit",&idInit); + Singular.method("idInit", &idInit); - Singular.method("setindex_internal",[]( ideal r, poly n, int o) {return r->m[o] = n; }); + Singular.method("setindex_internal", + [](ideal r, poly n, int o) { return r->m[o] = n; }); - Singular.method("getindex",[]( ideal r, int o) { return (poly) (r->m[o]); }); - - Singular.method("idIs0",&idIs0); + Singular.method("getindex", + [](ideal r, int o) { return (poly)(r->m[o]); }); - Singular.method("id_IsConstant",&id_IsConstant); + Singular.method("idIs0", &idIs0); - Singular.method("id_IsZeroDim",&id_IsZeroDim); + Singular.method("id_IsConstant", &id_IsConstant); - Singular.method("idElem",&idElem); + Singular.method("id_IsZeroDim", &id_IsZeroDim); - Singular.method("id_Normalize",&id_Normalize); + Singular.method("idElem", &idElem); - Singular.method("id_Head",&id_Head); + Singular.method("id_Normalize", &id_Normalize); - Singular.method("id_MaxIdeal",[](int m, ring n) { return id_MaxIdeal(m,n); }); + Singular.method("id_Head", &id_Head); - Singular.method("id_Add",&id_Add); + Singular.method("id_MaxIdeal", + [](int m, ring n) { return id_MaxIdeal(m, n); }); - Singular.method("id_Mult",&id_Mult); + Singular.method("id_Add", &id_Add); - Singular.method("id_Power",&id_Power); + Singular.method("id_Mult", &id_Mult); - Singular.method("id_IsEqual",[](ideal m, ideal n, ring o) { return mp_Equal((ip_smatrix *) m, (ip_smatrix *) n, o); }); + Singular.method("id_Power", &id_Power); - Singular.method("id_FreeModule",&id_FreeModule); + Singular.method("id_IsEqual", [](ideal m, ideal n, ring o) { + return mp_Equal((ip_smatrix *)m, (ip_smatrix *)n, o); + }); - Singular.method("idSkipZeroes",&idSkipZeroes); + Singular.method("id_FreeModule", &id_FreeModule); - Singular.method("ngens",[](ideal m) { return (int) IDELEMS(m); }); + Singular.method("idSkipZeroes", &idSkipZeroes); - Singular.method("rank",[](ideal m ) { return (int) m->rank; }); + Singular.method("ngens", [](ideal m) { return (int)IDELEMS(m); }); - // Singular.method("p_Copy",[](void o, ring r){ return p_Copy(o,r);}); + Singular.method("rank", [](ideal m) { return (int)m->rank; }); - Singular.method("id_Quotient",[](ideal a, ideal b, bool c, ring d) { - const ring origin = currRing; - rChangeCurrRing(d); - ideal id = idQuot(a, b, c, TRUE); - rChangeCurrRing(origin); - return id; }); + // Singular.method("p_Copy",[](void o, ring r){ return p_Copy(o,r);}); - Singular.method("id_Intersection",[](ideal a, ideal b, ring c) { - const ring origin = currRing; - rChangeCurrRing(c); - ideal id = idSect(a, b); - rChangeCurrRing(origin); - return id; }); + Singular.method("id_Quotient", [](ideal a, ideal b, bool c, ring d) { + const ring origin = currRing; + rChangeCurrRing(d); + ideal id = idQuot(a, b, c, TRUE); + rChangeCurrRing(origin); + return id; + }); - Singular.method("id_Syzygies",&id_Syzygies_internal); + Singular.method("id_Intersection", [](ideal a, ideal b, ring c) { + const ring origin = currRing; + rChangeCurrRing(c); + ideal id = idSect(a, b); + rChangeCurrRing(origin); + return id; + }); - Singular.method("id_sres",&id_sres_helper); + Singular.method("id_Syzygies", &id_Syzygies_internal); - Singular.method("id_fres",&id_fres_helper); + Singular.method("id_sres", &id_sres_helper); - Singular.method("id_Slimgb",&id_Slimgb_helper); + Singular.method("id_fres", &id_fres_helper); - Singular.method("id_Std",&id_Std_helper); + Singular.method("id_Slimgb", &id_Slimgb_helper); - Singular.method("id_Eliminate",[](ideal m, poly p, ring o) { - const ring origin = currRing; - rChangeCurrRing(o); - ideal res = idElimination(m, p); - rChangeCurrRing(origin); - return res; }); + Singular.method("id_Std", &id_Std_helper); - Singular.method("id_Satstd",&id_Satstd); + Singular.method("id_Eliminate", [](ideal m, poly p, ring o) { + const ring origin = currRing; + rChangeCurrRing(o); + ideal res = idElimination(m, p); + rChangeCurrRing(origin); + return res; + }); - Singular.method("id_Array2Vector",[]( void* p, int a, ring o) { - return id_Array2Vector( reinterpret_cast(p), a, o);} ); + Singular.method("id_Satstd", &id_Satstd); - Singular.method("p_Vector2Array",[](poly p, void* a, int b, ring o) { p_Vec2Array(p, reinterpret_cast(a), b, o); }); + Singular.method("id_Array2Vector", [](void * p, int a, ring o) { + return id_Array2Vector(reinterpret_cast(p), a, o); + }); - Singular.method("internal_void_to_poly_helper",[](void* p){ return reinterpret_cast(p);}); + Singular.method("p_Vector2Array", [](poly p, void * a, int b, ring o) { + p_Vec2Array(p, reinterpret_cast(a), b, o); + }); - Singular.method("maGetPreimage",[](ring trgt, ideal a, ideal b, ring src){ - sip_smap sing_map = { a->m, (char *)"julia_ring", 1, a->ncols }; - return maGetPreimage(trgt, &sing_map, b, src); + Singular.method("internal_void_to_poly_helper", + [](void * p) { return reinterpret_cast(p); }); - }); + Singular.method( + "maGetPreimage", [](ring trgt, ideal a, ideal b, ring src) { + sip_smap sing_map = {a->m, (char *)"julia_ring", 1, a->ncols}; + return maGetPreimage(trgt, &sing_map, b, src); + }); } \ No newline at end of file diff --git a/deps/src/ideals.h b/deps/src/ideals.h index 02f5c2661..8f596d3c2 100644 --- a/deps/src/ideals.h +++ b/deps/src/ideals.h @@ -3,7 +3,6 @@ #include "includes.h" -void singular_define_ideals(jlcxx::Module&); +void singular_define_ideals(jlcxx::Module &); #endif - diff --git a/deps/src/includes.h b/deps/src/includes.h index b6aee16a0..ff2023e0d 100644 --- a/deps/src/includes.h +++ b/deps/src/includes.h @@ -24,12 +24,12 @@ #include #include #include -#include +#include #include #include #include #include -#include +#include #include #include #include @@ -42,8 +42,10 @@ #include namespace jlcxx { - template<> struct IsBits : std::true_type {}; - template<> struct IsBits : std::true_type {}; -} +template <> struct IsBits : std::true_type { +}; +template <> struct IsBits : std::true_type { +}; +} // namespace jlcxx #endif \ No newline at end of file diff --git a/deps/src/matrices.cpp b/deps/src/matrices.cpp index 5062229f2..53541b04c 100644 --- a/deps/src/matrices.cpp +++ b/deps/src/matrices.cpp @@ -1,26 +1,32 @@ #include "matrices.h" -void singular_define_matrices(jlcxx::Module& Singular){ - Singular.method("ncols",[](matrix I){ return (int) MATCOLS(I);}); +void singular_define_matrices(jlcxx::Module & Singular) +{ + Singular.method("ncols", [](matrix I) { return (int)MATCOLS(I); }); - Singular.method("nrows",[](matrix I){ return (int) MATROWS(I); }); + Singular.method("nrows", [](matrix I) { return (int)MATROWS(I); }); - Singular.method("id_Module2Matrix",&id_Module2Matrix); + Singular.method("id_Module2Matrix", &id_Module2Matrix); - Singular.method("getindex",[](matrix M, int i, int j){ return (poly) MATELEM(M, i, j); }); + Singular.method("getindex", [](matrix M, int i, int j) { + return (poly)MATELEM(M, i, j); + }); - Singular.method("mp_Copy",[](matrix M, ring R){ return mp_Copy(M, R);}); + Singular.method("mp_Copy", + [](matrix M, ring R) { return mp_Copy(M, R); }); - Singular.method("mp_Delete",[](matrix M, ring R){ return mp_Delete(&M, R);}); + Singular.method("mp_Delete", + [](matrix M, ring R) { return mp_Delete(&M, R); }); - Singular.method("mp_Add",&mp_Add); + Singular.method("mp_Add", &mp_Add); - Singular.method("mp_Sub",&mp_Sub); + Singular.method("mp_Sub", &mp_Sub); - Singular.method("mp_Mult",&mp_Mult); + Singular.method("mp_Mult", &mp_Mult); - Singular.method("mp_Equal",&mp_Equal); - - Singular.method("iiStringMatrix",[](matrix I, int d, ring o){ return std::string(iiStringMatrix(I, d, o)); }); + Singular.method("mp_Equal", &mp_Equal); + Singular.method("iiStringMatrix", [](matrix I, int d, ring o) { + return std::string(iiStringMatrix(I, d, o)); + }); } \ No newline at end of file diff --git a/deps/src/matrices.h b/deps/src/matrices.h index 3876a64f2..e68b23a10 100644 --- a/deps/src/matrices.h +++ b/deps/src/matrices.h @@ -3,7 +3,6 @@ #include "includes.h" -void singular_define_matrices(jlcxx::Module&); +void singular_define_matrices(jlcxx::Module &); #endif - diff --git a/deps/src/rings.cpp b/deps/src/rings.cpp index 33dd5bca3..258238527 100644 --- a/deps/src/rings.cpp +++ b/deps/src/rings.cpp @@ -1,102 +1,186 @@ #include "rings.h" -auto rDefault_helper(coeffs cf, jlcxx::ArrayRef vars, rRingOrder_t ord){ - auto len = vars.size(); - char** vars_ptr = new char*[len]; - for(int i = 0;i vars, + rRingOrder_t ord) +{ + auto len = vars.size(); + char ** vars_ptr = new char *[len]; + for (int i = 0; i < len; i++) { + vars_ptr[i] = new char[vars[i].length() + 1]; + std::strcpy(vars_ptr[i], vars[i].c_str()); } - auto r = rDefault(cf,len,vars_ptr,ord); + auto r = rDefault(cf, len, vars_ptr, ord); delete[] vars_ptr; r->ShortOut = 0; return r; } -auto rDefault_long_helper(coeffs cf, jlcxx::ArrayRef vars, jlcxx::ArrayRef ord, int* blk0, int* blk1, unsigned long bitmask){ - auto len = vars.size(); - char** vars_ptr = new char*[len]; - for(int i = 0;i(vars[i]); +auto rDefault_long_helper(coeffs cf, + jlcxx::ArrayRef vars, + jlcxx::ArrayRef ord, + int * blk0, + int * blk1, + unsigned long bitmask) +{ + auto len = vars.size(); + char ** vars_ptr = new char *[len]; + for (int i = 0; i < len; i++) { + vars_ptr[i] = reinterpret_cast(vars[i]); // std::strcpy(vars_ptr[i],vars[i].c_str()); } - auto len_ord = ord.size(); - rRingOrder_t* ord_ptr = (rRingOrder_t*)omAlloc0(len_ord*sizeof(rRingOrder_t)); - for(int i = 0;iShortOut = 0; return r; } -void singular_define_rings(jlcxx::Module& Singular){ - Singular.method("rDefault_helper",&rDefault_helper); - Singular.method("rDefault_long_helper",&rDefault_long_helper); - Singular.method("rDelete",&rDelete); - Singular.method("rString",[](ip_sring* r){auto s = rString(r); return std::string(s);}); - Singular.method("rChar",&rChar); - Singular.method("rGetVar",&rGetVar); - Singular.method("rVar",&rVar); - Singular.method("rGetExpSize",[]( unsigned long bitmask, int N){ int bits; return static_cast(rGetExpSize(bitmask,bits,N));}); - Singular.method("rHasGlobalOrdering",&rHasGlobalOrdering); - Singular.method("rBitmask",[](ip_sring* r){ return (unsigned int)r->bitmask; }); - Singular.method("p_Delete",[](spolyrec* p, ip_sring* r){ return p_Delete(&p,r);}); - Singular.method("p_Copy",[](spolyrec* p, ip_sring* r){ return p_Copy(p,r);}); - Singular.method("p_IsOne",[](spolyrec* p, ip_sring* r){ return p_IsOne(p,r);}); - Singular.method("p_One",[](ip_sring* r){ return p_One(r);}); - Singular.method("p_Init",[](ip_sring*r ){ return p_Init(r);} ); - Singular.method("p_IsUnit",[](spolyrec* p, ip_sring* r){ return p_IsUnit(p,r);}); - Singular.method("p_GetExp",[](spolyrec* p, int i, ip_sring* r){ return p_GetExp(p,i,r);}); - Singular.method("p_GetComp",[](spolyrec* p, ip_sring* r){ return p_GetComp(p,r);}); - Singular.method("p_String",[](spolyrec* p, ip_sring* r){ std::string s(p_String(p,r)); return s; }); - Singular.method("p_ISet",[](long i, ip_sring* r){ return p_ISet(i,r);}); - Singular.method("p_NSet",[](snumber* p, ip_sring* r){ return p_NSet(p,r);}); - Singular.method("pLength",[](spolyrec* p){ return pLength(p);}); - Singular.method("SetpNext",[](spolyrec* p, spolyrec* q){ p->next = q; }); - Singular.method("pNext",[](spolyrec* a){ poly p = pNext(a); return p; }); - Singular.method("p_Neg",[](spolyrec* p, ip_sring* r){ return p_Neg(p,r); }); - Singular.method("pGetCoeff",[](spolyrec* p){ return pGetCoeff(p);}); - Singular.method("pSetCoeff",[](spolyrec* p, long c, ip_sring* r){ number n = n_Init(c,r); return p_SetCoeff(p,n,r); }); - Singular.method("pSetCoeff0",[](spolyrec* p, long c, ip_sring* r){ number n = n_Init(c,r); return p_SetCoeff0(p,n,r); }); - Singular.method("pLDeg",[](spolyrec* a, ip_sring* r){ long res; int dummy; if(a!=NULL){ res = r->pLDeg(a,&dummy,r);}else{ res = -1;} return res; }); - Singular.method("p_Add_q",[](spolyrec* p, spolyrec* q, ip_sring* r){ return p_Add_q(p,q,r); }); - Singular.method("p_Sub",[](spolyrec* p, spolyrec* q, ip_sring* r){ return p_Sub(p,q,r); }); - Singular.method("p_Mult_q",[](spolyrec* p, spolyrec* q, ip_sring* r){ return p_Mult_q(p,q,r); }); - Singular.method("p_Power",[](spolyrec* p, int q, ip_sring* r){ return p_Power(p,q,r); }); - Singular.method("p_EqualPolys",[](spolyrec* p, spolyrec* q, ip_sring* r){ return p_EqualPolys(p,q,r); }); - Singular.method("p_Divide",[](spolyrec* p, spolyrec* q, ip_sring* r){ return p_Divide(p,q,r); }); - Singular.method("singclap_gcd",[](spolyrec* p, spolyrec* q, ip_sring* r){ return singclap_gcd(p,q,r); }); - Singular.method("p_ExtGcd_internal",[]( spolyrec* a, spolyrec* b, void* res, void* s, void* t, ip_sring* r ){ return singclap_extgcd(a,b, - reinterpret_cast(res), - reinterpret_cast(s), - reinterpret_cast(t),r); }); - Singular.method("p_Content",[](spolyrec* p, ip_sring* r){ return p_Content(p,r); }); - Singular.method("p_GetExpVL_internal",[](spolyrec* p, long* ev, ip_sring* r){return p_GetExpVL(p,ev,r);}); - Singular.method("p_SetExpV_internal",[](spolyrec* p, int* ev, ip_sring* r){return p_SetExpV(p,ev,r);}); - Singular.method("p_Reduce",[](spolyrec* p, sip_sideal* G, ip_sring* R){ - const ring origin = currRing; - rChangeCurrRing(R); - poly res = kNF(G, R->qideal, p); - rChangeCurrRing(origin); - return res; - }); - Singular.method("p_Reduce",[](sip_sideal* p, sip_sideal* G, ip_sring* R){ - const ring origin = currRing; - rChangeCurrRing(R); - ideal res = kNF(G, R->qideal, p); - rChangeCurrRing(origin); - return res; - }); - - Singular.method("letterplace_ring_helper",[](ip_sring* r, long block_size){ - rUnComplete(r); - r->isLPring = block_size; - r->ShortOut = FALSE; - r->CanShortOut = FALSE; - rComplete(r); - }); +void singular_define_rings(jlcxx::Module & Singular) +{ + Singular.method("rDefault_helper", &rDefault_helper); + Singular.method("rDefault_long_helper", &rDefault_long_helper); + Singular.method("rDelete", &rDelete); + Singular.method("rString", [](ip_sring * r) { + auto s = rString(r); + return std::string(s); + }); + Singular.method("rChar", &rChar); + Singular.method("rGetVar", &rGetVar); + Singular.method("rVar", &rVar); + Singular.method("rGetExpSize", [](unsigned long bitmask, int N) { + int bits; + return static_cast(rGetExpSize(bitmask, bits, N)); + }); + Singular.method("rHasGlobalOrdering", &rHasGlobalOrdering); + Singular.method("rBitmask", + [](ip_sring * r) { return (unsigned int)r->bitmask; }); + Singular.method("p_Delete", [](spolyrec * p, ip_sring * r) { + return p_Delete(&p, r); + }); + Singular.method("p_Copy", + [](spolyrec * p, ip_sring * r) { return p_Copy(p, r); }); + Singular.method("p_IsOne", + [](spolyrec * p, ip_sring * r) { return p_IsOne(p, r); }); + Singular.method("p_One", [](ip_sring * r) { return p_One(r); }); + Singular.method("p_Init", [](ip_sring * r) { return p_Init(r); }); + Singular.method("p_IsUnit", [](spolyrec * p, ip_sring * r) { + return p_IsUnit(p, r); + }); + Singular.method("p_GetExp", [](spolyrec * p, int i, ip_sring * r) { + return p_GetExp(p, i, r); + }); + Singular.method("p_GetComp", [](spolyrec * p, ip_sring * r) { + return p_GetComp(p, r); + }); + Singular.method("p_String", [](spolyrec * p, ip_sring * r) { + std::string s(p_String(p, r)); + return s; + }); + Singular.method("p_ISet", + [](long i, ip_sring * r) { return p_ISet(i, r); }); + Singular.method("p_NSet", + [](snumber * p, ip_sring * r) { return p_NSet(p, r); }); + Singular.method("pLength", [](spolyrec * p) { return pLength(p); }); + Singular.method("SetpNext", + [](spolyrec * p, spolyrec * q) { p->next = q; }); + Singular.method("pNext", [](spolyrec * a) { + poly p = pNext(a); + return p; + }); + Singular.method("p_Neg", + [](spolyrec * p, ip_sring * r) { return p_Neg(p, r); }); + Singular.method("pGetCoeff", [](spolyrec * p) { return pGetCoeff(p); }); + Singular.method("pSetCoeff", [](spolyrec * p, long c, ip_sring * r) { + number n = n_Init(c, r); + return p_SetCoeff(p, n, r); + }); + Singular.method("pSetCoeff0", [](spolyrec * p, long c, ip_sring * r) { + number n = n_Init(c, r); + return p_SetCoeff0(p, n, r); + }); + Singular.method("pLDeg", [](spolyrec * a, ip_sring * r) { + long res; + int dummy; + if (a != NULL) { + res = r->pLDeg(a, &dummy, r); + } + else { + res = -1; + } + return res; + }); + Singular.method("p_Add_q", [](spolyrec * p, spolyrec * q, ip_sring * r) { + return p_Add_q(p, q, r); + }); + Singular.method("p_Sub", [](spolyrec * p, spolyrec * q, ip_sring * r) { + return p_Sub(p, q, r); + }); + Singular.method("p_Mult_q", [](spolyrec * p, spolyrec * q, ip_sring * r) { + return p_Mult_q(p, q, r); + }); + Singular.method("p_Power", [](spolyrec * p, int q, ip_sring * r) { + return p_Power(p, q, r); + }); + Singular.method("p_EqualPolys", + [](spolyrec * p, spolyrec * q, ip_sring * r) { + return p_EqualPolys(p, q, r); + }); + Singular.method("p_Divide", [](spolyrec * p, spolyrec * q, ip_sring * r) { + return p_Divide(p, q, r); + }); + Singular.method("singclap_gcd", + [](spolyrec * p, spolyrec * q, ip_sring * r) { + return singclap_gcd(p, q, r); + }); + Singular.method("p_ExtGcd_internal", [](spolyrec * a, spolyrec * b, + void * res, void * s, void * t, + ip_sring * r) { + return singclap_extgcd(a, b, reinterpret_cast(res), + reinterpret_cast(s), + reinterpret_cast(t), r); + }); + Singular.method("p_Content", [](spolyrec * p, ip_sring * r) { + return p_Content(p, r); + }); + Singular.method("p_GetExpVL_internal", + [](spolyrec * p, long * ev, ip_sring * r) { + return p_GetExpVL(p, ev, r); + }); + Singular.method("p_SetExpV_internal", + [](spolyrec * p, int * ev, ip_sring * r) { + return p_SetExpV(p, ev, r); + }); + Singular.method("p_Reduce", + [](spolyrec * p, sip_sideal * G, ip_sring * R) { + const ring origin = currRing; + rChangeCurrRing(R); + poly res = kNF(G, R->qideal, p); + rChangeCurrRing(origin); + return res; + }); + Singular.method("p_Reduce", + [](sip_sideal * p, sip_sideal * G, ip_sring * R) { + const ring origin = currRing; + rChangeCurrRing(R); + ideal res = kNF(G, R->qideal, p); + rChangeCurrRing(origin); + return res; + }); + Singular.method("letterplace_ring_helper", + [](ip_sring * r, long block_size) { + rUnComplete(r); + r->isLPring = block_size; + r->ShortOut = FALSE; + r->CanShortOut = FALSE; + rComplete(r); + }); } diff --git a/deps/src/rings.h b/deps/src/rings.h index 8c917ca72..b320c64ef 100644 --- a/deps/src/rings.h +++ b/deps/src/rings.h @@ -3,7 +3,6 @@ #include "includes.h" -void singular_define_rings(jlcxx::Module&); +void singular_define_rings(jlcxx::Module &); #endif - diff --git a/deps/src/singular.cpp b/deps/src/singular.cpp index 304a372bd..0208693dc 100644 --- a/deps/src/singular.cpp +++ b/deps/src/singular.cpp @@ -6,117 +6,121 @@ #include "matrices.h" - -JLCXX_MODULE define_julia_module(jlcxx::Module& Singular) +JLCXX_MODULE define_julia_module(jlcxx::Module & Singular) { - Singular.add_type("coeffs"); - Singular.add_bits("n_coeffType"); - Singular.set_const("n_Z",n_Z); - Singular.set_const("n_Q",n_Q); - Singular.set_const("n_Zn",n_Zn); - Singular.set_const("n_Zp",n_Zp); - Singular.set_const("n_GF",n_GF); - Singular.set_const("n_unknown",n_unknown); - Singular.add_type("number"); - Singular.add_type<__mpz_struct>("__mpz_struct"); - Singular.add_type("ring"); - Singular.add_type("poly"); - // Singular.add_type("nMapFunc"); - // Singular.add_type("vector"); - Singular.add_bits("rRingOrder_t"); - Singular.add_type("ideal"); - Singular.add_type("ip_smatrix"); - Singular.add_type("syStrategy"); - Singular.add_type("sip_smap"); + Singular.add_type("coeffs"); + Singular.add_bits("n_coeffType"); + Singular.set_const("n_Z", n_Z); + Singular.set_const("n_Q", n_Q); + Singular.set_const("n_Zn", n_Zn); + Singular.set_const("n_Zp", n_Zp); + Singular.set_const("n_GF", n_GF); + Singular.set_const("n_unknown", n_unknown); + Singular.add_type("number"); + Singular.add_type<__mpz_struct>("__mpz_struct"); + Singular.add_type("ring"); + Singular.add_type("poly"); + // Singular.add_type("nMapFunc"); + // Singular.add_type("vector"); + Singular.add_bits("rRingOrder_t"); + Singular.add_type("ideal"); + Singular.add_type("ip_smatrix"); + Singular.add_type("syStrategy"); + Singular.add_type("sip_smap"); - /* monomial orderings */ - Singular.set_const("ringorder_no", ringorder_no); - Singular.set_const("ringorder_lp", ringorder_lp); - Singular.set_const("ringorder_rp", ringorder_rp); - Singular.set_const("ringorder_dp", ringorder_dp); - Singular.set_const("ringorder_Dp", ringorder_Dp); - Singular.set_const("ringorder_ls", ringorder_ls); - Singular.set_const("ringorder_rs", ringorder_rs); - Singular.set_const("ringorder_ds", ringorder_ds); - Singular.set_const("ringorder_Ds", ringorder_Ds); - Singular.set_const("ringorder_c", ringorder_c); - Singular.set_const("ringorder_C", ringorder_C); + /* monomial orderings */ + Singular.set_const("ringorder_no", ringorder_no); + Singular.set_const("ringorder_lp", ringorder_lp); + Singular.set_const("ringorder_rp", ringorder_rp); + Singular.set_const("ringorder_dp", ringorder_dp); + Singular.set_const("ringorder_Dp", ringorder_Dp); + Singular.set_const("ringorder_ls", ringorder_ls); + Singular.set_const("ringorder_rs", ringorder_rs); + Singular.set_const("ringorder_ds", ringorder_ds); + Singular.set_const("ringorder_Ds", ringorder_Ds); + Singular.set_const("ringorder_c", ringorder_c); + Singular.set_const("ringorder_C", ringorder_C); - Singular.method("siInit",[](const char* path){ siInit(const_cast(path)); }); - Singular.method("versionString",[](){ return const_cast(versionString()); }); + Singular.method("siInit", [](const char * path) { + siInit(const_cast(path)); + }); + Singular.method("versionString", []() { + return const_cast(versionString()); + }); - singular_define_coeffs(Singular); - singular_define_rings(Singular); - singular_define_ideals(Singular); - singular_define_matrices(Singular); + singular_define_coeffs(Singular); + singular_define_rings(Singular); + singular_define_ideals(Singular); + singular_define_matrices(Singular); - /**************************** - ** from resolutions.jl - ***************************/ + /**************************** + ** from resolutions.jl + ***************************/ - Singular.method("res_Delete_helper",[](void* ra_void, int len, ring o){ - auto ra = reinterpret_cast(ra_void); - for (int i = 0; i < len; i++) { - id_Delete(ra + i, o); - } - omFreeSize((ADDRESS) ra, (len + 1)*sizeof(ideal));}); + Singular.method("res_Delete_helper", [](void * ra_void, int len, ring o) { + auto ra = reinterpret_cast(ra_void); + for (int i = 0; i < len; i++) { + id_Delete(ra + i, o); + } + omFreeSize((ADDRESS)ra, (len + 1) * sizeof(ideal)); + }); - Singular.method("res_Copy",[](void* ra_void, int len, ring o){ - auto ra = reinterpret_cast(ra_void); - resolvente res = (resolvente) omAlloc0((len + 1)*sizeof(ideal)); - rChangeCurrRing(o); - for (int i = len - 1; i >= 0; i--) - { - if (ra[i] != NULL) + Singular.method("res_Copy", [](void * ra_void, int len, ring o) { + auto ra = reinterpret_cast(ra_void); + resolvente res = (resolvente)omAlloc0((len + 1) * sizeof(ideal)); + rChangeCurrRing(o); + for (int i = len - 1; i >= 0; i--) { + if (ra[i] != NULL) res[i] = id_Copy(ra[i], o); - } - return reinterpret_cast(res); }); - + } + return reinterpret_cast(res); + }); - Singular.method("getindex",[](void* ra_void, int k){ - auto ra = reinterpret_cast(ra_void); - return (ideal) ra[k];}); + Singular.method("getindex", [](void * ra_void, int k) { + auto ra = reinterpret_cast(ra_void); + return (ideal)ra[k]; + }); - Singular.method("syMinimize",[](void* ra_void, int len, ring o){ - auto ra = reinterpret_cast(ra_void); - const ring origin = currRing; - syStrategy temp = (syStrategy) omAlloc0(sizeof(ssyStrategy)); - resolvente result; - rChangeCurrRing(o); - temp->fullres = (resolvente) omAlloc0((len + 1)*sizeof(ideal)); - for (int i = len - 1; i >= 0; i--) - { - if (ra[i] != NULL) - temp->fullres[i] = idCopy(ra[i]); - } - temp->length = len; - syMinimize(temp); - result = temp->minres; - temp->minres = NULL; - // syMinimize increments this as it returns a value we ignore - temp->references--; - syKillComputation(temp, o); - rChangeCurrRing(origin); - return reinterpret_cast(result);}); + Singular.method("syMinimize", [](void * ra_void, int len, ring o) { + auto ra = reinterpret_cast(ra_void); + const ring origin = currRing; + syStrategy temp = (syStrategy)omAlloc0(sizeof(ssyStrategy)); + resolvente result; + rChangeCurrRing(o); + temp->fullres = (resolvente)omAlloc0((len + 1) * sizeof(ideal)); + for (int i = len - 1; i >= 0; i--) { + if (ra[i] != NULL) + temp->fullres[i] = idCopy(ra[i]); + } + temp->length = len; + syMinimize(temp); + result = temp->minres; + temp->minres = NULL; + // syMinimize increments this as it returns a value we ignore + temp->references--; + syKillComputation(temp, o); + rChangeCurrRing(origin); + return reinterpret_cast(result); + }); - - Singular.method("syBetti",[](void* ra_void, int len, ring o){ - auto ra = reinterpret_cast(ra_void); - const ring origin = currRing; - rChangeCurrRing(o); - int dummy; - intvec *iv = syBetti(ra, len, &dummy, NULL, FALSE, NULL); - rChangeCurrRing(origin); - int nrows = iv->rows(); - int ncols = iv->cols(); - auto betti = (int *)malloc(ncols*nrows*sizeof(int)); - for (int i = 0; i < ncols; i++) { + Singular.method("syBetti", [](void * ra_void, int len, ring o) { + auto ra = reinterpret_cast(ra_void); + const ring origin = currRing; + rChangeCurrRing(o); + int dummy; + intvec * iv = syBetti(ra, len, &dummy, NULL, FALSE, NULL); + rChangeCurrRing(origin); + int nrows = iv->rows(); + int ncols = iv->cols(); + auto betti = (int *)malloc(ncols * nrows * sizeof(int)); + for (int i = 0; i < ncols; i++) { for (int j = 0; j < nrows; j++) { - betti[i*nrows+j] = IMATELEM(*iv, j+1, i+1); + betti[i * nrows + j] = IMATELEM(*iv, j + 1, i + 1); } - } - delete(iv); - return std::make_tuple(betti,nrows,ncols);}); + } + delete (iv); + return std::make_tuple(betti, nrows, ncols); + }); }