Skip to content

Commit

Permalink
#38960 simplify eclib interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCremona committed Dec 4, 2024
1 parent 1b3d718 commit f0dc04f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/sage/libs/eclib/__init__.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ cdef extern from "eclib/matrix.h":
cdef cppclass mat:
mat()
mat(mat m)
vector[scalar] get_entries()
scalar sub(long, long)
long nrows()
long ncols()
Expand All @@ -67,7 +66,6 @@ cdef extern from "eclib/smatrix.h":
cdef cppclass smat:
smat()
smat(smat m)
vector[scalar] get_entries()
scalar sub(long, long)
long nrows()
long ncols()
Expand Down
18 changes: 7 additions & 11 deletions src/sage/libs/eclib/mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ from sage.rings.integer_ring import ZZ
from sage.matrix.matrix_integer_sparse cimport Matrix_integer_sparse
from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
from sage.rings.integer cimport Integer
from libcpp.vector cimport vector

cdef class Matrix:
"""
Expand Down Expand Up @@ -212,30 +211,27 @@ cdef class Matrix:
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
"""
cdef long n = self.nrows()
cdef long i, j, k
cdef vector[scalar] v = <vector[scalar]> self.M.get_entries() # coercion needed to deal with const
cdef long i, j

cdef Matrix_integer_dense Td
cdef Matrix_integer_sparse Ts

# Ugly code...
if sparse:
Ts = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__()
k = 0
for i from 0 <= i < n:
for j from 0 <= j < n:
if v[k]:
Ts.set_unsafe(i, j, Integer(v[k]))
k += 1
Mij = Integer(self.M.sub(i+1,j+1));
if Mij:
Ts.set_unsafe(i, j, Mij)
return Ts
else:
Td = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__()
k = 0
for i from 0 <= i < n:
for j from 0 <= j < n:
if v[k]:
Td.set_unsafe(i, j, Integer(v[k]))
k += 1
Mij = Integer(self.M.sub(i+1,j+1));
if Mij:
Td.set_unsafe(i, j, Mij)
return Td


Expand Down

0 comments on commit f0dc04f

Please sign in to comment.