Skip to content

Commit

Permalink
Add IsPositionalVectorRep, IsPositionalMatrixRep
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Dec 15, 2022
1 parent 5313cc4 commit 0b590c3
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 97 deletions.
49 changes: 49 additions & 0 deletions lib/matobj/positional.gd
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????
88 changes: 88 additions & 0 deletions lib/matobj/positional.gi
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 );
19 changes: 7 additions & 12 deletions lib/matobjplist.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
## <#/GAPDoc>
##
DeclareRepresentation( "IsPlistVectorRep",
IsVectorObj and IsPositionalObjectRep
and IsNoImmediateMethodsObject
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
IsPositionalVectorRep,
[] );


Expand Down Expand Up @@ -86,22 +84,19 @@ DeclareRepresentation( "IsPlistVectorRep",
## <#/GAPDoc>
##
DeclareRepresentation( "IsPlistMatrixRep",
IsRowListMatrix and IsPositionalObjectRep
and IsNoImmediateMethodsObject
and HasNumberRows and HasNumberColumns
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
IsRowListMatrix and IsPositionalMatrixRep,
[] );


# Some constants for matrix access:
BindGlobal( "BDPOS", 1 );
BindGlobal( "EMPOS", 2 );
BindGlobal( "RLPOS", 3 );
BindGlobal( "ROWSPOS", 4 );
BindGlobal( "BDPOS", 1 ); # base domain
BindGlobal( "EMPOS", 2 ); # empty vector as template for new vectors
BindGlobal( "RLPOS", 3 ); # row length = number of columns
BindGlobal( "ROWSPOS", 4 ); # list of row vectors

# For vector access:
#BindGlobal( "BDPOS", 1 ); # see above
BindGlobal( "ELSPOS", 2 );
BindGlobal( "ELSPOS", 2 ); # list of elements

# Two filters to speed up some methods:
DeclareFilter( "IsIntVector" );
Expand Down
86 changes: 1 addition & 85 deletions lib/matobjplist.gi
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,6 @@ InstallMethod( CompatibleVectorFilter, ["IsPlistMatrixRep"],
############################################################################


############################################################################
# The basic attributes:
############################################################################

InstallMethod( BaseDomain, "for a plist vector", [ IsPlistVectorRep ],
function( v )
return v![BDPOS];
end );

InstallMethod( Length, "for a plist vector", [ IsPlistVectorRep ],
function( v )
return Length(v![ELSPOS]);
end );


############################################################################
# Representation preserving constructors:
############################################################################
Expand All @@ -225,6 +210,7 @@ InstallMethod( ZeroVector, "for an integer and a plist matrix",
[ IsInt, IsPlistMatrixRep ],
function( l, m )
local v;
# TODO: minimize number of places invoking `Objectify`
v := Objectify(TypeObj(m![EMPOS]),
[m![BDPOS],ListWithIdenticalEntries(l,Zero(m![BDPOS]))]);
if not IsMutable(v) then SetFilterObj(v,IsMutable); fi;
Expand Down Expand Up @@ -323,26 +309,6 @@ InstallMethod( Unpack, "for a plist vector",
end );


############################################################################
# Standard operations for all objects:
############################################################################

InstallMethod( ShallowCopy, "for a plist vector", [ IsPlistVectorRep ],
function( v )
local res;
res := Objectify(TypeObj(v),[v![BDPOS],ShallowCopy(v![ELSPOS])]);
if not IsMutable(v) then SetFilterObj(res,IsMutable); fi;
return res;
end );

# StructuralCopy works automatically

InstallMethod( PostMakeImmutable, "for a plist vector", [ IsPlistVectorRep ],
function( v )
MakeImmutable( v![ELSPOS] );
end );


############################################################################
# Arithmetical operations:
############################################################################
Expand Down Expand Up @@ -562,36 +528,6 @@ InstallMethod( CopySubVector, "for two plist vectors and two lists",
############################################################################
############################################################################


############################################################################
# The basic attributes:
############################################################################

InstallMethod( BaseDomain, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
return m![BDPOS];
end );

InstallMethod( NumberRows, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
return Length(m![ROWSPOS]);
end );

InstallMethod( NumberColumns, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
return m![RLPOS];
end );

InstallMethod( DimensionsMat, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
return [Length(m![ROWSPOS]),m![RLPOS]];
end );


############################################################################
# Representation preserving constructors:
############################################################################
Expand Down Expand Up @@ -738,26 +674,6 @@ InstallMethod( Append, "for two plist matrices",
Append(m![ROWSPOS],n![ROWSPOS]);
end );

InstallMethod( ShallowCopy, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
local res;
res := Objectify(TypeObj(m),[m![BDPOS],m![EMPOS],m![RLPOS],
ShallowCopy(m![ROWSPOS])]);
if not IsMutable(m) then
SetFilterObj(res,IsMutable);
fi;
#T 'ShallowCopy' MUST return a mutable object
#T if such an object exists at all!
return res;
end );

InstallMethod( PostMakeImmutable, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
MakeImmutable( m![ROWSPOS] );
end );

InstallMethod( ListOp, "for a plist matrix",
[ IsPlistMatrixRep ],
function( m )
Expand Down
1 change: 1 addition & 0 deletions lib/read3.g
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ReadLib( "word.gd" );
ReadLib( "wordass.gd" );

ReadLib( "matobj2.gd" );
ReadLib( "matobj/positional.gd" );
ReadLib( "matobjplist.gd" );
ReadLib( "matobjnz.gd" );

Expand Down
1 change: 1 addition & 0 deletions lib/read5.g
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ ReadLib( "matrobjrowlist.gi" );
ReadLib( "vecmat.gi" );
ReadLib( "vec8bit.gi" );
ReadLib( "mat8bit.gi" );
ReadLib( "matobj/positional.gi" );
ReadLib( "matobjplist.gi" );
ReadLib( "matobjnz.gi" );
ReadLib( "meataxe.gi" );
Expand Down

0 comments on commit 0b590c3

Please sign in to comment.