Ticket #11718: trac_11718_linbox_1_1_7.patch
File trac_11718_linbox_1_1_7.patch, 8.7 KB (added by , 11 years ago) |
---|
-
module_list.py
# HG changeset patch # User Martin Albrecht <martinralbrecht@googlemail.com> # Date 1314077417 -3600 # Node ID de6d8e9acde7f11c98722a884ef465b9983dbf45 # Parent 6b2cfe6da5b068e5d6e4ac3b102836ff8ef43277 #11718 upgrade LinBox to newest upstream release diff -r 6b2cfe6da5b0 -r de6d8e9acde7 module_list.py
a b 550 550 sources = ['sage/libs/linbox/linbox.pyx'], 551 551 # For this to work on cygwin, linboxwrap *must* be 552 552 # before ntl. 553 libraries = ['linbox sage', 'ntl', 'linbox',553 libraries = ['linbox', 'linboxsage', 'ntl', 554 554 'stdc++', 'givaro', 'gmp', 'gmpxx', BLAS, BLAS2], 555 depends = [SAGE_INC + 'linbox/linbox-config.h'], 556 extra_compile_args = ['-DDISABLE_COMMENTATOR'], 555 557 language = 'c++'), 556 558 557 559 -
sage/all.py
diff -r 6b2cfe6da5b0 -r de6d8e9acde7 sage/all.py
a b 19 19 20 20 """ 21 21 22 22 23 from __future__ import with_statement 23 24 24 25 ############################################################################### -
sage/libs/linbox/linbox.pyx
diff -r 6b2cfe6da5b0 -r de6d8e9acde7 sage/libs/linbox/linbox.pyx
a b 13 13 # * charpoly and minpoly don't work randomly 14 14 15 15 cdef extern from "linbox/linbox-sage.h": 16 void linbox_modn_dense_delete_array(mod_int *f) 16 17 cdef void linbox_modn_dense_delete_array_double (double *f) 17 18 18 int linbox_modn_dense_echelonize(unsigned long modulus,19 mod_int **matrix, size_t nrows, size_t ncols)20 void linbox_modn_dense_minpoly(unsigned long modulus, mod_int **mp, size_t* degree, size_t n,21 mod_int **matrix, int do_minpoly)22 19 23 int linbox_modn_dense_matrix_matrix_multiply(unsigned long modulus, mod_int **ans, 24 mod_int **A, mod_int **B, 25 size_t A_nr, size_t A_nc, 26 size_t B_nr, size_t B_nc) 20 unsigned long int linbox_modn_dense_echelonize_double (double modulus, double*matrix, size_t nrows, size_t ncols) 27 21 28 int linbox_modn_dense_rank(unsigned long modulus, 29 mod_int** matrix, size_t nrows, size_t ncols) 22 cdef unsigned long int linbox_modn_dense_rank_double (double modulus, double* matrix, size_t nrows, size_t ncols) 30 23 31 mod_int linbox_modn_dense_det(mod_int modulus, mod_int** matrix, size_t nrows, size_t ncols)24 cdef double linbox_modn_dense_det_double (double modulus, double* matrix, size_t nrows, size_t ncols) 32 25 26 cdef double* linbox_modn_dense_minpoly_double (double modulus, double ** mp, size_t* degree, size_t n, double*matrix) 27 28 cdef double* linbox_modn_dense_charpoly_double (double modulus, double ** cp, size_t n, double * matrix) 29 30 cdef double* linbox_modn_dense_matrix_matrix_multiply_double(double modulus, double * ans, double *A, double *B, size_t m,size_t n,size_t k) 31 32 cdef double* linbox_modn_dense_matrix_matrix_general_multiply_double (double modulus, double * ans, double alpha, double beta, double *A, double *B, size_t m, size_t n, size_t k) 33 34 cdef unsigned long linbox_modn_dense_col_rankprofile_submatrix_double (double modulus, double* matrix, double* out, size_t* rank, size_t nrows, size_t ncols) 35 36 cdef unsigned long linbox_modn_dense_col_rankprofile_submatrix_indices_double (double modulus, double* matrix, size_t ** row_idx, size_t ** col_idx, size_t * rank, size_t nrows, size_t ncols) 37 38 39 cdef double *to_double_matrix(Py_ssize_t nrows, Py_ssize_t ncols, mod_int **matrix): 40 cdef double *A = <double*>sage_malloc(sizeof(double)*nrows*ncols) 41 cdef Py_ssize_t i, j 42 for i in range(nrows): 43 for j in range(ncols): 44 A[i*ncols+j] = <double>matrix[i][j] 45 return A 33 46 34 47 cdef class Linbox_modn_dense: 35 48 def __init__(self): … … 50 63 51 64 cdef int echelonize(self): 52 65 cdef int r 53 r = linbox_modn_dense_echelonize(self.n, self.matrix, 54 self.nrows, self.ncols) 66 cdef Py_ssize_t i,j 67 68 cdef double *A = to_double_matrix(self.nrows, self.ncols, self.matrix) 69 70 r = linbox_modn_dense_echelonize_double(<double>self.n, A, self.nrows, self.ncols) 71 72 for i in range(self.nrows): 73 for j in range(self.ncols): 74 self.matrix[i][j] = <mod_int>A[i*self.ncols+j] 75 76 sage_free(A) 55 77 return r 56 78 57 79 def minpoly(self): … … 68 90 OUTPUT: 69 91 coefficients of charpoly or minpoly as a Python list 70 92 """ 71 cdef mod_int*f93 cdef double *f 72 94 cdef size_t degree 73 linbox_modn_dense_minpoly(self.n, &f, °ree, 74 self.nrows, self.matrix, 75 minpoly) 95 96 cdef double *A = to_double_matrix(self.nrows, self.ncols, self.matrix) 97 98 if minpoly: 99 linbox_modn_dense_minpoly_double(<double>self.n, &f, °ree, self.nrows, A) 100 else: 101 linbox_modn_dense_charpoly_double(<double>self.n, &f, self.nrows, A) 102 degree = self.nrows 76 103 v = [] 77 104 cdef Py_ssize_t i 78 105 for i from 0 <= i <= degree: 79 v.append( f[i])80 linbox_modn_dense_delete_array (f)106 v.append(<mod_int>f[i]) 107 linbox_modn_dense_delete_array_double(f) 81 108 return v 82 109 83 110 cdef matrix_matrix_multiply(self, 84 111 mod_int **ans, 85 112 mod_int **B, 86 113 size_t B_nr, size_t B_nc): 87 cdef int e 88 e = linbox_modn_dense_matrix_matrix_multiply(self.n, ans, 89 self.matrix, B, 90 self.nrows, self.ncols, 91 B_nr, B_nc) 92 if e: 93 raise RuntimeError, "error doing matrix matrix multiply modn using linbox" 94 114 cdef double *_A = to_double_matrix(self.nrows, self.ncols, self.matrix) 115 cdef double *_B = to_double_matrix(B_nr, B_nc, B) 116 cdef double *_C = to_double_matrix(self.nrows, B_nc, ans) 117 118 linbox_modn_dense_matrix_matrix_multiply_double(<double>self.n, _C, _A, _B, 119 self.nrows, self.ncols, B_nc) 120 121 for i in range(self.nrows): 122 for j in range(self.ncols): 123 ans[i][j] = <mod_int>_C[i*self.ncols+j] 124 125 sage_free(_A) 126 sage_free(_B) 127 sage_free(_C) 95 128 96 129 cdef unsigned long rank(self) except -1: 97 130 cdef unsigned long r 98 r = linbox_modn_dense_rank(self.n, self.matrix, self.nrows, self.ncols) 131 cdef double *_A = to_double_matrix(self.nrows, self.ncols, self.matrix) 132 r = linbox_modn_dense_rank_double(self.n, _A, self.nrows, self.ncols) 133 sage_free(_A) 99 134 return r 100 135 101 136 cpdef mod_int det(self) except -1: 102 137 cdef mod_int d 103 d = linbox_modn_dense_det(self.n, self.matrix, self.nrows, self.ncols) 138 cdef double *_A = to_double_matrix(self.nrows, self.ncols, self.matrix) 139 d = <mod_int>linbox_modn_dense_det_double(self.n, _A, self.nrows, self.ncols) 140 sage_free(_A) 104 141 return d 105 142 106 143 ########################################################################## … … 155 192 ########################################################################## 156 193 157 194 cdef extern from "linbox/linbox-sage.h": 158 void linbox_integer_dense_minpoly_hacked(mpz_t* *minpoly, size_t* degree, 159 size_t n, mpz_t** matrix, int do_minpoly) 160 161 void linbox_integer_dense_minpoly(mpz_t* *minpoly, size_t* degree, 195 void linbox_integer_dense_minpoly(mpz_t** minpoly, size_t *degree, 162 196 size_t n, mpz_t** matrix) 163 197 164 void linbox_integer_dense_charpoly(mpz_t* *charpoly, size_t*degree,198 void linbox_integer_dense_charpoly(mpz_t** charpoly, size_t *degree, 165 199 size_t n, mpz_t** matrix) 166 200 167 201 void linbox_integer_dense_delete_array(mpz_t* f) … … 173 207 size_t ncols) 174 208 175 209 void linbox_integer_dense_det(mpz_t ans, mpz_t** matrix, 176 size_t nrows, size_t ncols) 210 size_t nrows, size_t ncols) 177 211 178 212 void linbox_integer_dense_smithform(mpz_t **v, 179 213 mpz_t **matrix,