diff --git a/src/libgap-api.c b/src/libgap-api.c index 2bb0483fc5..24117d8c85 100644 --- a/src/libgap-api.c +++ b/src/libgap-api.c @@ -412,6 +412,7 @@ Obj GAP_NewPlist(Int capacity) //// static Obj IsMatrixOrMatrixObjFilt; +static Obj IsMatrixFilt; static Obj IsMatrixObjFilt; static Obj NrRowsAttr; static Obj NrColsAttr; @@ -419,13 +420,19 @@ static Obj NrColsAttr; // Returns 1 if is a GAP matrix or matrix obj, 0 if not. int GAP_IsMatrixOrMatrixObj(Obj obj) { - return obj && DoFilter(IsMatrixOrMatrixObjFilt, obj) == True; + return obj && CALL_1ARGS(IsMatrixOrMatrixObjFilt, obj) == True; +} + +// Returns 1 if is a GAP matrix, 0 if not. +int GAP_IsMatrix(Obj obj) +{ + return obj && CALL_1ARGS(IsMatrixFilt, obj) == True; } // Returns 1 if is a GAP matrix obj, 0 if not. int GAP_IsMatrixObj(Obj obj) { - return obj && DoFilter(IsMatrixObjFilt, obj) == True; + return obj && CALL_1ARGS(IsMatrixObjFilt, obj) == True; } // Returns the number of rows of the given GAP matrix obj. @@ -436,17 +443,17 @@ UInt GAP_NrRows(Obj mat) return UInt_ObjInt(nrows); } -// Returns the number of columns of the given GAP matrix obj. -// If is not a GAP matrix obj, an error may be raised. +// Returns the number of columns of the given GAP matrix or matrix obj. +// If is not a GAP matrix or matrix obj, an error may be raised. UInt GAP_NrCols(Obj mat) { Obj ncols = CALL_1ARGS(NrColsAttr, mat); return UInt_ObjInt(ncols); } -// Assign at position into the GAP matrix obj . +// Assign at the , into the GAP matrix or matrix obj . // If is zero, then this unbinds the list entry. -// If is not a GAP matrix obj, an error may be raised. +// If is not a GAP matrix or matrix obj, an error may be raised. void GAP_AssMat(Obj mat, UInt row, UInt col, Obj val) { Obj r = ObjInt_UInt(row); @@ -456,8 +463,8 @@ void GAP_AssMat(Obj mat, UInt row, UInt col, Obj val) // Returns the element at the , in the GAP matrix obj . // Returns 0 if or are out of bounds, i.e., if either -// is zero, or larger than the number of rows respectively columns of the list. -// If is not a GAP matrix obj, an error may be raised. +// is zero, or larger than the number of rows respectively columns of . +// If is not a GAP matrix or matrix obj, an error may be raised. Obj GAP_ElmMat(Obj mat, UInt row, UInt col) { Obj r = ObjInt_UInt(row); @@ -616,6 +623,7 @@ void GAP_Error_Postjmp_Returning_(void) static Int InitKernel(StructInitInfo * module) { InitFopyGVar("IsMatrixOrMatrixObj", &IsMatrixOrMatrixObjFilt); + InitFopyGVar("IsMatrix", &IsMatrixFilt); InitFopyGVar("IsMatrixObj", &IsMatrixObjFilt); InitFopyGVar("NrRows", &NrRowsAttr); InitFopyGVar("NrCols", &NrColsAttr); diff --git a/src/libgap-api.h b/src/libgap-api.h index d15068ee04..1d5d814425 100644 --- a/src/libgap-api.h +++ b/src/libgap-api.h @@ -374,18 +374,31 @@ Obj GAP_NewPlist(Int capacity); //// matrix obj //// +// Note that the meaning of the following filters is not self-explanatory, +// see the chapter "Vector and Matrix Objects" in the GAP Reference Manual. +// `GAP_IsMatrixOrMatrixObj` checks whether the argument is an abstract +// 2-dim. array; such objects admit access to entries via `GAP_ElmMat`, +// one can ask for the numbers of rows and columns via `GAP_NrRows` and +// `GAP_NrCols`, respectively, etc. +// `GAP_IsMatrix` checks for special cases that are nonempty list of lists +// with additional properties; often these are plain lists. +// `GAP_IsMatrixObj` checks for special cases that are not plain lists. + // Returns 1 if is a GAP matrix or matrix obj, 0 if not. int GAP_IsMatrixOrMatrixObj(Obj obj); +// Returns 1 if is a GAP matrix, 0 if not. +int GAP_IsMatrix(Obj obj); + // Returns 1 if is a GAP matrix obj, 0 if not. int GAP_IsMatrixObj(Obj obj); -// Returns the number of rows of the given GAP matrix obj. -// If is not a GAP matrix obj, an error may be raised. +// Returns the number of rows of the given GAP matrix or matrix obj. +// If is not a GAP matrix or matrix obj, an error may be raised. UInt GAP_NrRows(Obj mat); -// Returns the number of columns of the given GAP matrix obj. -// If is not a GAP matrix obj, an error may be raised. +// Returns the number of columns of the given GAP matrix or matrix obj. +// If is not a GAP matrix or matrix obj, an error may be raised. UInt GAP_NrCols(Obj mat); // Assign at position into the GAP matrix obj . diff --git a/tst/testlibgap/api.c b/tst/testlibgap/api.c index c11c45bc41..d6314d8a8a 100644 --- a/tst/testlibgap/api.c +++ b/tst/testlibgap/api.c @@ -68,10 +68,13 @@ void matrices(void) assert(!GAP_IsMatrixOrMatrixObj(mat)); // empty list, not yet a matrix assert(!GAP_IsMatrixObj(mat)); + assert(!GAP_IsMatrix(mat)); assert(!GAP_IsMatrixOrMatrixObj(0)); assert(!GAP_IsMatrixObj(0)); + assert(!GAP_IsMatrix(0)); assert(!GAP_IsMatrixOrMatrixObj(val)); assert(!GAP_IsMatrixObj(val)); + assert(!GAP_IsMatrix(val)); row = GAP_NewPlist(2); GAP_AssList(row, 1, INTOBJ_INT(1)); @@ -79,8 +82,10 @@ void matrices(void) GAP_AssList(mat, 1, row); assert(!GAP_IsMatrixOrMatrixObj(row)); assert(!GAP_IsMatrixObj(row)); + assert(!GAP_IsMatrix(row)); assert(GAP_IsMatrixOrMatrixObj(mat)); assert(!GAP_IsMatrixObj(mat)); // list of lists, not proper matrix object + assert(GAP_IsMatrix(mat)); GAP_AssMat(mat, 1, 1, val); ret = GAP_ElmMat(mat, 1, 1);