Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kernel functions for directly accessing entries of GF2/8bit compressed matrices #1585

Merged
merged 2 commits into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hpcgap/lib/mat8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ InstallOtherMethod( Length, "For a compressed MatFFE",
##

InstallOtherMethod( \[\], "For a compressed MatFFE",
true, [IsList and Is8BitMatrixRep, IsPosInt], 0, function(m,i)
return m![i+1]; end);
[IsList and Is8BitMatrixRep, IsPosInt],
ELM_MAT8BIT
);

#############################################################################
##
Expand All @@ -88,8 +89,7 @@ InstallOtherMethod( \[\], "For a compressed MatFFE",
##

InstallOtherMethod( \[\]\:\=, "For a compressed MatFE",
true, [IsMutable and IsList and Is8BitMatrixRep, IsPosInt, IsObject],
0,
[IsMutable and IsList and Is8BitMatrixRep, IsPosInt, IsObject],
ASS_MAT8BIT
);

Expand Down
4 changes: 2 additions & 2 deletions hpcgap/lib/vec8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,10 @@ InstallMethod( MutableCopyMat, "for an 8bit matrix",
end );
InstallMethod( MatElm, "for an 8bit matrix and two integers",
[ Is8BitMatrixRep, IsPosInt, IsPosInt ],
function( m, r, c ) return m[r][c]; end );
MAT_ELM_MAT8BIT );
InstallMethod( SetMatElm, "for an 8bit matrix, two integers, and a ffe",
[ Is8BitMatrixRep, IsPosInt, IsPosInt, IsFFE ],
function( m, r, c, e ) m[r][c] := e; end );
SET_MAT_ELM_MAT8BIT );
InstallMethod( Matrix, "for a list of vecs, an integer, and an 8bit mat",
[IsList, IsInt, Is8BitMatrixRep],
function(l,rl,m)
Expand Down
30 changes: 10 additions & 20 deletions hpcgap/lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -574,42 +574,30 @@ end );

#############################################################################
##
#M ELM_LIST( <list>, <pos> ) . . . . . . . select an element of a GF2 matrix
#M <list> [ <pos> ] . . . . . . . . . . . select an element of a GF2 matrix
##
InstallOtherMethod( ELM_LIST,
"for GF2 matrix",
true,
InstallOtherMethod( \[\], "for GF2 matrix",
[ IsMatrix and IsGF2MatrixRep,
IsPosInt ],
0,

function( list, pos )
return list![pos+1];
end );


ELM_GF2MAT );


#############################################################################
##
#M ASS_LIST( <gf2mat>, <pos>, <elm> ) . . assign an element to a GF2 matrix
#M <gf2mat> [ <pos> ] := <elm> . . . . . . assign an element to a GF2 matrix
##
InstallOtherMethod( ASS_LIST,
InstallOtherMethod( \[\]\:\=,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep and IsMutable,
IsPosInt,
IsObject ],
0,
ASS_GF2MAT );

InstallOtherMethod( ASS_LIST,
InstallOtherMethod( \[\]\:\=,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep,
IsPosInt,
IsObject ],
0,
ASS_GF2MAT );


Expand Down Expand Up @@ -2382,12 +2370,14 @@ InstallMethod( MutableCopyMat, "for a gf2 matrix",
ConvertToMatrixRep(mm,2);
return mm;
end );

InstallMethod( MatElm, "for a gf2 matrix and two integers",
[ IsGF2MatrixRep, IsPosInt, IsPosInt ],
function( m, r, c ) return m[r][c]; end );
MAT_ELM_GF2MAT );
InstallMethod( SetMatElm, "for a gf2 matrix, two integers, and a ffe",
[ IsGF2MatrixRep, IsPosInt, IsPosInt, IsFFE ],
function( m, r, c, e ) m[r][c] := e; end );
SET_MAT_ELM_GF2MAT );

