-
Notifications
You must be signed in to change notification settings - Fork 162
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
WIP: positional matrix obj rep #5217
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and |
||
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???? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
############################################################################# | ||
## | ||
## 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); | ||
# FIXME: actually the "generic" ShallowCopy method is wrong, as it | ||
# e.g. doesn't reset IsZero etc -- if we want to keep this, we need | ||
# something like a helper to produce a "basic" typeobj for the | ||
# given basedomain. | ||
|
||
|
||
# 'ShallowCopy' MUST return a mutable object if such an object exists at all! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My interpretation of |
||
if not IsMutable(v) then | ||
SetFilterObj(res, IsMutable); | ||
fi; | ||
return res; | ||
end ); | ||
|
||
# StructuralCopy works automatically | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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); | ||
# FIXME: actually the "generic" ShallowCopy method is wrong, as it | ||
# e.g. doesn't reset IsZero etc -- if we want to keep this, we need | ||
# something like a helper to produce a "basic" typeobj for the | ||
# given basedomain. | ||
|
||
# 'ShallowCopy' MUST return a mutable object if such an object exists at all! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the comment about |
||
if not IsMutable(m) then | ||
SetFilterObj(res, IsMutable); | ||
fi; | ||
return res; | ||
end ); | ||
|
||
InstallMethod( PostMakeImmutable, [ IsPositionalMatrixRep ], | ||
function( m ) | ||
MakeImmutable( m![MAT_DATA_POS] ); | ||
end ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and IsCopyable
if we adopt the idea to make this explicit