Skip to content

Commit 0b590c3

Browse files
committed
Add IsPositionalVectorRep, IsPositionalMatrixRep
1 parent 5313cc4 commit 0b590c3

File tree

6 files changed

+147
-97
lines changed

6 files changed

+147
-97
lines changed

lib/matobj/positional.gd

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#############################################################################
2+
##
3+
## This file is part of GAP, a system for computational discrete algebra.
4+
##
5+
## SPDX-License-Identifier: GPL-2.0-or-later
6+
##
7+
## Copyright of GAP belongs to its developers, whose names are too numerous
8+
## to list here. Please refer to the COPYRIGHT file for details.
9+
##
10+
11+
# TODO: document this
12+
DeclareRepresentation( "IsPositionalVectorRep",
13+
IsVectorObj and IsPositionalObjectRep
14+
and IsNoImmediateMethodsObject
15+
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
16+
[] );
17+
18+
# TODO: document this
19+
DeclareRepresentation( "IsPositionalMatrixRep",
20+
IsMatrixObj and IsPositionalObjectRep
21+
and IsNoImmediateMethodsObject
22+
and HasNumberRows and HasNumberColumns
23+
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
24+
[] );
25+
26+
27+
#
28+
# Some constants for matrix resp. vector access
29+
#
30+
# TODO: For now the order follows the order of the predecessors:
31+
# BDPOS = 1, RLPOS = 3, ROWSPOS = 4; the goal is to
32+
# eventually change this. But this needs us to carefully revisit
33+
# all Objectify calls
34+
35+
# Position of the base domain
36+
BindConstant( "MAT_BD_POS", 1 );
37+
# Position of the number of rows
38+
BindConstant( "MAT_NROWS_POS", 5 ); # FIXME: in many cases superfluous (can be computed from NCOLS and DATA)
39+
# Position of the number of columns
40+
BindConstant( "MAT_NCOLS_POS", 3 ); #
41+
# Position of the data
42+
BindConstant( "MAT_DATA_POS", 4 );
43+
44+
# Position of the base domain
45+
BindConstant( "VEC_BD_POS", 1 );
46+
# Position of the data
47+
BindConstant( "VEC_DATA_POS", 2 );
48+
# Position of the length
49+
#BindConstant( "VEC_LENPOS", 3 ); # FIXME: not actually needed in general????

lib/matobj/positional.gi

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#############################################################################
2+
##
3+
## This file is part of GAP, a system for computational discrete algebra.
4+
##
5+
## SPDX-License-Identifier: GPL-2.0-or-later
6+
##
7+
## Copyright of GAP belongs to its developers, whose names are too numerous
8+
## to list here. Please refer to the COPYRIGHT file for details.
9+
##
10+
11+
############################################################################
12+
#
13+
# Operations for positional matrix objects
14+
#
15+
############################################################################
16+
17+
InstallMethod( BaseDomain, [ IsPositionalVectorRep ],
18+
function( v )
19+
return v![VEC_BD_POS];
20+
end );
21+
22+
InstallMethod( Length, [ IsPositionalVectorRep ],
23+
function( v )
24+
return Length(v![VEC_DATA_POS]); # FIXME: assumptions
25+
end );
26+
27+
28+
InstallMethod( ShallowCopy, [ IsPositionalVectorRep ],
29+
function( v )
30+
local i, res;
31+
res := List([1..LEN_POSOBJ(v)], i -> v![i]);
32+
res![VEC_DATA_POS] := ShallowCopy(v![VEC_DATA_POS]);
33+
res := Objectify(TypeObj(v), res);
34+
35+
# 'ShallowCopy' MUST return a mutable object if such an object exists at all!
36+
if not IsMutable(v) then
37+
SetFilterObj(res, IsMutable);
38+
fi;
39+
return res;
40+
end );
41+
42+
# StructuralCopy works automatically
43+
44+
InstallMethod( PostMakeImmutable, [ IsPositionalVectorRep ],
45+
function( v )
46+
MakeImmutable( v![VEC_DATA_POS] );
47+
end );
48+
49+
50+
############################################################################
51+
#
52+
# Operations for positional matrix objects
53+
#
54+
############################################################################
55+
56+
InstallMethod( BaseDomain, [ IsPositionalMatrixRep ],
57+
function( m )
58+
return m![MAT_BD_POS];
59+
end );
60+
61+
InstallMethod( NumberRows, [ IsPositionalMatrixRep ],
62+
function( m )
63+
return Length(m![MAT_DATA_POS]); # FIXME: this makes assumptions...
64+
end );
65+
66+
InstallMethod( NumberColumns, [ IsPositionalMatrixRep ],
67+
function( m )
68+
return m![MAT_NCOLS_POS];
69+
end );
70+
71+
InstallMethod( ShallowCopy, [ IsPositionalMatrixRep ],
72+
function( m )
73+
local res;
74+
res := List([1..LEN_POSOBJ(m)], i -> m![i]);
75+
res![MAT_DATA_POS] := ShallowCopy(m![MAT_DATA_POS]);
76+
res := Objectify(TypeObj(m), res);
77+
78+
# 'ShallowCopy' MUST return a mutable object if such an object exists at all!
79+
if not IsMutable(m) then
80+
SetFilterObj(res, IsMutable);
81+
fi;
82+
return res;
83+
end );
84+
85+
InstallMethod( PostMakeImmutable, [ IsPositionalMatrixRep ],
86+
function( m )
87+
MakeImmutable( m![MAT_DATA_POS] );
88+
end );

lib/matobjplist.gd

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
## <#/GAPDoc>
4646
##
4747
DeclareRepresentation( "IsPlistVectorRep",
48-
IsVectorObj and IsPositionalObjectRep
49-
and IsNoImmediateMethodsObject
50-
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
48+
IsPositionalVectorRep,
5149
[] );
5250

5351

@@ -86,22 +84,19 @@ DeclareRepresentation( "IsPlistVectorRep",
8684
## <#/GAPDoc>
8785
##
8886
DeclareRepresentation( "IsPlistMatrixRep",
89-
IsRowListMatrix and IsPositionalObjectRep
90-
and IsNoImmediateMethodsObject
91-
and HasNumberRows and HasNumberColumns
92-
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
87+
IsRowListMatrix and IsPositionalMatrixRep,
9388
[] );
9489

9590

9691
# Some constants for matrix access:
97-
BindGlobal( "BDPOS", 1 );
98-
BindGlobal( "EMPOS", 2 );
99-
BindGlobal( "RLPOS", 3 );
100-
BindGlobal( "ROWSPOS", 4 );
92+
BindGlobal( "BDPOS", 1 ); # base domain
93+
BindGlobal( "EMPOS", 2 ); # empty vector as template for new vectors
94+
BindGlobal( "RLPOS", 3 ); # row length = number of columns
95+
BindGlobal( "ROWSPOS", 4 ); # list of row vectors
10196

10297
# For vector access:
10398
#BindGlobal( "BDPOS", 1 ); # see above
104-
BindGlobal( "ELSPOS", 2 );
99+
BindGlobal( "ELSPOS", 2 ); # list of elements
105100

106101
# Two filters to speed up some methods:
107102
DeclareFilter( "IsIntVector" );

lib/matobjplist.gi

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,6 @@ InstallMethod( CompatibleVectorFilter, ["IsPlistMatrixRep"],
192192
############################################################################
193193

194194

195-
############################################################################
196-
# The basic attributes:
197-
############################################################################
198-
199-
InstallMethod( BaseDomain, "for a plist vector", [ IsPlistVectorRep ],
200-
function( v )
201-
return v![BDPOS];
202-
end );
203-
204-
InstallMethod( Length, "for a plist vector", [ IsPlistVectorRep ],
205-
function( v )
206-
return Length(v![ELSPOS]);
207-
end );
208-
209-
210195
############################################################################
211196
# Representation preserving constructors:
212197
############################################################################
@@ -225,6 +210,7 @@ InstallMethod( ZeroVector, "for an integer and a plist matrix",
225210
[ IsInt, IsPlistMatrixRep ],
226211
function( l, m )
227212
local v;
213+
# TODO: minimize number of places invoking `Objectify`
228214
v := Objectify(TypeObj(m![EMPOS]),
229215
[m![BDPOS],ListWithIdenticalEntries(l,Zero(m![BDPOS]))]);
230216
if not IsMutable(v) then SetFilterObj(v,IsMutable); fi;
@@ -323,26 +309,6 @@ InstallMethod( Unpack, "for a plist vector",
323309
end );
324310

325311

326-
############################################################################
327-
# Standard operations for all objects:
328-
############################################################################
329-
330-
InstallMethod( ShallowCopy, "for a plist vector", [ IsPlistVectorRep ],
331-
function( v )
332-
local res;
333-
res := Objectify(TypeObj(v),[v![BDPOS],ShallowCopy(v![ELSPOS])]);
334-
if not IsMutable(v) then SetFilterObj(res,IsMutable); fi;
335-
return res;
336-
end );
337-
338-
# StructuralCopy works automatically
339-
340-
InstallMethod( PostMakeImmutable, "for a plist vector", [ IsPlistVectorRep ],
341-
function( v )
342-
MakeImmutable( v![ELSPOS] );
343-
end );
344-
345-
346312
############################################################################
347313
# Arithmetical operations:
348314
############################################################################
@@ -562,36 +528,6 @@ InstallMethod( CopySubVector, "for two plist vectors and two lists",
562528
############################################################################
563529
############################################################################
564530

565-
566-
############################################################################
567-
# The basic attributes:
568-
############################################################################
569-
570-
InstallMethod( BaseDomain, "for a plist matrix",
571-
[ IsPlistMatrixRep ],
572-
function( m )
573-
return m![BDPOS];
574-
end );
575-
576-
InstallMethod( NumberRows, "for a plist matrix",
577-
[ IsPlistMatrixRep ],
578-
function( m )
579-
return Length(m![ROWSPOS]);
580-
end );
581-
582-
InstallMethod( NumberColumns, "for a plist matrix",
583-
[ IsPlistMatrixRep ],
584-
function( m )
585-
return m![RLPOS];
586-
end );
587-
588-
InstallMethod( DimensionsMat, "for a plist matrix",
589-
[ IsPlistMatrixRep ],
590-
function( m )
591-
return [Length(m![ROWSPOS]),m![RLPOS]];
592-
end );
593-
594-
595531
############################################################################
596532
# Representation preserving constructors:
597533
############################################################################
@@ -738,26 +674,6 @@ InstallMethod( Append, "for two plist matrices",
738674
Append(m![ROWSPOS],n![ROWSPOS]);
739675
end );
740676

741-
InstallMethod( ShallowCopy, "for a plist matrix",
742-
[ IsPlistMatrixRep ],
743-
function( m )
744-
local res;
745-
res := Objectify(TypeObj(m),[m![BDPOS],m![EMPOS],m![RLPOS],
746-
ShallowCopy(m![ROWSPOS])]);
747-
if not IsMutable(m) then
748-
SetFilterObj(res,IsMutable);
749-
fi;
750-
#T 'ShallowCopy' MUST return a mutable object
751-
#T if such an object exists at all!
752-
return res;
753-
end );
754-
755-
InstallMethod( PostMakeImmutable, "for a plist matrix",
756-
[ IsPlistMatrixRep ],
757-
function( m )
758-
MakeImmutable( m![ROWSPOS] );
759-
end );
760-
761677
InstallMethod( ListOp, "for a plist matrix",
762678
[ IsPlistMatrixRep ],
763679
function( m )

lib/read3.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ReadLib( "word.gd" );
105105
ReadLib( "wordass.gd" );
106106

107107
ReadLib( "matobj2.gd" );
108+
ReadLib( "matobj/positional.gd" );
108109
ReadLib( "matobjplist.gd" );
109110
ReadLib( "matobjnz.gd" );
110111

lib/read5.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ ReadLib( "matrobjrowlist.gi" );
112112
ReadLib( "vecmat.gi" );
113113
ReadLib( "vec8bit.gi" );
114114
ReadLib( "mat8bit.gi" );
115+
ReadLib( "matobj/positional.gi" );
115116
ReadLib( "matobjplist.gi" );
116117
ReadLib( "matobjnz.gi" );
117118
ReadLib( "meataxe.gi" );

0 commit comments

Comments
 (0)