InstallMethod( Matrix, "for a list of vecs, an integer, and a gf2 mat",
[IsList, IsInt, IsGF2MatrixRep],
function(l,rl,m)
Expand Down
8 changes: 4 additions & 4 deletions lib/mat8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ InstallOtherMethod( Length, "For a compressed MatFFE",
##

InstallOtherMethod( \[\], "For a compressed MatFFE",
true, [IsList and Is8BitMatrixRep, IsPosInt], 0, function(m,i)
return m![i+1]; end);
[IsList and Is8BitMatrixRep, IsPosInt],
ELM_MAT8BIT
);

#############################################################################
##
Expand All @@ -85,8 +86,7 @@ InstallOtherMethod( \[\], "For a compressed MatFFE",
##

InstallOtherMethod( \[\]\:\=, "For a compressed MatFE",
true, [IsMutable and IsList and Is8BitMatrixRep, IsPosInt, IsObject],
0,
[IsMutable and IsList and Is8BitMatrixRep, IsPosInt, IsObject],
ASS_MAT8BIT
);

Expand Down
4 changes: 2 additions & 2 deletions lib/vec8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,10 @@ InstallMethod( MutableCopyMat, "for an 8bit matrix",
end );
InstallMethod( MatElm, "for an 8bit matrix and two integers",
[ Is8BitMatrixRep, IsPosInt, IsPosInt ],
function( m, r, c ) return m[r][c]; end );
MAT_ELM_MAT8BIT );
InstallMethod( SetMatElm, "for an 8bit matrix, two integers, and a ffe",
[ Is8BitMatrixRep, IsPosInt, IsPosInt, IsFFE ],
function( m, r, c, e ) m[r][c] := e; end );
SET_MAT_ELM_MAT8BIT );
InstallMethod( Matrix, "for a list of vecs, an integer, and an 8bit mat",
[IsList, IsInt, Is8BitMatrixRep],
function(l,rl,m)
Expand Down
30 changes: 10 additions & 20 deletions lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -553,42 +553,30 @@ end );

#############################################################################
##
#M ELM_LIST( <list>, <pos> ) . . . . . . . select an element of a GF2 matrix
#M <list> [ <pos> ] . . . . . . . . . . . select an element of a GF2 matrix
##
InstallOtherMethod( ELM_LIST,
"for GF2 matrix",
true,
InstallOtherMethod( \[\], "for GF2 matrix",
[ IsMatrix and IsGF2MatrixRep,
IsPosInt ],
0,

function( list, pos )
return list![pos+1];
end );


ELM_GF2MAT );


#############################################################################
##
#M ASS_LIST( <gf2mat>, <pos>, <elm> ) . . assign an element to a GF2 matrix
#M <gf2mat> [ <pos> ] := <elm> . . . . . . assign an element to a GF2 matrix
##
InstallOtherMethod( ASS_LIST,
InstallOtherMethod( \[\]\:\=,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep and IsMutable,
IsPosInt,
IsObject ],
0,
ASS_GF2MAT );

InstallOtherMethod( ASS_LIST,
InstallOtherMethod( \[\]\:\=,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep,
IsPosInt,
IsObject ],
0,
ASS_GF2MAT );


Expand Down Expand Up @@ -2177,12 +2165,14 @@ InstallMethod( MutableCopyMat, "for a gf2 matrix",
ConvertToMatrixRep(mm,2);
return mm;
end );

InstallMethod( MatElm, "for a gf2 matrix and two integers",
[ IsGF2MatrixRep, IsPosInt, IsPosInt ],
function( m, r, c ) return m[r][c]; end );
MAT_ELM_GF2MAT );
InstallMethod( SetMatElm, "for a gf2 matrix, two integers, and a ffe",
[ IsGF2MatrixRep, IsPosInt, IsPosInt, IsFFE ],
function( m, r, c, e ) m[r][c] := e; end );
SET_MAT_ELM_GF2MAT );

InstallMethod( Matrix, "for a list of vecs, an integer, and a gf2 mat",
[IsList, IsInt, IsGF2MatrixRep],
function(l,rl,m)
Expand Down
92 changes: 92 additions & 0 deletions src/vec8bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4097,6 +4097,26 @@ Obj FuncASS_MAT8BIT(Obj self, Obj mat, Obj p, Obj obj)
return (Obj)0;
}


/****************************************************************************
**
*F FuncELM_MAT8BIT( <self>, <mat>, <row> ) . select a row of an 8bit matrix
**
*/
Obj FuncELM_MAT8BIT( Obj self, Obj mat, Obj row )
{
if (!IS_POS_INTOBJ(row)) {
ErrorMayQuit("ELM_MAT8BIT: position must be a small integer, not a %s",
(Int)TNAM_OBJ(row), 0L);
}
UInt r = INT_INTOBJ(row);
if (LEN_MAT8BIT(mat) < r) {
ErrorMayQuit("row index %d exceeds %d, the number of rows", r, LEN_MAT8BIT(mat));
}
return ELM_MAT8BIT(mat, r);
}


