Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
More stuff in the meataxe interface, and a meataxe helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-king-jena authored and jdemeyer committed Jun 6, 2018
1 parent 3c4a06d commit 1eaed37
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/sage/libs/meataxe.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ cdef extern from "meataxe.h":
cdef extern int FfChar # Current characteristic
cdef extern FEL FfGen # Generator
cdef extern int FfNoc # Number of columns for row ops
cdef extern int MPB # Number of marks stored in a single byte
cdef extern size_t FfCurrentRowSize # The byte size of a single row in memory,
# always a multiple of sizeof(long)
cdef extern size_t FfCurrentRowSizeIo # The number of bytes actually used in a row.
cdef extern size_t FfCurrentRowSizeIo # The number of bytes actually used in a row
cdef extern char MtxLibDir[1024] # Where to search/create multiplication tables

# we only wrap MeatAxe for small fields (size < 255)
Expand All @@ -50,12 +51,12 @@ cdef extern from "meataxe.h":
int FfSetNoc(int ncols) except -1

## Finite Fields
# FEL FfAdd(FEL a,FEL b)
# FEL FfSub(FEL a, FEL b)
# FEL FfNeg(FEL a)
# FEL FfMul(FEL a, FEL b)
# FEL FfDiv(FEL a, FEL b)
# FEL FfInv(FEL a)
FEL FfAdd(FEL a, FEL b)
FEL FfSub(FEL a, FEL b)
FEL FfNeg(FEL a)
FEL FfMul(FEL a, FEL b)
FEL FfDiv(FEL a, FEL b)
FEL FfInv(FEL a)
# FEL FfEmbed(FEL a, int subfield) except 255
# FEL FfRestrict(FEL a, int subfield) except 255
FEL FfFromInt(int l)
Expand All @@ -64,8 +65,11 @@ cdef extern from "meataxe.h":
## Rows
void FfMulRow(PTR row, FEL mark)
void FfAddMulRow(PTR dest, PTR src, FEL f)
void FfAddMulRowPartial(PTR dest, PTR src, FEL f, int first, int len)
PTR FfAddRow(PTR dest, PTR src)
PTR FfAddRowPartial(PTR dest, PTR src, int first, int len)
PTR FfSubRow(PTR dest, PTR src)
PTR FfSubRowPartial(PTR dest, PTR src, int first, int len)
FEL FfExtract(PTR row, int col)
void FfInsert(PTR row, int col, FEL mark)
int FfFindPivot(PTR row, FEL *mark)
Expand Down Expand Up @@ -130,6 +134,7 @@ cdef extern from "meataxe.h":
long MatNullity(Matrix_t *mat)
Matrix_t *MatInverse(Matrix_t *src) except NULL
Matrix_t *MatNullSpace(Matrix_t *mat) except NULL
Matrix_t *MatNullSpace__(Matrix_t *mat) except NULL

## Error handling
cdef extern int MTX_ERR_NOMEM, MTX_ERR_GAME_OVER, MTX_ERR_DIV0, MTX_ERR_FILEFMT, MTX_ERR_BADARG
Expand All @@ -146,3 +151,5 @@ cdef extern from "meataxe.h":

ctypedef void MtxErrorHandler_t(MtxErrorRecord_t*)
MtxErrorHandler_t *MtxSetErrorHandler(MtxErrorHandler_t *h)

cdef Matrix_t *rawMatrix(int Field, list entries) except NULL
26 changes: 26 additions & 0 deletions src/sage/libs/meataxe.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ cdef dict ErrMsg = {
"Not a permutation": TypeError
}

cdef Matrix_t *rawMatrix(int Field, list entries) except NULL:
"""
Return a meataxe matrix.
INPUT:
- ``Field``: Integer, the field size
- ``entries``: list of lists, the entries of the matrix, also defining the
matrix dimensions. It is *not* tested that all rows
in ``entries`` have the same length, and it is assumed
that both the number of rows and the number of columns
is positive. All elements are given by ints, they are
automatically interpreted as field elements.
"""
cdef Matrix_t *M = MatAlloc(Field, len(entries), len(entries[0]))
cdef PTR x = M.Data
cdef int idx, i, j
cdef list dt_i
for i in range(M.Nor):
idx = 0
dt_i = entries[i]
for j in range(M.Noc):
FfInsert(x, j, FfFromInt(dt_i[j]))
FfStepPtr(&(x))
return M

###############################################################
## It is needed to do some initialisation. Since the meataxe
## version used in Sage (SharedMeatAxe) is a dynamic (shared)
Expand Down
2 changes: 2 additions & 0 deletions src/sage/matrix/matrix_gfpn_dense.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ cdef class FieldConverter_class:
cpdef object int_to_field(self, int x)
cpdef int field_to_int(self, x)

cdef FieldConverter_class FieldConverter(field)

from sage.matrix.matrix_dense cimport Matrix_dense
from sage.structure.element cimport Matrix
from sage.libs.meataxe cimport *
Expand Down

0 comments on commit 1eaed37

Please sign in to comment.