summarylogtreecommitdiffstats
path: root/sagemath-linbox-1.6.patch
blob: bb2d0116aadfdb9a955c3a5a83772f8cf0e7e4a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
diff --git a/src/sage/libs/linbox/conversion.pxd b/src/sage/libs/linbox/conversion.pxd
index 810a197..7794c9e 100644
--- a/src/sage/libs/linbox/conversion.pxd
+++ b/src/sage/libs/linbox/conversion.pxd
@@ -45,7 +45,7 @@ from sage.modules.vector_integer_sparse cimport mpz_vector,  mpz_vector_get_entr
 
 ctypedef enum linbox_specifier:
     METHOD_DEFAULT              # no specification
-    METHOD_BLAS_ELIMINATION     # BlasElimination
+    METHOD_DENSE_ELIMINATION     # DenseElimination
     METHOD_SPARSE_ELIMINATION   # SparseElimination
     METHOD_BLACKBOX             # Blackbox
     METHOD_WIEDEMANN            # Wiedeman
@@ -54,10 +54,10 @@ ctypedef enum linbox_specifier:
 cdef inline linbox_specifier get_method(str algo) except ERROR:
     if algo is None or algo == "default":
         return METHOD_DEFAULT
-    elif algo == "blas_elimination" or \
-         algo == "linbox_blas_elimination" or \
-         algo == "LinBox::BlasElimination":
-        return METHOD_BLAS_ELIMINATION
+    elif algo == "dense_elimination" or \
+         algo == "linbox_dense_elimination" or \
+         algo == "LinBox::DenseElimination":
+        return METHOD_DENSE_ELIMINATION
     elif algo == "sparse_elimination" or \
          algo == "linbox_sparse_elimination" or \
          algo == "LinBox::SparseElimination":
diff --git a/src/sage/libs/linbox/fflas.pxd b/src/sage/libs/linbox/fflas.pxd
index f3a7ce3..8bf62f1 100644
--- a/src/sage/libs/linbox/fflas.pxd
+++ b/src/sage/libs/linbox/fflas.pxd
@@ -63,8 +63,7 @@ cdef extern from "fflas-ffpack/fflas-ffpack.h" namespace "FFPACK":
     Modular_double.Element* Invert (Modular_double F, size_t order,
                                     Modular_double.Element* A, size_t A_stride, int nullity)
 
