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

WIP: positional matrix obj rep #5217

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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
Copy link
Contributor

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

and IsNoImmediateMethodsObject
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
[] );

# TODO: document this
DeclareRepresentation( "IsPositionalMatrixRep",
IsMatrixObj and IsPositionalObjectRep
Copy link
Contributor

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

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????
97 changes: 97 additions & 0 deletions lib/matobj/positional.gi
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!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My interpretation of ShallowCopy is that it returns its argument if this is not copyable.
We could restrict the method installation to IsPositionalVectorRep and IsCopyable.
And perhaps we should add an explicit reference to IsCopyable to the documentation of ShallowCopy.

if not IsMutable(v) then
SetFilterObj(res, IsMutable);
fi;
return res;
end );

# StructuralCopy works automatically
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StructuralCopy is not an operation, so we cannot do anything for it here.


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!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the comment about ShallowCopy for IsPositionalVectorRep

if not IsMutable(m) then
SetFilterObj(res, IsMutable);
fi;
return res;
end );

InstallMethod( PostMakeImmutable, [ IsPositionalMatrixRep ],
function( m )
MakeImmutable( m![MAT_DATA_POS] );
end );
21 changes: 7 additions & 14 deletions lib/matobjplist.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
## </Enum>
##
DeclareRepresentation( "IsPlistVectorRep",
IsVectorObj and IsPositionalObjectRep
and IsCopyable
and IsNoImmediateMethodsObject
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
IsPositionalVectorRep and IsCopyable,
[] );


Expand Down Expand Up @@ -94,23 +91,19 @@ DeclareRepresentation( "IsPlistVectorRep",
## </Enum>
##
DeclareRepresentation( "IsPlistMatrixRep",
IsRowListMatrix and IsPositionalObjectRep
and IsCopyable
and IsNoImmediateMethodsObject
and HasNumberRows and HasNumberColumns
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
IsRowListMatrix and IsPositionalMatrixRep and IsCopyable,
[] );


# 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
82 changes: 0 additions & 82 deletions lib/matobjplist.gi
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,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 Down Expand Up @@ -340,23 +325,6 @@ InstallMethod( Unpack, "for a plist vector",
end );


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

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

# StructuralCopy works automatically

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


############################################################################
# Arithmetical operations:
############################################################################
Expand Down Expand Up @@ -545,36 +513,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 @@ -721,26 +659,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