/****************************************************************************
**
*F SumMat8BitMat8Bit( <ml> ,<mr>)
Expand Down Expand Up @@ -5836,6 +5856,75 @@ Obj FuncKRONECKERPRODUCT_MAT8BIT_MAT8BIT( Obj self, Obj matl, Obj matr)
}


/****************************************************************************
**
*F FuncMAT_ELM_MAT8BIT( <self>, <mat>, <row>, <col> )
**
*/
Obj FuncMAT_ELM_MAT8BIT( Obj self, Obj mat, Obj row, Obj col )
{
if (!IS_POS_INTOBJ(row)) {
ErrorMayQuit("row index must be a small positive integer, not a %s",
(Int)TNAM_OBJ(row), 0L);
}
if (!IS_POS_INTOBJ(col)) {
ErrorMayQuit("column index must be a small positive integer, not a %s",
(Int)TNAM_OBJ(col), 0L);
}

UInt r = INT_INTOBJ(row);
if (LEN_MAT8BIT(mat) < r) {
ErrorMayQuit("row index %d exceeds %d, the number of rows", r, LEN_MAT8BIT(mat));
}

Obj vec = ELM_MAT8BIT(mat, r);

UInt c = INT_INTOBJ(col);
if (LEN_VEC8BIT(vec) < c) {
ErrorMayQuit("column index %d exceeds %d, the number of columns", c, LEN_VEC8BIT(vec));
}

return FuncELM_VEC8BIT(self, vec, col);
}


/****************************************************************************
**
*F FuncSET_MAT_ELM_MAT8BIT( <self>, <mat>, <row>, <col>, <elm> )
**
*/
Obj FuncSET_MAT_ELM_MAT8BIT( Obj self, Obj mat, Obj row, Obj col, Obj elm )
{
if (!IS_POS_INTOBJ(row)) {
ErrorMayQuit("row index must be a small positive integer, not a %s",
(Int)TNAM_OBJ(row), 0L);
}
if (!IS_POS_INTOBJ(col)) {
ErrorMayQuit("column index must be a small positive integer, not a %s",
(Int)TNAM_OBJ(col), 0L);
}

UInt r = INT_INTOBJ(row);
if (LEN_MAT8BIT(mat) < r) {
ErrorMayQuit("row index %d exceeds %d, the number of rows", r, LEN_MAT8BIT(mat));
}

Obj vec = ELM_MAT8BIT(mat, r);
if ( ! IS_MUTABLE_OBJ(vec) ) {
ErrorMayQuit("row %d is immutable", r, 0);
}

UInt c = INT_INTOBJ(col);
if (LEN_VEC8BIT(vec) < c) {
ErrorMayQuit("column index %d exceeds %d, the number of columns", c, LEN_VEC8BIT(vec));
}

// TODO: replace the following call by direct access? E.g. so that we can
// always reject input elements in the "wrong domain"?
return FuncASS_VEC8BIT( self, vec, col, elm );
}


/****************************************************************************
**
*f * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -5892,6 +5981,7 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(INV_MAT8BIT_SAME_MUTABILITY, 1, "mat"),
GVAR_FUNC(INV_MAT8BIT_IMMUTABLE, 1, "mat"),
GVAR_FUNC(ASS_MAT8BIT, 3, "mat, pos, obj"),
GVAR_FUNC(ELM_MAT8BIT, 2, "mat, pos"),
GVAR_FUNC(SUM_MAT8BIT_MAT8BIT, 2, "ml, mr"),
GVAR_FUNC(DIFF_MAT8BIT_MAT8BIT, 2, "ml, mr"),
GVAR_FUNC(ADD_COEFFS_VEC8BIT_3, 3, "vec1, vec2, mult"),
Expand All @@ -5917,6 +6007,8 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(LT_MAT8BIT_MAT8BIT, 2, "mat8bit, mat8bit"),
GVAR_FUNC(TRANSPOSED_MAT8BIT, 1, "mat8bit"),
GVAR_FUNC(KRONECKERPRODUCT_MAT8BIT_MAT8BIT, 2, "mat8bit, mat8bit"),
GVAR_FUNC(MAT_ELM_MAT8BIT, 3, "mat, row, col"),
GVAR_FUNC(SET_MAT_ELM_MAT8BIT, 4, "mat, row, col, elm"),
{ 0, 0, 0, 0, 0 }

};
Expand Down
Loading