-    Modular_double.Element Det (Modular_double F,
-                                size_t nrows, size_t ncols,
+    Modular_double.Element Det (Modular_double F, Modular_double.Element& d, size_t n,
                                 Modular_double.Element* A, size_t A_stride)
 
     int Rank (Modular_double,
@@ -97,8 +96,7 @@ cdef extern from "fflas-ffpack/fflas-ffpack.h" namespace "FFPACK":
     Modular_float.Element* Invert (Modular_float F, size_t order,
                                    Modular_float.Element* A, size_t A_stride, int nullity)
 
-    Modular_float.Element Det (Modular_float F,
-                               size_t nrows, size_t ncols,
+    Modular_float.Element Det (Modular_float F, Modular_float.Element& d, size_t n,
                                Modular_float.Element* A, size_t A_stride)
 
     int Rank (Modular_float,
diff --git a/src/sage/libs/linbox/linbox.pxd b/src/sage/libs/linbox/linbox.pxd
index 35a3fa0..fb0e0dc 100644
--- a/src/sage/libs/linbox/linbox.pxd
+++ b/src/sage/libs/linbox/linbox.pxd
@@ -10,10 +10,10 @@ from .givaro cimport *
 
 cdef extern from "linbox/matrix/dense-matrix.h":
     ## template <class _Field, class _blasRep=typename Vector<_Field>::Dense >
-    ## class BlasMatrix ;
+    ## class DenseMatrix ;
     ##
     ## template <class _Field>
-    ## using DenseMatrix = BlasMatrix<_Field> ;
+    ## using DenseMatrix = DenseMatrix<_Field> ;
     cdef cppclass DenseMatrix_integer "LinBox::DenseMatrix<Givaro::ZRing<Givaro::Integer>>":
         ctypedef ZRing Field
         ctypedef Integer Element
@@ -30,6 +30,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)
         void setEntry(size_t i, size_t j, Element& a)
         Element &getEntry(size_t i, size_t j)
 
@@ -39,6 +40,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)
         void setEntry(size_t i, size_t j, Element& a)
         Element &getEntry(size_t i, size_t j)
 
@@ -125,7 +127,7 @@ cdef extern from "linbox/solutions/methods.h" namespace "LinBox":
         pass
     cdef struct WiedemannTraits:
         pass
-    cdef struct BlasEliminationTraits:
+    cdef struct DenseEliminationTraits:
         pass
     cdef struct SparseEliminationTraits:
         pass
@@ -135,7 +137,7 @@ cdef extern from "linbox/solutions/methods.h" namespace "LinBox":
         ctypedef BlackboxSpecifier Blackbox
         ctypedef EliminationSpecifier Elimination
         ctypedef WiedemannTraits Wiedemann
-        ctypedef BlasEliminationTraits BlasElimination
+        ctypedef DenseEliminationTraits DenseElimination
         ctypedef SparseEliminationTraits SparseElimination
 
 cdef extern from "linbox/solutions/charpoly.h" namespace "LinBox":
@@ -157,18 +159,24 @@ cdef extern from "linbox/algorithms/gauss.h":
                                              unsigned long Ni,
                                              unsigned long Nj)
 
-cdef extern from "linbox/algorithms/echelon-form.h":
-    ## template<class Field>
-    ## class EchelonFormDomain
-    cdef cppclass EchelonForm_Modular_double "LinBox::EchelonFormDomain<Givaro::Modular<double>>":
-        ctypedef double Element
-        EchelonForm_Modular_double(Modular_double)
-        int rowReducedEchelon(DenseMatrix_Modular_double&, const DenseMatrix_Modular_double&)
-
-    cdef cppclass EchelonForm_Modular_float "LinBox::EchelonFormDomain<Givaro::Modular<float>>":
-        ctypedef float Element
-        EchelonForm_Modular_float(Modular_float)
-        int rowReducedEchelon(DenseMatrix_Modular_float, const DenseMatrix_Modular_float)
+cdef extern from "linbox/solutions/echelon.h" namespace "LinBox":
+    size_t rowEchelon (DenseMatrix_Modular_float&, const DenseMatrix_Modular_float&)
+    size_t rowEchelonize (DenseMatrix_Modular_float&)
+    size_t reducedRowEchelon (DenseMatrix_Modular_float&, const DenseMatrix_Modular_float&)
+    size_t reducedRowEchelonize (DenseMatrix_Modular_float&)
+    size_t colEchelon (DenseMatrix_Modular_float&, const DenseMatrix_Modular_float&)
+    size_t colEchelonize (DenseMatrix_Modular_float&)
+    size_t reducedColEchelon (DenseMatrix_Modular_float&, const DenseMatrix_Modular_float&)
+    size_t reducedColEchelonize (DenseMatrix_Modular_float&)
+
+    size_t rowEchelon (DenseMatrix_Modular_double&, const DenseMatrix_Modular_double&)
+    size_t rowEchelonize (DenseMatrix_Modular_double&)
+    size_t reducedRowEchelon (DenseMatrix_Modular_double&, const DenseMatrix_Modular_double&)
+    size_t reducedRowEchelonize (DenseMatrix_Modular_double&)
+    size_t colEchelon (DenseMatrix_Modular_double&, const DenseMatrix_Modular_double&)
+    size_t colEchelonize (DenseMatrix_Modular_double&)
+    size_t reducedColEchelon (DenseMatrix_Modular_double&, const DenseMatrix_Modular_double&)
+    size_t reducedColEchelonize (DenseMatrix_Modular_double&)
 
 cdef extern from "linbox/solutions/rank.h" namespace "LinBox":
     unsigned long & rank (unsigned long&, DenseMatrix_integer)
@@ -185,7 +193,7 @@ cdef extern from "linbox/solutions/solve.h" namespace "LinBox":
                                 Integer &,
                                 SparseMatrix_integer &,
                                 DenseVector_integer &,
-                                Method.BlasElimination) except +
+                                Method.DenseElimination) except +
 
     DenseVector_integer& solve (DenseVector_integer &,
                                 Integer &,
diff --git a/src/sage/matrix/matrix_integer_sparse.pyx b/src/sage/matrix/matrix_integer_sparse.pyx
index 7fa386e..132140f 100644
--- a/src/sage/matrix/matrix_integer_sparse.pyx
+++ b/src/sage/matrix/matrix_integer_sparse.pyx
@@ -42,7 +42,7 @@ from sage.libs.linbox.conversion cimport (
     new_linbox_vector_integer_dense,
     new_sage_vector_integer_dense,
     new_linbox_matrix_integer_sparse,
-    METHOD_DEFAULT, METHOD_BLAS_ELIMINATION,
+    METHOD_DEFAULT, METHOD_DENSE_ELIMINATION,
     METHOD_SPARSE_ELIMINATION, METHOD_BLACKBOX,
     METHOD_WIEDEMANN, get_method)
 
@@ -926,7 +926,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
             - ``'linbox'`` or ``'linbox_default'`` - (default) use LinBox
               and let it chooses the appropriate algorithm
 
-            -  ``linbox_blas_elimination'`` - use LinBox dense elimination
+            -  ``linbox_dense_elimination'`` - use LinBox dense elimination
 
             - ``'linbox_sparse_elimination'`` - use LinBox sparse elimination
 
@@ -993,7 +993,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
 
         - ``b`` -- a dense integer vector
 
-        - ``algorithm`` -- (optional) either ``None``, ``'blas_elimination'``,
+        - ``algorithm`` -- (optional) either ``None``, ``'dense_elimination'``,
           ``'sparse_elimination'``, ``'wiedemann'`` or ``'blackbox'``.
 
         OUTPUT: a pair ``(a, d)`` consisting of
@@ -1012,7 +1012,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
             sage: b0 = vector((1,1,1,1))
             sage: m._solve_vector_linbox(b0)
             ((-1, -7, -3, -1), 1)
-            sage: m._solve_vector_linbox(b0, 'blas_elimination')
+            sage: m._solve_vector_linbox(b0, 'dense_elimination')
             ((-1, -7, -3, -1), 1)
             sage: m._solve_vector_linbox(b0, 'sparse_elimination')
             ((-1, -7, -3, -1), 1)
@@ -1024,7 +1024,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
             sage: b1 = vector((1,2,3,4))
             sage: m._solve_vector_linbox(b1)
             ((-18, -92, -41, -17), 5)
-            sage: m._solve_vector_linbox(b1, 'blas_elimination')
+            sage: m._solve_vector_linbox(b1, 'dense_elimination')
             ((-18, -92, -41, -17), 5)
             sage: m._solve_vector_linbox(b1, 'sparse_elimination')
             ((-18, -92, -41, -17), 5)
@@ -1039,7 +1039,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
 
         TESTS::
 
-            sage: algos = ["default", "blas_elimination", "sparse_elimination",
+            sage: algos = ["default", "dense_elimination", "sparse_elimination",
             ....:          "blackbox", "wiedemann"]
             sage: for i in range(20):
             ....:     dim = randint(1, 30)
@@ -1080,8 +1080,8 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
             linbox.solve(res[0], D, A[0], b[0])
         elif method == METHOD_WIEDEMANN:
             linbox.solve(res[0], D, A[0], b[0], linbox.Method.Wiedemann())
-        elif method == METHOD_BLAS_ELIMINATION:
-            linbox.solve(res[0], D, A[0], b[0], linbox.Method.BlasElimination())
+        elif method == METHOD_DENSE_ELIMINATION:
+            linbox.solve(res[0], D, A[0], b[0], linbox.Method.DenseElimination())
         elif method == METHOD_SPARSE_ELIMINATION:
             linbox.solve(res[0], D, A[0], b[0], linbox.Method.SparseElimination())
         elif method == METHOD_BLACKBOX:
@@ -1136,7 +1136,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
 
         TESTS::
 
-            sage: algos = ["default", "blas_elimination", "sparse_elimination",
+            sage: algos = ["default", "dense_elimination", "sparse_elimination",
             ....:          "blackbox", "wiedemann"]
 
             sage: for _ in range(10):
@@ -1191,8 +1191,8 @@ cdef class Matrix_integer_sparse(Matrix_sparse):
             # solve the current row
             if algo == METHOD_DEFAULT:
                 linbox.solve(res[0], D, A[0], b[0])
-            elif algo == METHOD_BLAS_ELIMINATION:
-                linbox.solve(res[0], D, A[0], b[0], linbox.Method.BlasElimination())
+            elif algo == METHOD_DENSE_ELIMINATION:
+                linbox.solve(res[0], D, A[0], b[0], linbox.Method.DenseElimination())
             elif algo == METHOD_SPARSE_ELIMINATION:
                 linbox.solve(res[0], D, A[0], b[0], linbox.Method.SparseElimination())
             elif algo == METHOD_BLACKBOX:
diff --git a/src/sage/matrix/matrix_modn_dense_double.pyx b/src/sage/matrix/matrix_modn_dense_double.pyx
index c4b1a46..880caec 100644
--- a/src/sage/matrix/matrix_modn_dense_double.pyx
+++ b/src/sage/matrix/matrix_modn_dense_double.pyx
@@ -24,8 +24,8 @@ from sage.libs.linbox.givaro cimport \
     Poly1Dom, Dense
 
 from sage.libs.linbox.linbox cimport \
-    DenseMatrix_Modular_double as BlasMatrix, \
-    EchelonForm_Modular_double as EchelonFormDomain
+    reducedRowEchelonize, \
+    DenseMatrix_Modular_double as DenseMatrix
 
 from sage.libs.linbox.fflas cimport \
     fgemm, fgemv, Det, Rank, ReducedRowEchelonForm, applyP, \
diff --git a/src/sage/matrix/matrix_modn_dense_float.pyx b/src/sage/matrix/matrix_modn_dense_float.pyx
index 89d1a94..8a468c1 100644
--- a/src/sage/matrix/matrix_modn_dense_float.pyx
+++ b/src/sage/matrix/matrix_modn_dense_float.pyx
@@ -23,8 +23,8 @@ from sage.libs.linbox.givaro cimport \
     Poly1Dom, Dense
 
 from sage.libs.linbox.linbox cimport \
-    DenseMatrix_Modular_float as BlasMatrix, \
-    EchelonForm_Modular_float as EchelonFormDomain
+    DenseMatrix_Modular_float as DenseMatrix, \
+    reducedRowEchelonize
 
 from sage.libs.linbox.fflas cimport \
     fgemm, fgemv, Det, Rank, ReducedRowEchelonForm, applyP, \
diff --git a/src/sage/matrix/matrix_modn_dense_template.pxi b/src/sage/matrix/matrix_modn_dense_template.pxi
index 6a5e164..230a16e 100644
--- a/src/sage/matrix/matrix_modn_dense_template.pxi
+++ b/src/sage/matrix/matrix_modn_dense_template.pxi
@@ -207,21 +207,12 @@ cdef inline linbox_echelonize_efd(celement modulus, celement* entries, Py_ssize_
         return 0,[]
 
     cdef ModField *F = new ModField(<long>modulus)
-    cdef EchelonFormDomain *EF = new EchelonFormDomain(F[0])
-    cdef BlasMatrix *A = new BlasMatrix(F[0], <uint64_t>nrows, <uint64_t>ncols)
-    cdef BlasMatrix *E = new BlasMatrix(F[0], <uint64_t>nrows, <uint64_t>ncols)
-
+    cdef DenseMatrix *A = new DenseMatrix(F[0], <ModField.Element*>entries,<Py_ssize_t>nrows, <Py_ssize_t>ncols)
+    cdef Py_ssize_t r = reducedRowEchelonize(A[0])
     cdef Py_ssize_t i,j
-
-    # TODO: can we avoid this copy?
-    for i in range(nrows):
-        for j in range(ncols):
-            A.setEntry(i, j, <ModField.Element>entries[i*ncols+j])
-
-    cdef int r = EF.rowReducedEchelon(E[0], A[0])
     for i in range(nrows):
         for j in range(ncols):
-            entries[i*ncols+j] = <celement>E.getEntry(i,j)
+            entries[i*ncols+j] = <celement>A.getEntry(i,j)
 
     cdef Py_ssize_t ii = 0
     cdef list pivots = []
@@ -232,7 +223,7 @@ cdef inline linbox_echelonize_efd(celement modulus, celement* entries, Py_ssize_
                 ii = j+1
                 break
 
-    del F, A, E, EF
+    del F
     return r, pivots
 
 cdef inline celement *linbox_copy(celement modulus, celement *entries,  Py_ssize_t nrows, Py_ssize_t ncols) except? NULL:
@@ -258,15 +249,16 @@ cdef inline int linbox_rank(celement modulus, celement* entries, Py_ssize_t nrow
     del F
     return r
 
-cdef inline celement linbox_det(celement modulus, celement* entries, Py_ssize_t nrows, Py_ssize_t ncols):
+cdef inline celement linbox_det(celement modulus, celement* entries, Py_ssize_t n):
     """
     Return the determinant of this matrix.
     """
     cdef ModField *F = new ModField(<long>modulus)
-    cdef celement *cpy = linbox_copy(modulus, entries, nrows, ncols)
-    if nrows*ncols > 1000: sig_on()
-    d =  <celement>Det(F[0], nrows, ncols, <ModField.Element*>cpy, ncols)
-    if nrows*ncols > 1000: sig_off()
+    cdef celement *cpy = linbox_copy(modulus, entries, n, n)
+    if n*n > 1000: sig_on()
+    cdef celement d
+    Det(F[0], d, n, <ModField.Element*>cpy, n)
+    if n*n > 1000: sig_off()
     sig_free(cpy)
     del F
     return d
@@ -1672,9 +1664,9 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
 
         - ``algorithm``
 
-          - ``linbox`` - uses the LinBox library (``EchelonFormDomain`` implementation, default)
+          - ``linbox`` - uses the LinBox library (wrapping fflas-ffpack)
 
-          - ``linbox_noefd`` - uses the LinBox library (FFPACK directly, less memory but slower)
+          - ``linbox_noefd`` - uses the FFPACK directly, less memory and faster
 
           - ``gauss`` - uses a custom slower `O(n^3)` Gauss
             elimination implemented in Sage.
@@ -1929,7 +1921,6 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
         else:
             r, pivots = linbox_echelonize(self.p, self._entries, self._nrows, self._ncols)
         verbose('done with echelonize',t)
-
         self.cache('in_echelon_form',True)
         self.cache('rank', r)
         self.cache('pivots', tuple(pivots))
@@ -2468,7 +2459,7 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
             x = self.fetch('det')
             if not x is None:
                 return x
-            d = linbox_det(self.p, self._entries, self._nrows, self._ncols)
+            d = linbox_det(self.p, self._entries, self._nrows)
             d2 = self._coerce_element(d)
             self.cache('det', d2)
             return d2
diff --git a/src/sage/matrix/matrix_modn_sparse.pyx b/src/sage/matrix/matrix_modn_sparse.pyx
index 241167a..dd3a2f0 100644
--- a/src/sage/matrix/matrix_modn_sparse.pyx
+++ b/src/sage/matrix/matrix_modn_sparse.pyx
@@ -882,7 +882,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
             - ``'linbox'`` or ``'linbox_default'`` - (default) use LinBox
               and let it chooses the appropriate algorithm
 
-            -  ``linbox_blas_elimination'`` - use LinBox dense elimination
+            -  ``linbox_dense_elimination'`` - use LinBox dense elimination
 
             - ``'linbox_sparse_elimination'`` - use LinBox sparse elimination
 
@@ -949,7 +949,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
 
         - ``b`` -- a dense integer vector
 
-        - ``algorithm`` -- (optional) either ``None``, ``'blas_elimination'``,
+        - ``algorithm`` -- (optional) either ``None``, ``'dense_elimination'``,
           ``'sparse_elimination'``, ``'wiedemann'`` or ``'blackbox'``.
 
         OUTPUT: a pair ``(a, d)`` consisting of
@@ -968,7 +968,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
             sage: b0 = vector((1,1,1,1))
             sage: m._solve_vector_linbox(b0)
             ((-1, -7, -3, -1), 1)
-            sage: m._solve_vector_linbox(b0, 'blas_elimination')
+            sage: m._solve_vector_linbox(b0, 'dense_elimination')
             ((-1, -7, -3, -1), 1)
             sage: m._solve_vector_linbox(b0, 'sparse_elimination')
             ((-1, -7, -3, -1), 1)
@@ -984,7 +984,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
 
         TESTS::
 
-            sage: algos = ["default", "blas_elimination", "sparse_elimination",
+            sage: algos = ["default", "dense_elimination", "sparse_elimination",
             ....:          "blackbox", "wiedemann"]
             sage: for i in range(20):
             ....:     dim = randint(1, 30)
@@ -1025,8 +1025,8 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
             linbox.solve(res[0], D, A[0], b[0])
         elif method == METHOD_WIEDEMANN:
             linbox.solve(res[0], D, A[0], b[0], linbox.Method.Wiedemann())
-        elif method == METHOD_BLAS_ELIMINATION:
-            linbox.solve(res[0], D, A[0], b[0], linbox.Method.BlasElimination())
+        elif method == METHOD_DENSE_ELIMINATION:
+            linbox.solve(res[0], D, A[0], b[0], linbox.Method.DenseElimination())
         elif method == METHOD_SPARSE_ELIMINATION:
             linbox.solve(res[0], D, A[0], b[0], linbox.Method.SparseElimination())
         elif method == METHOD_BLACKBOX:
@@ -1081,7 +1081,7 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
 
         TESTS::
 
-            sage: algos = ["default", "blas_elimination", "sparse_elimination",
+            sage: algos = ["default", "dense_elimination", "sparse_elimination",
             ....:          "blackbox", "wiedemann"]
 
             sage: for _ in range(10):
@@ -1136,8 +1136,8 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
             # solve the current row
             if algo == METHOD_DEFAULT:
                 linbox.solve(res[0], D, A[0], b[0])
-            elif algo == METHOD_BLAS_ELIMINATION:
-                linbox.solve(res[0], D, A[0], b[0], linbox.Method.BlasElimination())
+            elif algo == METHOD_DENSE_ELIMINATION:
+                linbox.solve(res[0], D, A[0], b[0], linbox.Method.DenseElimination())
             elif algo == METHOD_SPARSE_ELIMINATION:
                 linbox.solve(res[0], D, A[0], b[0], linbox.Method.SparseElimination())
             elif algo == METHOD_BLACKBOX:
diff --git a/src/sage/rings/finite_rings/element_givaro.pxd b/src/sage/rings/finite_rings/element_givaro.pxd
index f0fd7e35..8ae25c5 100644
--- a/src/sage/rings/finite_rings/element_givaro.pxd
+++ b/src/sage/rings/finite_rings/element_givaro.pxd
@@ -20,35 +20,35 @@ cdef extern from "givaro/givrandom.h":
     GivRandom GivRandomSeeded  "Givaro::GivRandom"(unsigned long seed)
 
 cdef extern from "givaro/gfq.h":
-    ctypedef struct GivaroGfq "Givaro::GFqDom<int>":
+    cdef cppclass GivaroGfq "Givaro::GFqDom<int>":
         #attributes
         unsigned int one
         unsigned int zero
 
         # methods
-        int (* mul)(int r, int a, int b)
-        int (* add)(int r, int a, int b)
-        int (* sub)(int r, int a, int b)
-        int (* div)(int r, int a, int b)
-        int (* inv)(int r, int x)
-        int (* neg)(int r, int x)
-        int (* mulin)(int a, int b)
-        unsigned int (* characteristic)()
-        unsigned int (* cardinality)()
-        int (* exponent)()
-        int (* random)(GivRandom gen, int res)
-        int (* initi "init")(int res, int64_t e)
-        int (* initd "init")(int res, double e)
-        int (* indeterminate)()
-        int (* convert)(int64_t r, int p)
-        int (* read)(int r, int p)
-        int (* axpyin)(int r, int a, int x)
-        int (* axpy)(int r, int a, int b, int c)
-        int (* axmy)(int r, int a, int b, int c)
-        int (* maxpy)(int r, int a, int b, int c)
-        bint (* isZero)(int e)
-        bint (* isOne)(int e)
-        bint (* isunit)(int e)
+        int mul(int r, int a, int b)
+        int add(int r, int a, int b)
+        int sub(int r, int a, int b)
+        int div(int r, int a, int b)
+        int inv(int r, int x)
+        int neg(int r, int x)
+        int mulin(int a, int b)
+        unsigned int characteristic()
+        unsigned int cardinality()
+        int exponent()
+        int random(GivRandom gen, int res)
+        int initi "init"(int& res, int64_t e)
+        int initd "init"(int& res, double e)
+        int indeterminate()
+        int64_t convert(int64_t& r, int p)
+        int read(int& r, int p)
+        int axpyin(int r, int a, int x)
+        int axpy(int r, int a, int b, int c)
+        int axmy(int r, int a, int b, int c)
+        int maxpy(int r, int a, int b, int c)
+        bint isZero(int e)
+        bint isOne(int e)
+        bint isunit(int e)
 
     GivaroGfq *gfq_factorypk "new Givaro::GFqDom<int>" (unsigned int p, unsigned int k)
     GivaroGfq *gfq_factorypkp "new Givaro::GFqDom<int>" (unsigned int p, unsigned int k, intvec poly)
diff --git a/src/sage/rings/finite_rings/element_givaro.pyx b/src/sage/rings/finite_rings/element_givaro.pyx
index 3739020..a7f9c2f 100644
--- a/src/sage/rings/finite_rings/element_givaro.pyx
+++ b/src/sage/rings/finite_rings/element_givaro.pyx
@@ -310,7 +310,7 @@ cdef class Cache_givaro(SageObject):
         cdef int seed = current_randstate().c_random()
         cdef int res
         cdef GivRandom generator = GivRandomSeeded(seed)
-        res = self.objectptr.random(generator,res)
+        self.objectptr.random(generator,res)
         return make_FiniteField_givaroElement(self,res)
 
     cpdef FiniteField_givaroElement element_from_data(self, e):
@@ -386,16 +386,16 @@ cdef class Cache_givaro(SageObject):
              isinstance(e, long) or is_IntegerMod(e):
             try:
                 e_int = e % self.characteristic()
-                res = self.objectptr.initi(res, e_int)
+                self.objectptr.initi(res, e_int)
             except ArithmeticError:
                 raise TypeError("unable to coerce from a finite field other than the prime subfield")
         elif e is None:
             e_int = 0
-            res = self.objectptr.initi(res, e_int)
+            self.objectptr.initi(res, e_int)
 
         elif isinstance(e, float):
             e_int = int(e) % self.characteristic()
-            res = self.objectptr.initd(res, e_int)
+            self.objectptr.initd(res, e_int)
 
         elif isinstance(e, str):
             return self.parent(eval(e.replace("^","**"),self.parent.gens_dict()))
@@ -406,7 +406,7 @@ cdef class Cache_givaro(SageObject):
             ret = self._zero_element
             for i in range(len(e)):
                 e_int = e[i] % self.characteristic()
-                res = self.objectptr.initi(res, e_int)
+                self.objectptr.initi(res, e_int)
                 to_add = make_FiniteField_givaroElement(self, res)
                 ret = ret + to_add*self.parent.gen()**i
             return ret
@@ -446,7 +446,7 @@ cdef class Cache_givaro(SageObject):
             ret = self._zero_element
             for i in range(len(e)):
                 e_int = e[i] % self.characteristic()
-                res = self.objectptr.initi(res, e_int)
+                self.objectptr.initi(res, e_int)
                 to_add = make_FiniteField_givaroElement(self, res)
                 ret = ret + to_add*self.parent.gen()**i
             return ret
@@ -475,8 +475,8 @@ cdef class Cache_givaro(SageObject):
 
                 for i from 0 <= i <= degpol(t):
                     c = gtolong(gel(t, i+2))
-                    res = self.objectptr.axpyin(res, self.int_to_log(c), x)
-                    x = self.objectptr.mul(x,x,g)
+                    self.objectptr.axpyin(res, self.int_to_log(c), x)
+                    self.objectptr.mulin(x,g)
                 clear_stack()
             else:
                 clear_stack()
@@ -580,21 +580,10 @@ cdef class Cache_givaro(SageObject):
             sage: 2^7 + 2^4 + 2^2 + 2 + 1
             151
         """
-        cdef GivaroGfq *k = self.objectptr
-        cdef int ret = k.zero
-        cdef int a = k.indeterminate()
-        cdef int at = k.one
-        cdef int ch = k.characteristic()
-        cdef int t, i
-
-        if n<0 or n>k.cardinality():
+        if n<0 or n>self.order():
             raise TypeError("n must be between 0 and self.order()")
 
-        for i from 0 <= i < k.exponent():
-            t = k.initi(t, n % ch)
-            ret = k.axpy(ret, t, at, ret)
-            at = k.mul(at,at,a)
-            n //= ch
+        cdef int ret = self.int_to_log(n)
         return make_FiniteField_givaroElement(self, ret)
 
     def _element_repr(self, FiniteField_givaroElement e):
@@ -715,7 +704,7 @@ cdef class Cache_givaro(SageObject):
         """
         cdef int r
 
-        r = self.objectptr.axpy(r, a.element, b.element, c.element)
+        self.objectptr.axpy(r, a.element, b.element, c.element)
         return make_FiniteField_givaroElement(self,r)
 
     def a_times_b_minus_c(self,FiniteField_givaroElement a, FiniteField_givaroElement b, FiniteField_givaroElement c):
@@ -734,7 +723,7 @@ cdef class Cache_givaro(SageObject):
         """
         cdef int r
 
-        r = self.objectptr.axmy(r, a.element, b.element, c.element, )
+        self.objectptr.axmy(r, a.element, b.element, c.element, )
         return make_FiniteField_givaroElement(self,r)
 
     def c_minus_a_times_b(self,FiniteField_givaroElement a,
@@ -754,7 +743,7 @@ cdef class Cache_givaro(SageObject):
         """
         cdef int r
 
-        r = self.objectptr.maxpy(r , a.element, b.element, c.element, )
+        self.objectptr.maxpy(r , a.element, b.element, c.element, )
         return make_FiniteField_givaroElement(self,r)
 
     def __reduce__(self):
@@ -1108,7 +1097,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
             2*b^3 + 2*b^2 + 2*b + 1
         """
         cdef int r
-        r = self._cache.objectptr.add(r, self.element ,
+        self._cache.objectptr.add(r, self.element ,
                                               (<FiniteField_givaroElement>right).element )
         return make_FiniteField_givaroElement(self._cache,r)
 
@@ -1125,7 +1114,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
             c^2
         """
         cdef int r
-        r = self._cache.objectptr.mul(r, self.element,
+        self._cache.objectptr.mul(r, self.element,
                                               (<FiniteField_givaroElement>right).element)
         return make_FiniteField_givaroElement(self._cache,r)
 
@@ -1147,7 +1136,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
         cdef int r
         if (<FiniteField_givaroElement>right).element == 0:
             raise ZeroDivisionError('division by zero in finite field')
-        r = self._cache.objectptr.div(r, self.element,
+        self._cache.objectptr.div(r, self.element,
                                               (<FiniteField_givaroElement>right).element)
         return make_FiniteField_givaroElement(self._cache,r)
 
@@ -1164,7 +1153,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
             2*a^2 + 2*a
         """
         cdef int r
-        r = self._cache.objectptr.sub(r, self.element,
+        self._cache.objectptr.sub(r, self.element,
                                               (<FiniteField_givaroElement>right).element)
         return make_FiniteField_givaroElement(self._cache,r)
 
@@ -1181,7 +1170,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
         """
         cdef int r
 
-        r = self._cache.objectptr.neg(r, self.element)
+        self._cache.objectptr.neg(r, self.element)
         return make_FiniteField_givaroElement(self._cache,r)
 
     def __invert__(FiniteField_givaroElement self):