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
+ list[ (rowindex- 1 )* nrcols + colindex] := list_in[ rowindex][ colindex] ;
33
+ od ;
34
+ od ;
35
+ else
36
+ if Length(list_in) mod nrcols <> 0 then
37
+ Error( " NewMatrix: Length of list must be a multiple of ncols." );
38
+ fi ;
39
+ list := list_in;
40
+ fi ;
41
+
42
+ obj := [ basedomain,Length(list)/ nrcols,nrcols,list] ;
43
+ filter2 := IsMinimalExampleMatrixRep and IsMutable;
44
+ if HasCanEasilyCompareElements(Representative(basedomain)) and
45
+ CanEasilyCompareElements(Representative(basedomain)) then
46
+ filter2 := filter2 and CanEasilyCompareElements;
47
+ fi ;
48
+ Objectify( NewType(CollectionsFamily(FamilyObj(basedomain)),
49
+ filter2), obj);
50
+ return obj;
51
+ end );
52
+
53
+ InstallMethod( BaseDomain, " for a minimal example matrix rep" ,
54
+ [ IsMinimalExampleMatrixRep ] ,
55
+ function ( m )
56
+ return m![ MINREP_BDPOS] ;
57
+ end );
58
+
59
+ InstallMethod( NumberRows, " for a minimal example matrix rep" ,
60
+ [ IsMinimalExampleMatrixRep ] ,
61
+ function ( m )
62
+ return m![ MINREP_NRPOS] ;
63
+ end );
64
+
65
+ InstallMethod( NumberColumns, " for a minimal example matrix rep" ,
66
+ [ IsMinimalExampleMatrixRep ] ,
67
+ function ( m )
68
+ return m![ MINREP_NCPOS] ;
69
+ end );
70
+
71
+ InstallMethod( MatElm, " for an minimal example matrix rep and two positions" ,
72
+ [ IsMinimalExampleMatrixRep, IsPosInt, IsPosInt ] ,
73
+ function ( mat, row, col )
74
+ return mat![ MINREP_ELSPOS][ (row- 1 )* mat![ MINREP_NCPOS] + col] ;
75
+ end );
76
+
77
+ InstallMethod( SetMatElm, " for an minimal example matrix rep, two positions, and an object" ,
78
+ [ IsMinimalExampleMatrixRep and IsMutable, IsPosInt, IsPosInt, IsObject ] ,
79
+ function ( mat, row, col, obj )
80
+ mat![ MINREP_ELSPOS][ (row- 1 )* mat![ MINREP_NCPOS] + col] := obj;
81
+ end );
82
+
83
+ InstallMethod( \< , " for two minimal example matrices" ,
84
+ [ IsMinimalExampleMatrixRep, IsMinimalExampleMatrixRep ] ,
85
+ function ( a, b )
86
+ return LT_LIST_LIST_DEFAULT(a![ MINREP_ELSPOS] ,b![ MINREP_ELSPOS] );
87
+ end );
88
+
89
+ InstallMethod( ConstructingFilter, " for a minimal example matrix rep" ,
90
+ [ IsMinimalExampleMatrixRep ] ,
91
+ function ( mat )
92
+ return IsMinimalExampleMatrixRep;
93
+ end );
94
+
95
+ InstallMethod( CompatibleVectorFilter, [ IsMinimalExampleMatrixRep ] ,
96
+ M -> IsPlistVectorRep );
0 commit comments