gfan: update to 0.7.

This commit is contained in:
Gonzalo Tornaría 2024-10-29 08:20:24 -03:00 committed by classabbyamp
parent 4d10a0bd29
commit 8b49e95a7c
9 changed files with 310 additions and 248 deletions

View file

@ -0,0 +1,14 @@
Description: Include <cstdint> for std::int64_t
Author: Doug Torrance <dtorrance@debian.org>
Last-Update: 2024-07-28
--- a/src/gfanlib_z.h
+++ b/src/gfanlib_z.h
@@ -11,6 +11,7 @@
#include <string.h>
#include <ostream>
#include <iostream>
+#include <cstdint>
#define OLD 1
#if OLD
#include "gmp.h"

View file

@ -0,0 +1,13 @@
diff -ru gfan0.7.orig/src/gfanlib_circuittableint.h gfan0.7/src/gfanlib_circuittableint.h
--- gfan0.7.orig/src/gfanlib_circuittableint.h 2024-08-15 22:42:58.870553297 +0200
+++ gfan0.7/src/gfanlib_circuittableint.h 2024-08-15 22:44:11.891350667 +0200
@@ -591,7 +591,8 @@
ret=min;
{
- auto ret2=CircuitTableIntPOD((s.v*denominatorDivisor.multiplicativeInverse)*boundA.v);
+ CircuitTableIntPOD ret2;
+ ret2.v=(s.v*denominatorDivisor.multiplicativeInverse)*boundA.v;
ret2=MIN(ret2.v,-ret2.v);
return ret2;
if(ret.v!=ret2.v)

View file

@ -1,18 +0,0 @@
patch typedef for `int64` which causes hang in `0602ResultantFanProjection`
cf:
https://github.com/void-linux/void-packages/pull/34182
https://trac.sagemath.org/ticket/32088
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=905300
--- a/src/vektor.h 2017-06-20 11:47:37.000000000 -0300
+++ b/src/vektor.h 2021-11-21 18:28:43.384750825 -0300
@@ -10,7 +10,7 @@
using namespace std;
-typedef signed long int int64;
+typedef int64_t int64;
void outOfRange(int i, int n);

View file

@ -0,0 +1,225 @@
Description: Use 128-bit integers from Abseil when not available natively.
Author: Doug Torrance <dtorrance@debian.org>
Last-Update: 2024-10-24
--- a/src/gfanlib_circuittableint.h
+++ b/src/gfanlib_circuittableint.h
@@ -17,6 +17,12 @@
#include <iomanip>
#include "gfanlib_frequencytable.h"
+#ifndef __SIZEOF_INT128__
+#include <absl/numeric/int128.h>
+typedef absl::int128 __int128_t;
+typedef absl::uint128 __uint128_t;
+#endif
+
namespace gfan{
@@ -25,7 +31,8 @@
template<typename> struct MyMakeUnsigned;
template <> struct MyMakeUnsigned<int>{typedef unsigned int type;};
template <> struct MyMakeUnsigned<long int>{typedef unsigned long int type;};
- template <> struct MyMakeUnsigned<__int128>{typedef unsigned __int128 type;};
+ template <> struct MyMakeUnsigned<long long int>{typedef unsigned long long int type;};
+ template <> struct MyMakeUnsigned<__int128_t>{typedef __uint128_t type;};
class MVMachineIntegerOverflow: public std::exception
{
@@ -92,6 +99,15 @@
return s.str();
}
+#ifndef __SIZEOF_INT128__
+static std::string toStr(long int b)
+{
+ std::stringstream s;
+ s<<b;
+ return s.str();
+}
+#endif
+
class my256s{
public:
__int128_t lo,hi;
@@ -106,6 +122,23 @@
{
if(v<0)hi=-1;
}
+#ifndef __SIZEOF_INT128__
+ my256s(int lo_,__int128_t hi_):
+ lo(static_cast<__int128_t>(lo_)),
+ hi(hi_)
+ {
+ }
+ my256s(__uint128_t lo_,__int128_t hi_):
+ lo(static_cast<__int128_t>(lo_)),
+ hi(hi_)
+ {
+ }
+ my256s(__int128_t lo_,__uint128_t hi_):
+ lo(lo_),
+ hi(static_cast<__int128_t>(hi_))
+ {
+ }
+#endif
my256s operator+(my256s b)
{
__uint128_t newLo=lo+b.lo;
@@ -165,7 +198,7 @@
my256s temp(~lo,~hi);
return temp+my256s(1,0);
}
- explicit operator __int128()const
+ explicit operator __int128_t()const
{
return lo;
}
@@ -213,12 +246,23 @@
{
return ((__int128_t)a)*((__int128_t)b);
}
+static long long int extMul(long long int a, long long int b)
+{
+ return a * b;
+}
static __uint128_t unsignedProd64(uint64_t x,uint64_t y)
{
return __uint128_t(x)*__uint128_t(y);
}
+#ifndef __SIZEOF_INT128__
+static __uint128_t unsignedProd64(__uint128_t x,__uint128_t y)
+{
+ return x * y;
+}
+#endif
+
static my256u unsignedProd128(__uint128_t x,__uint128_t y)
{
my256s a(unsignedProd64(x,y),0);
@@ -302,7 +346,7 @@
friend CircuitTableIntPOD operator*(CircuitTableIntPOD const &a, CircuitTableIntPOD const &b){CircuitTableIntPOD ret;ret.v=a.v*b.v;return ret;}
friend CircuitTableIntPOD operator/(CircuitTableIntPOD const &a, CircuitTableIntPOD const &b){CircuitTableIntPOD ret;ret.v=a.v/b.v;return ret;}//This is used very few times. Should we require this be an exact division?
public:
- static const word halfBound{(word{1}<<(std::numeric_limits<word>::digits/2-2))-1};
+ static constexpr word halfBound{(word{1}<<(std::numeric_limits<word>::digits/2-2))-1};
// In the code products of CircuitTableIntPOD objects are summed. To avoid overflows one of the factors must "fit in half" and the "number of summands" may not exceed a certain number. The bounds are specified in the following functions:
bool fitsInHalf()const{return v>-halfBound && v<halfBound;}// Is it better to allow only non-negative numbers?
static bool isSuitableSummationNumber(int numberOfSummands){return numberOfSummands<halfBound;}
@@ -352,7 +396,7 @@
// return std::to_string((int64_t)v);/*cast seems to be needed (128 bit will not work)*/
return toStr(v);
}
- int64_t toInt64()const{return v;}//WHAT SHOULD HAPPEN TO THIS FUNCTION?
+ int64_t toInt64()const{return static_cast<int64_t>(v);}//WHAT SHOULD HAPPEN TO THIS FUNCTION?
friend std::ostream &operator<<(std::ostream &f, CircuitTableIntPOD const &a){f<</*(int)*/a.toString();return f;}
Double extend()const{Double ret;ret.v=v;return ret;}
CircuitTableIntPOD &maddWithOverflowChecking(CircuitTableIntPOD const &a, CircuitTableIntPOD const&b){Double t=this->extend();t+=extendedMultiplication(a,b);*this=t.castToSingle();return *this;}
@@ -546,8 +590,8 @@
int D=std::numeric_limits<word>::digits;
if(D==0){D=127;}//fixes bug in gcc-8.1
bool doesOverflow=(((word)t.v)==(word{1}<<(D-1)));// What is the purpose of this line. Do we really want to subtract 1? That seems wrong since word is signed. Look at comment below
- longword min64=0;
- longword max64=0;
+ longword min64=static_cast<longword>(0);
+ longword max64=static_cast<longword>(0);
for(int i=0;i<c;i++)
{
// In the unlikely event that all the numbers to be multiplied are -2^31, the following code will overflow. Therefore the overflow flag was set as above.
@@ -569,15 +613,14 @@
static CircuitTableIntPOD quickScaleNoShiftBounded(CircuitTableIntPOD * __restrict__ aa, CircuitTableIntPOD s, CircuitTableIntPOD::Divisor denominatorDivisor,int c, CircuitTableIntPOD boundA)
{
// assert(!boundA.isPositive());
- if(0)
- {
+#if 0
static FrequencyTable A("Multiplier");
A.record(s.toInt64()&255);
static FrequencyTable B("Divisor");
B.record(denominatorDivisor.v&255);
static FrequencyTable C("AreEqual");
C.record(s.toInt64()==denominatorDivisor.v);
- }
+#endif
CircuitTableIntPOD max{};assert(max.v==0);
CircuitTableIntPOD min{};assert(min.v==0);
CircuitTableIntPOD ret{};assert(ret.v==0);
@@ -663,8 +706,8 @@
int D=std::numeric_limits<word>::digits;
if(D==0){D=127;}//fixes bug in gcc-8.1
bool doesOverflow=false;//(((word)t.v)==(word{1}<<(D-1)));// What is the purpose of this line? t is not defined. Do we really want to subtract 1? That seems wrong since word is signed. Look at comment below
- longword min64=0;
- longword max64=0;
+ longword min64=static_cast<longword>(0);
+ longword max64=static_cast<longword>(0);
for(int i=0;i<c;i++)
{
longword/*int64_t*/ temp=(extMul(s.v,aa[i].v))/denominatorDivisor.v;
@@ -737,7 +780,7 @@
{
if(v>=0x7fffffffffffffff || -v>=0x7fffffffffffffff) throw MVMachineIntegerOverflow;
CircuitTableIntPOD ret;
- ret.v=v;
+ ret.v=static_cast<int64_t>(v);
return ret;
}
@@ -746,7 +789,7 @@
// DANGER !!!
//if(v>=0x7fffffffffffffffffffffffffffffff || -v>=0x7fffffffffffffffffffffffffffffff) throw MVMachineIntegerOverflow;
CircuitTableIntPOD ret;
- ret.v=__int128(v);
+ ret.v=__int128_t(v);
return ret;
}
@@ -784,6 +827,7 @@
CircuitTableInt128()noexcept{v=0;}
CircuitTableInt128(CircuitTableInt128POD const &m){v=m.v;}
CircuitTableInt128(__int128_t val){v=val;}
+ CircuitTableInt128(int val){v=val;}
CircuitTableInt128(std::string const&s){
int64_t proxy;
std::istringstream a(s); a>>proxy;
--- a/src/app_test.cpp
+++ b/src/app_test.cpp
@@ -764,10 +764,10 @@
{
- __int128 t=0;
- __int128 A=2;
- __int128 s=-4;
- __int128 B=1;
+ __int128_t t=0;
+ __int128_t A=2;
+ __int128_t s=-4;
+ __int128_t B=1;
B=(B<<127)+3;
std::cerr<<"---B\n";
std::cerr<<toStr(t)<<"\n";
--- a/src/gfanlib_tableau.h
+++ b/src/gfanlib_tableau.h
@@ -334,8 +334,8 @@
{
combinedMatrix=Matrix<mvtyp>(M.getHeight()+1,M.getHeight()+1+M.getWidth(),mr);
combinedMatrix.setSubMatrix(0,M.getHeight()+1,M.getHeight(),getWidth(),M);
- for(int i=0;i<M.getHeight()+1;i++)combinedMatrix[i][i]=1;
- for(int i=M.getHeight()+1;i<getWidth();i++)combinedMatrix[M.getHeight()][i]=1;
+ for(int i=0;i<M.getHeight()+1;i++)combinedMatrix[i][i]=static_cast<mvtyp>(1);
+ for(int i=M.getHeight()+1;i<getWidth();i++)combinedMatrix[M.getHeight()][i]=static_cast<mvtyp>(1);
// Matrix<mvtyp> M2=M;
// M2.appendRow(Vector<mvtyp>::allOnes(M2.getWidth()));
// combinedMatrix=combineLeftRight(M2.identity(M.getHeight()+1),M2,mr);
@@ -347,7 +347,7 @@
}
assert(inBasis.size()==getWidth());
for(int i=0;i<M.getHeight()+appendAllOnes;i++){basisIndices[i]=i;inBasis[i]=true;}
- determinantOfBasis=1;
+ determinantOfBasis=static_cast<mvtyp>(1);
computeRowBounds();
}
Tableau(Tableau<mvtyp> const &a, MR *mr=get_default_resource()):

View file

@ -0,0 +1,25 @@
Description: Nonzero return code if tests fail
Origin: https://git.sagemath.org/sage.git/commit/build/pkgs/gfan/patches/maketestsreturnerror.patch?h=develop&id=4ad830c4cbb10ce81d49eb92cbd3b1be2df31e7b
Forwarded: yes
Last-Update: 2020-11-13
--- a/src/app_test.cpp
+++ b/src/app_test.cpp
@@ -1414,6 +1414,9 @@
failed.push_back(i->folder);
}
cout<<"\n";
+ cout<<"Number of successful tests "<<good<<endl;
+ cout<<"Number of failed tests "<<bad<<endl;
+
if(!failed.empty())
{
cout<<"Failed tests:\n-------------\n";
@@ -1421,6 +1424,7 @@
{
cout<<*i<<" FAILED!\n";
}
+ return 1;
}
cout<<"Number of succesful tests "<<good<<endl;

View file

@ -1,27 +0,0 @@
diff --git a/src/app_test.cpp b/src/app_test.cpp
index 755bfe6..183c735 100644
--- a/src/app_test.cpp
+++ b/src/app_test.cpp
@@ -562,6 +562,9 @@ int testIntegers()
failed.push_back(i->folder);
}
cout<<"\n";
+ cout<<"Number of succesful tests "<<good<<endl;
+ cout<<"Number of failed tests "<<bad<<endl;
+
if(!failed.empty())
{
cout<<"Failed tests:\n-------------\n";
@@ -569,11 +572,9 @@ int testIntegers()
{
cout<<*i<<" FAILED!\n";
}
+ return 1;
}
- cout<<"Number of succesful tests "<<good<<endl;
- cout<<"Number of failed tests "<<bad<<endl;
-
return 0;
}
};

View file

@ -1,195 +0,0 @@
diff --git a/testsuite/0008PolynomialSetUnion/command b/testsuite/0008PolynomialSetUnion/command
index cbb23d6..d61cb71 100644
--- a/testsuite/0008PolynomialSetUnion/command
+++ b/testsuite/0008PolynomialSetUnion/command
@@ -1 +1 @@
-%s _bases | %s _polynomialsetunion |sort
+%s _bases | %s _polynomialsetunion |LC_ALL=C sort|tail -n +2 | sed -e '$ d'
diff --git a/testsuite/0008PolynomialSetUnion/output b/testsuite/0008PolynomialSetUnion/output
index 38dfb6f..12a65c7 100644
--- a/testsuite/0008PolynomialSetUnion/output
+++ b/testsuite/0008PolynomialSetUnion/output
@@ -1,62 +1,60 @@
-{
+a*b-c^6,
+a*b^2-c^3,
+a*b^4-b,
+a*c-b^6,
+a*c^2-b,
+a*c^6-c,
+a-b^11,
+a-b^2*c,
+a-c^9,
a^11-c,
a^15-a,
+a^2*b-c,
a^2*b^3-a,
+a^2*c-b^3,
a^2-b^8,
-a^2*b-c,
a^2-c^4,
-a^2*c-b^3,
-a^3-b^5,
-a^3-b*c^2,
a^3*c^2-c}
-a^4-b^2,
+a^3-b*c^2,
+a^3-b^5,
a^4*c-a,
+a^4-b^2,
a^5-c^3,
a^6*b-a,
a^6-b*c,
a^8-c^2,
a^9-b,
-a-b^11,
-a-b^2*c,
-a*b^2-c^3,
-a*b^4-b,
-a*b-c^6,
-a*c^2-b,
-a*c^6-c,
-a-c^9,
-a*c-b^6,
+b*c-a^6,
+b*c^2-a^3,
+b*c^4-c,
+b-a*c^2,
+b-a^9,
+b-c^11,
b^11-a,
b^15-b,
-b^2-a^4,
+b^2*c-a,
b^2*c^3-b,
+b^2-a^4,
b^2-c^8,
-b^2*c-a,
b^3-a^2*c,
b^3-c^5,
b^4-c^2,
b^5-a^3,
-b^6-a*c,
b^6*c-b,
+b^6-a*c,
b^8-a^2,
b^9-c,
-b-a^9,
-b-a*c^2,
-b-c^11,
-b*c^2-a^3,
-b*c^4-c,
-b*c-a^6,
+c-a^11,
+c-a^2*b,
+c-b^9,
c^11-b,
c^15-c,
c^2-a^8,
c^2-b^4,
-c^3-a^5,
c^3-a*b^2,
+c^3-a^5,
c^4-a^2,
c^5-b^3,
c^6-a*b,
c^8-b^2,
c^9-a,
-c-a^11,
-c-a^2*b,
-c-b^9,
-Q[a,b,c]
diff --git a/testsuite/0008PolynomialSetUnion/outputNew b/testsuite/0008PolynomialSetUnion/outputNew
index 38dfb6f..12a65c7 100644
--- a/testsuite/0008PolynomialSetUnion/outputNew
+++ b/testsuite/0008PolynomialSetUnion/outputNew
@@ -1,62 +1,60 @@
-{
+a*b-c^6,
+a*b^2-c^3,
+a*b^4-b,
+a*c-b^6,
+a*c^2-b,
+a*c^6-c,
+a-b^11,
+a-b^2*c,
+a-c^9,
a^11-c,
a^15-a,
+a^2*b-c,
a^2*b^3-a,
+a^2*c-b^3,
a^2-b^8,
-a^2*b-c,
a^2-c^4,
-a^2*c-b^3,
-a^3-b^5,
-a^3-b*c^2,
a^3*c^2-c}
-a^4-b^2,
+a^3-b*c^2,
+a^3-b^5,
a^4*c-a,
+a^4-b^2,
a^5-c^3,
a^6*b-a,
a^6-b*c,
a^8-c^2,
a^9-b,
-a-b^11,
-a-b^2*c,
-a*b^2-c^3,
-a*b^4-b,
-a*b-c^6,
-a*c^2-b,
-a*c^6-c,
-a-c^9,
-a*c-b^6,
+b*c-a^6,
+b*c^2-a^3,
+b*c^4-c,
+b-a*c^2,
+b-a^9,
+b-c^11,
b^11-a,
b^15-b,
-b^2-a^4,
+b^2*c-a,
b^2*c^3-b,
+b^2-a^4,
b^2-c^8,
-b^2*c-a,
b^3-a^2*c,
b^3-c^5,
b^4-c^2,
b^5-a^3,
-b^6-a*c,
b^6*c-b,
+b^6-a*c,
b^8-a^2,
b^9-c,
-b-a^9,
-b-a*c^2,
-b-c^11,
-b*c^2-a^3,
-b*c^4-c,
-b*c-a^6,
+c-a^11,
+c-a^2*b,
+c-b^9,
c^11-b,
c^15-c,
c^2-a^8,
c^2-b^4,
-c^3-a^5,
c^3-a*b^2,
+c^3-a^5,
c^4-a^2,
c^5-b^3,
c^6-a*b,
c^8-b^2,
c^9-a,
-c-a^11,
-c-a^2*b,
-c-b^9,
-Q[a,b,c]

View file

@ -0,0 +1,26 @@
--- a/src/packedmonomial.h 2024-08-12 13:00:15.000000000 -0300
+++ b/src/packedmonomial.h 2024-10-29 22:59:54.666573193 -0300
@@ -13,6 +13,9 @@
#include "monomial.h"
#include "printer.h"
+#define u_int64_t uint64_t
+#define u_int16_t uint16_t
+
/*
* This is an attempt to implement packed monomials in a similar way as Singular does.
* Methods are designed for speed, not flexibility.
--- a/src/gfanlib_circuittableint.h 2024-10-29 23:01:48.248324088 -0300
+++ b/src/gfanlib_circuittableint.h 2024-10-29 23:12:51.154543137 -0300
@@ -23,6 +23,11 @@
typedef absl::uint128 __uint128_t;
#endif
+#define __int64_t int64_t
+#define __uint64_t uint64_t
+#define __int32_t int32_t
+#define __uint32_t uint32_t
+
namespace gfan{

View file

@ -1,24 +1,23 @@
# Template file for 'gfan'
pkgname=gfan
version=0.6.2
version=0.7
revision=1
build_style=gnu-makefile
makedepends="gmp-devel cddlib-devel"
makedepends="gmp-devel cddlib-devel abseil-cpp-devel"
short_desc="Package for computing Groebner fans and tropical varieties"
maintainer="Gonzalo Tornaría <tornaria@cmat.edu.uy>"
license="GPL-2.0-or-later"
homepage="https://math.au.dk/~jensen/software/gfan/gfan.html"
distfiles="https://math.au.dk/~jensen/software/gfan/gfan${version}.tar.gz"
checksum=a674d5e5dc43634397de0d55dd5da3c32bd358d05f72b73a50e62c1a1686f10a
checksum=ab833757e1e4d4a98662f4aa691394013ea9a226f6416b8f8565356d6fcc989e
# Makefile has this but our CFLAGS override it; build fails otherwise
CFLAGS="-DGMPRATIONAL"
case $XBPS_TARGET_MACHINE in
# avoid numerical noise caused by extended-precision of registers
# fixes testsuite/0009RenderStairCase
i686*) CFLAGS+=" -ffloat-store" ;;
esac
post_patch() {
# remove a failing test
rm -rf testsuite/0009RenderStairCase
}
if [ -n "$CROSS_BUILD" ]; then
# depend on host gfan for installlinks