-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IsPositionalVectorRep, IsPositionalMatrixRep
- Loading branch information
Showing
6 changed files
with
147 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
############################################################################# | ||
## | ||
## This file is part of GAP, a system for computational discrete algebra. | ||
## | ||
## SPDX-License-Identifier: GPL-2.0-or-later | ||
## | ||
## Copyright of GAP belongs to its developers, whose names are too numerous | ||
## to list here. Please refer to the COPYRIGHT file for details. | ||
## | ||
|
||
# TODO: document this | ||
DeclareRepresentation( "IsPositionalVectorRep", | ||
IsVectorObj and IsPositionalObjectRep | ||
and IsNoImmediateMethodsObject | ||
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain, | ||
[] ); | ||
|
||
# TODO: document this | ||
DeclareRepresentation( "IsPositionalMatrixRep", | ||
IsMatrixObj and IsPositionalObjectRep | ||
and IsNoImmediateMethodsObject | ||
and HasNumberRows and HasNumberColumns | ||
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain, | ||
[] ); | ||
|
||
|
||
# | ||
# Some constants for matrix resp. vector access | ||
# | ||
# TODO: For now the order follows the order of the predecessors: | ||
# BDPOS = 1, RLPOS = 3, ROWSPOS = 4; the goal is to | ||
# eventually change this. But this needs us to carefully revisit | ||
# all Objectify calls | ||
|
||
# Position of the base domain | ||
BindConstant( "MAT_BD_POS", 1 ); | ||
# Position of the number of rows | ||
BindConstant( "MAT_NROWS_POS", 5 ); # FIXME: in many cases superfluous (can be computed from NCOLS and DATA) | ||
# Position of the number of columns | ||
BindConstant( "MAT_NCOLS_POS", 3 ); # | ||
# Position of the data | ||
BindConstant( "MAT_DATA_POS", 4 ); | ||
|
||
# Position of the base domain | ||
BindConstant( "VEC_BD_POS", 1 ); | ||
# Position of the data | ||
BindConstant( "VEC_DATA_POS", 2 ); | ||
# Position of the length | ||
#BindConstant( "VEC_LENPOS", 3 ); # FIXME: not actually needed in general???? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
############################################################################# | ||
## | ||
## This file is part of GAP, a system for computational discrete algebra. | ||
## | ||
## SPDX-License-Identifier: GPL-2.0-or-later | ||
## | ||
## Copyright of GAP belongs to its developers, whose names are too numerous | ||
## to list here. Please refer to the COPYRIGHT file for details. | ||
## | ||
|
||
############################################################################ | ||
# | ||
# Operations for positional matrix objects | ||
# | ||
############################################################################ | ||
|
||
InstallMethod( BaseDomain, [ IsPositionalVectorRep ], | ||
function( v ) | ||
return v![VEC_BD_POS]; | ||
end ); | ||
|
||
InstallMethod( Length, [ IsPositionalVectorRep ], | ||
function( v ) | ||
return Length(v![VEC_DATA_POS]); # FIXME: assumptions | ||
end ); | ||
|
||
|
||
InstallMethod( ShallowCopy, [ IsPositionalVectorRep ], | ||
function( v ) | ||
local i, res; | ||
res := List([1..LEN_POSOBJ(v)], i -> v![i]); | ||
res![VEC_DATA_POS] := ShallowCopy(v![VEC_DATA_POS]); | ||
res := Objectify(TypeObj(v), res); | ||
|
||
# 'ShallowCopy' MUST return a mutable object if such an object exists at all! | ||
if not IsMutable(v) then | ||
SetFilterObj(res, IsMutable); | ||
fi; | ||
return res; | ||
end ); | ||
|
||
# StructuralCopy works automatically | ||
|
||
InstallMethod( PostMakeImmutable, [ IsPositionalVectorRep ], | ||
function( v ) | ||
MakeImmutable( v![VEC_DATA_POS] ); | ||
end ); | ||
|
||
|
||
############################################################################ | ||
# | ||
# Operations for positional matrix objects | ||
# | ||
############################################################################ | ||
|
||
InstallMethod( BaseDomain, [ IsPositionalMatrixRep ], | ||
function( m ) | ||
return m![MAT_BD_POS]; | ||
end ); | ||
|
||
InstallMethod( NumberRows, [ IsPositionalMatrixRep ], | ||
function( m ) | ||
return Length(m![MAT_DATA_POS]); # FIXME: this makes assumptions... | ||
end ); | ||
|
||
InstallMethod( NumberColumns, [ IsPositionalMatrixRep ], | ||
function( m ) | ||
return m![MAT_NCOLS_POS]; | ||
end ); | ||
|
||
InstallMethod( ShallowCopy, [ IsPositionalMatrixRep ], | ||
function( m ) | ||
local res; | ||
res := List([1..LEN_POSOBJ(m)], i -> m![i]); | ||
res![MAT_DATA_POS] := ShallowCopy(m![MAT_DATA_POS]); | ||
res := Objectify(TypeObj(m), res); | ||
|
||
# 'ShallowCopy' MUST return a mutable object if such an object exists at all! | ||
if not IsMutable(m) then | ||
SetFilterObj(res, IsMutable); | ||
fi; | ||
return res; | ||
end ); | ||
|
||
InstallMethod( PostMakeImmutable, [ IsPositionalMatrixRep ], | ||
function( m ) | ||
MakeImmutable( m![MAT_DATA_POS] ); | ||
end ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters