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
+ # This file is a minimal implementation for new style vectors and matrices.
14
+ # It stores matrices as a dense flat list.
15
+ # This implementation implements only the methods required by the specification
16
+ # for matrix objects. This is intended for testing.
17
+
18
+ InstallMethod( NewMatrix,
19
+ " for IsMinimalExampleMatrixRep, a ring, an int, and a list" ,
20
+ [ IsMinimalExampleMatrixRep, IsRing, IsInt, IsList ] ,
21
+ function ( filter, basedomain, nrcols, list_in )
22
+ local obj, filter2, list, rowindex, colindex;
23
+
24
+ # If applicable then replace a nested list 'list_in' by a flat list 'list'.
25
+ if Length(list_in) > 0 and (IsVectorObj(list_in[ 1 ] ) or IsList(list_in[ 1 ] )) then
26
+ list := [] ;
27
+ for rowindex in [ 1 .. Length(list_in)] do
28
+ if Length(list_in[ rowindex] ) <> nrcols then
29
+ Error( " NewMatrix: Each row must have nrcols entries." );
30
+ fi ;
31
+ for colindex in [ 1 .. nrcols] do
32
+ Assert (2 , list_in[ rowindex][ colindex] in basedomain);
33
+ list[ (rowindex- 1 )* nrcols + colindex] := list_in[ rowindex][ colindex] ;
34
+ od ;
35
+ od ;
36
+ else
37
+ if Length(list_in) mod nrcols <> 0 then
38
+ Error( " NewMatrix: Length of list must be a multiple of ncols." );
39
+ fi ;
40
+ list := list_in;
41
+ fi ;
42
+
43
+ obj := [ basedomain,Length(list)/ nrcols,nrcols,list] ;
44
+ filter2 := IsMinimalExampleMatrixRep and IsMutable;
45
+ if HasCanEasilyCompareElements(Representative(basedomain)) and
46
+ CanEasilyCompareElements(Representative(basedomain)) then
47
+ filter2 := filter2 and CanEasilyCompareElements;
48
+ fi ;
49
+ Objectify( NewType(CollectionsFamily(FamilyObj(basedomain)),
50
+ filter2), obj);
51
+ return obj;
52
+ end );
53
+
54
+ InstallMethod( BaseDomain, " for a minimal example matrix rep" ,
55
+ [ IsMinimalExampleMatrixRep ] ,
56
+ function ( m )
57
+ return m![ MINREP_BDPOS] ;
58
+ end );
59
+
60
+ InstallMethod( NumberRows, " for a minimal example matrix rep" ,
61
+ [ IsMinimalExampleMatrixRep ] ,
62
+ function ( m )
63
+ return m![ MINREP_NRPOS] ;
64
+ end );
65
+
66
+ InstallMethod( NumberColumns, " for a minimal example matrix rep" ,
67
+ [ IsMinimalExampleMatrixRep ] ,
68
+ function ( m )
69
+ return m![ MINREP_NCPOS] ;
70
+ end );
71
+
72
+ InstallMethod( MatElm, " for an minimal example matrix rep and two positions" ,
73
+ [ IsMinimalExampleMatrixRep, IsPosInt, IsPosInt ] ,
74
+ function ( mat, row, col )
75
+ Assert (2 , 1 <= row and row <= mat![ MINREP_NRPOS] );
76
+ Assert (2 , 1 <= col and col <= mat![ MINREP_NCPOS] );
77
+ return mat![ MINREP_ELSPOS][ (row- 1 )* mat![ MINREP_NCPOS] + col] ;
78
+ end );
79
+
80
+ InstallMethod( SetMatElm, " for an minimal example matrix rep, two positions, and an object" ,
81
+ [ IsMinimalExampleMatrixRep and IsMutable, IsPosInt, IsPosInt, IsObject ] ,
82
+ function ( mat, row, col, obj )
83
+ Assert (2 , 1 <= row and row <= mat![ MINREP_NRPOS] );
84
+ Assert (2 , 1 <= col and col <= mat![ MINREP_NCPOS] );
85
+ Assert (2 , obj in mat![ MINREP_BDPOS] );
86
+ mat![ MINREP_ELSPOS][ (row- 1 )* mat![ MINREP_NCPOS] + col] := obj;
87
+ end );
88
+
89
+ InstallMethod( \< , " for two minimal example matrices" ,
90
+ [ IsMinimalExampleMatrixRep, IsMinimalExampleMatrixRep ] ,
91
+ function ( a, b )
92
+ return LT_LIST_LIST_DEFAULT(a![ MINREP_ELSPOS] ,b![ MINREP_ELSPOS] );
93
+ end );
94
+
95
+ InstallMethod( ConstructingFilter, " for a minimal example matrix rep" ,
96
+ [ IsMinimalExampleMatrixRep ] ,
97
+ function ( mat )
98
+ return IsMinimalExampleMatrixRep;
99
+ end );
100
+
101
+ InstallMethod( CompatibleVectorFilter, [ IsMinimalExampleMatrixRep ] ,
102
+ M -> IsPlistVectorRep );
103
+
0 commit comments