From 6bc986778787c8384035f77ee357d155fd409a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pernet?= Date: Tue, 7 Dec 2021 14:08:49 +0100 Subject: [PATCH 1/3] fix with LinBox new API --- src/sage/libs/linbox/conversion.pxd | 3 +-- src/sage/libs/linbox/linbox.pxd | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sage/libs/linbox/conversion.pxd b/src/sage/libs/linbox/conversion.pxd index 7794c9edc39..1753277b1f1 100644 --- a/src/sage/libs/linbox/conversion.pxd +++ b/src/sage/libs/linbox/conversion.pxd @@ -177,9 +177,8 @@ cdef inline Vector_integer_dense new_sage_vector_integer_dense(P, DenseVector_in - v -- linbox vector """ cdef Vector_integer_dense res = P() - cdef cppvector[Integer] * vec = &v.refRep() cdef size_t i for i in range( res._degree): - mpz_set(res._entries[i], vec[0][i].get_mpz_const()) + mpz_set(res._entries[i], v.getEntry(i).get_mpz_const()) return res diff --git a/src/sage/libs/linbox/linbox.pxd b/src/sage/libs/linbox/linbox.pxd index 9112d151f8b..dcc482960cc 100644 --- a/src/sage/libs/linbox/linbox.pxd +++ b/src/sage/libs/linbox/linbox.pxd @@ -32,7 +32,7 @@ cdef extern from "linbox/matrix/dense-matrix.h": ctypedef Modular_double Field ctypedef double Element DenseMatrix_Modular_double(Field F, size_t m, size_t n) - DenseMatrix_Modular_double(Field F, Element*, size_t m, size_t n) + DenseMatrix_Modular_double(Field F, size_t m, size_t n, Element*) void setEntry(size_t i, size_t j, Element& a) Element &getEntry(size_t i, size_t j) @@ -42,7 +42,7 @@ cdef extern from "linbox/matrix/dense-matrix.h": ctypedef Modular_float Field ctypedef float Element DenseMatrix_Modular_float(Field F, size_t m, size_t n) - DenseMatrix_Modular_float(Field F, Element*, size_t m, size_t n) + DenseMatrix_Modular_float(Field F, size_t m, size_t n, Element*) void setEntry(size_t i, size_t j, Element& a) Element &getEntry(size_t i, size_t j) @@ -101,7 +101,6 @@ cdef extern from "linbox/vector/vector.h": DenseVector_integer (Field &F) DenseVector_integer (Field &F, long& m) DenseVector_integer (Field &F, cppvector[Integer]&) - cppvector[Element]& refRep() size_t size() void resize(size_t) void resize(size_t n, const Element&) From 4dac911ce056a24c1dd3aa26697cf457b2e2b826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pernet?= Date: Tue, 7 Dec 2021 14:09:29 +0100 Subject: [PATCH 2/3] LinBox new API for DenseMatrix --- src/sage/matrix/matrix_modn_dense_template.pxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/matrix/matrix_modn_dense_template.pxi b/src/sage/matrix/matrix_modn_dense_template.pxi index abf29badce6..e45e05f3641 100644 --- a/src/sage/matrix/matrix_modn_dense_template.pxi +++ b/src/sage/matrix/matrix_modn_dense_template.pxi @@ -221,7 +221,7 @@ cdef inline linbox_echelonize_efd(celement modulus, celement* entries, Py_ssize_ return 0,[] cdef ModField *F = new ModField(modulus) - cdef DenseMatrix *A = new DenseMatrix(F[0], entries,nrows, ncols) + cdef DenseMatrix *A = new DenseMatrix(F[0], nrows, ncols, entries) cdef Py_ssize_t r = reducedRowEchelonize(A[0]) cdef Py_ssize_t i,j for i in range(nrows): From 9c8796c7b677e3a056348e3510331ea8b8c3c42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Thu, 4 May 2023 15:27:55 -0300 Subject: [PATCH 3/3] Support linbox 1.7.0 and 1.6.3 at the same time The constructor `DenseMatrix(field, entries, m, n)` in 1.6.3 was changed to `DenseMatrix(field, m, n, entries)` in 1.7.0. We replace use of this constructor by a different way to initialize a matrix from entries using part of the API that works both in 1.6.3 and in 1.7.0. Note that the two versions of the library are still ABI-incompatible so changing linbox requires recompiling sagelib. To complicate matters, linbox doesn't change soname so the dynamic linker will let this go and sagemath will eventually crash. --- src/sage/libs/linbox/linbox.pxd | 2 -- src/sage/matrix/matrix_modn_dense_template.pxi | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sage/libs/linbox/linbox.pxd b/src/sage/libs/linbox/linbox.pxd index dcc482960cc..bfeda4b6042 100644 --- a/src/sage/libs/linbox/linbox.pxd +++ b/src/sage/libs/linbox/linbox.pxd @@ -32,7 +32,6 @@ cdef extern from "linbox/matrix/dense-matrix.h": ctypedef Modular_double Field ctypedef double Element DenseMatrix_Modular_double(Field F, size_t m, size_t n) - DenseMatrix_Modular_double(Field F, size_t m, size_t n, Element*) void setEntry(size_t i, size_t j, Element& a) Element &getEntry(size_t i, size_t j) @@ -42,7 +41,6 @@ cdef extern from "linbox/matrix/dense-matrix.h": ctypedef Modular_float Field ctypedef float Element DenseMatrix_Modular_float(Field F, size_t m, size_t n) - DenseMatrix_Modular_float(Field F, size_t m, size_t n, Element*) void setEntry(size_t i, size_t j, Element& a) Element &getEntry(size_t i, size_t j) diff --git a/src/sage/matrix/matrix_modn_dense_template.pxi b/src/sage/matrix/matrix_modn_dense_template.pxi index e45e05f3641..68b869ce314 100644 --- a/src/sage/matrix/matrix_modn_dense_template.pxi +++ b/src/sage/matrix/matrix_modn_dense_template.pxi @@ -221,9 +221,14 @@ cdef inline linbox_echelonize_efd(celement modulus, celement* entries, Py_ssize_ return 0,[] cdef ModField *F = new ModField(modulus) - cdef DenseMatrix *A = new DenseMatrix(F[0], nrows, ncols, entries) - cdef Py_ssize_t r = reducedRowEchelonize(A[0]) + cdef DenseMatrix *A = new DenseMatrix(F[0], nrows, ncols) + cdef Py_ssize_t i,j + for i in range(nrows): + for j in range(ncols): + A.setEntry(i, j, entries[i*ncols+j]) + + cdef Py_ssize_t r = reducedRowEchelonize(A[0]) for i in range(nrows): for j in range(ncols): entries[i*ncols+j] = A.getEntry(i,j)