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

Merge some MatrixObj work into master #2640

Merged
merged 16 commits into from
Aug 15, 2018
Merged
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
40 changes: 26 additions & 14 deletions doc/ref/matobj.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<!-- Copyright (C) 2011 The GAP Group -->
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->

<Chapter Label="Matrix objects">
<Heading>Vector and matrix objects</Heading>
<Chapter Label="Vector and Matrix Objects">
<Heading>Vector and Matrix Objects</Heading>

This chapter is work in progress. It will eventually describe the new
interface to vector and matrix objects.
Expand All @@ -20,34 +20,46 @@ To eventually solve
this problem, this chapter describes a new programming interface to
vectors and matrices.

<Section>
<Heading>Fundamental ideas and rules</Heading>
<Section Label="Fundamental Ideas and Rules">
<Heading>Fundamental Ideas and Rules</Heading>

<#Include Label="MatObj_Overview">

</Section>

<Section>
<Heading>Categories of vectors and matrices</Heading>
<Section Label="Categories of Vectors and Matrices">
<Heading>Categories of Vectors and Matrices</Heading>

</Section>

<Section>
<Heading>Constructing vector and matrix objects</Heading>
<Section Label="Constructing Vector and Matrix Objects">
<Heading>Constructing Vector and Matrix Objects</Heading>
</Section>

<Section>
<Heading>Operations for row vector objects</Heading>
<Section Label="Operations for Vector Objects">
<Heading>Operations for Vector Objects</Heading>

<#Include Label="MatObj_PositionNonZero">
<#Include Label="MatObj_PositionLastNonZero">
<#Include Label="MatObj_ListOp">
<#Include Label="MatObj_UnpackVector">
<#Include Label="MatObj_ConcatenationOfVectors">
<#Include Label="MatObj_ExtractSubVector">
<#Include Label="MatObj_ZeroVector">
<#Include Label="MatObj_ConstructingFilter_Vector">
<#Include Label="MatObj_Randomize_Vectors">
<#Include Label="MatObj_WeightOfVector">
<#Include Label="MatObj_DistanceOfVectors">

</Section>

<Section>
<Heading>Operations for row list matrix objects</Heading>
<Section Label="Operations for Row List Matrix Objects">
<Heading>Operations for Row List Matrix Objects</Heading>

</Section>

<Section>
<Heading>Operations for flat matrix objects</Heading>
<Section Label="Operations for Flat Matrix Objects">
<Heading>Operations for Flat Matrix Objects</Heading>

</Section>

Expand Down
2 changes: 1 addition & 1 deletion doc/ref/matrix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Matrices are represented in &GAP; by lists of row vectors
(see <Ref Chap="Row Vectors"/>) (for future changes to this
policy see Chapter <Ref Chap="Matrix objects"/>).
policy see Chapter <Ref Chap="Vector and Matrix Objects"/>).
The vectors must all have the same length, and their elements must lie in
a common ring. However, since checking rectangularness can be expensive
functions and methods of operations for matrices often will not give an error
Expand Down
33 changes: 4 additions & 29 deletions hpcgap/lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1844,18 +1844,6 @@ InstallMethod( Append, "for GF2 vectors",
IsGF2VectorRep and IsList], 0,
APPEND_GF2VEC);

#############################################################################
##
#M PositionCanonical( <list>, <obj> ) . . for GF2 matrices
##
InstallMethod( PositionCanonical,
"for internally represented lists, fall back on `Position'",
true, # the list may be non-homogeneous.
[ IsList and IsGF2MatrixRep, IsObject ], 0,
function( list, obj )
return Position( list, obj, 0 );
end );

#############################################################################
##
#M ShallowCopy( <vec> ) . . . for GF2 vectors
Expand Down Expand Up @@ -2311,9 +2299,8 @@ InstallMethod(DeterminantMatDestructive,
##


InstallMethod(RankMatDestructive,
InstallOtherMethod(RankMatDestructive,
"kernel method for plain list of GF2 vectors",
true,
[IsMatrix and IsPlistRep and IsFFECollColl and IsMutable],
GF2_AHEAD_OF_8BIT_RANK,
RANK_LIST_GF2VECS);
Expand Down Expand Up @@ -2422,27 +2409,15 @@ InstallMethod( Matrix, "for a list of vecs, an integer, and a gf2 mat",
ConvertToMatrixRep(li,2);
return li;
end );
BindGlobal( "PositionLastNonZeroFunc",

InstallMethod( PositionLastNonZero, "for a row vector obj",
[IsVectorObj],
function(l)
local i;
i := Length(l);
while i >= 1 and IsZero(l[i]) do i := i - 1; od;
return i;
end );
BindGlobal( "PositionLastNonZeroFunc2",
function(l,pos)
local i;
i := pos-1;
while i >= 1 and IsZero(l[i]) do i := i - 1; od;
return i;
end );

InstallMethod( PositionLastNonZero, "for a row vector obj",
[IsVectorObj], PositionLastNonZeroFunc );
InstallMethod( PositionLastNonZero, "for a matrix obj",
[IsMatrixObj], PositionLastNonZeroFunc );
InstallMethod( PositionLastNonZero, "for a matrix obj, and an index",
[IsMatrixObj, IsPosInt], PositionLastNonZeroFunc2 );

InstallMethod( ExtractSubMatrix, "for a gf2 matrix, and two lists",
[IsGF2MatrixRep, IsList, IsList],
Expand Down
14 changes: 6 additions & 8 deletions lib/algebra.gi
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,6 @@ InstallMethod( IsAnticommutative,
function( A )
local n, # dimension of `A'
T, # table of structure constants for `A'
zero, # zero coefficient
i, j; # loop over rows and columns ot `T'

if not IsFiniteDimensional( A ) then
Expand All @@ -939,12 +938,11 @@ InstallMethod( IsAnticommutative,

n:= Dimension( A );
T:= StructureConstantsTable( Basis( A ) );
zero:= T[ n+2 ];
for i in [ 2 .. n ] do
for j in [ 1 .. i-1 ] do
if T[i][j][1] <> T[j][i][1]
or ( not IsEmpty( T[i][j][1] )
and PositionNot( T[i][j][2] + T[j][i][2], zero )
and PositionNonZero( T[i][j][2] + T[j][i][2] )
<= Length( T[i][j][2] ) ) then
return false;
fi;
Expand Down Expand Up @@ -2974,23 +2972,23 @@ InstallMethod( IsNilpotentElement,
local B, # a basis of `L'
A, # adjoint matrix of `x w.r. to `B'
n, # dimension of `L'
i, # loop variable
zero; # zero coefficient
i; # loop variable

B := Basis( L );
A := AdjointMatrix( B, x );
n := Dimension( L );
i := 1;
zero:= Zero( A[1][1] );

if ForAll( A, x -> n < PositionNot( x, zero ) ) then
if ForAll( A, x -> n < PositionNonZero( x ) ) then
#T better ask IsZero?
return true;
fi;

while i < n do
i:= 2 * i;
A:= A * A;
if ForAll( A, x -> n < PositionNot( x, zero ) ) then
if ForAll( A, x -> n < PositionNonZero( x ) ) then
#T better ask IsZero?
return true;
fi;
od;
Expand Down
8 changes: 4 additions & 4 deletions lib/algsc.gi
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ InstallMethod( PrintObj,
return;
fi;

zero := Zero( elm[1] );
depth := PositionNot( elm, zero );
depth := PositionNonZero( elm );

if len < depth then

Expand All @@ -174,6 +173,7 @@ InstallMethod( PrintObj,
else

one:= One( elm[1] );
zero:= Zero( elm[1] );

if elm[ depth ] <> one then
Print( "(", elm[ depth ], ")*" );
Expand Down Expand Up @@ -221,8 +221,7 @@ InstallMethod( String,
return "<zero of trivial s.c. algebra>";
fi;

zero := Zero( elm[1] );
depth := PositionNot( elm, zero );
depth := PositionNonZero( elm );

s:="";
if len < depth then
Expand All @@ -235,6 +234,7 @@ InstallMethod( String,
else

one:= One( elm[1] );
zero:= Zero( elm[1] );

if elm[ depth ] <> one then
Add(s,'(');
Expand Down
6 changes: 4 additions & 2 deletions lib/ctblpope.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,8 @@ InstallGlobalFunction( PermCandidates,
# delete zero rows:
shrink:= [];
for i in matrix do
if PositionNot( i, 0 ) <= Length( i ) then
if PositionNonZero( i ) <= Length( i ) then
#T better call IsZero?
Add( shrink, i );
fi;
od;
Expand Down Expand Up @@ -2156,7 +2157,8 @@ InstallGlobalFunction( PermCandidatesFaithful,
# delete zero rows:
shrink:= [];
for i in matrix do
if PositionNot( i, 0 ) <= Length( i ) then
if PositionNonZero( i ) <= Length( i ) then
#T better call IsZero?
Add( shrink, i );
fi;
od;
Expand Down
18 changes: 7 additions & 11 deletions lib/liefam.gi
Original file line number Diff line number Diff line change
Expand Up @@ -368,28 +368,24 @@ InstallMethod( AdditiveInverseOp,
#M IsBound\[\]( <mat>, <i> )
#M Position( <mat>, <obj> )
##
InstallMethod( \[\],
InstallOtherMethod( \[\],
"for Lie matrix in default representation, and positive integer",
true,
[ IsLieMatrix and IsPackedElementDefaultRep, IsPosInt ], 0,
[ IsLieMatrix and IsPackedElementDefaultRep, IsPosInt ],
function( mat, i ) return mat![1][i]; end );

InstallMethod( Length,
InstallOtherMethod( Length,
"for Lie matrix in default representation",
true,
[ IsLieMatrix and IsPackedElementDefaultRep ], 0,
mat -> Length( mat![1] ) );
[ IsLieMatrix and IsPackedElementDefaultRep ],
mat -> NumberRows( mat![1] ) );

InstallMethod( IsBound\[\],
"for Lie matrix in default representation, and integer",
true,
[ IsLieMatrix and IsPackedElementDefaultRep, IsPosInt ], 0,
[ IsLieMatrix and IsPackedElementDefaultRep, IsPosInt ],
function( mat, i ) return IsBound( mat![1][i] ); end );

InstallMethod( Position,
"for Lie matrix in default representation, row vector, and integer",
true,
[ IsLieMatrix and IsPackedElementDefaultRep, IsRowVector, IsInt ], 0,
[ IsLieMatrix and IsPackedElementDefaultRep, IsRowVector, IsInt ],
function( mat, v, pos ) return Position( mat![1], v, pos ); end );


Expand Down
6 changes: 3 additions & 3 deletions lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ InstallMethod( PositionNot, "default method ", [IsList, IsObject, IsInt ],
InstallOtherMethod( PositionNot, "default value of third argument ",
[IsList, IsObject],
function(l,x)
return PositionNot(l,x,0);
return POSITION_NOT(l,x,0);
end
);

Expand All @@ -3816,7 +3816,7 @@ InstallMethod( PositionNonZero, "default method", [IsHomogeneousList],
if Length(l) = 0 then
return 1;
else
return PositionNot(l, Zero(l[1]));
return POSITION_NOT(l, Zero(l[1]), 0);
fi;
end);

Expand All @@ -3825,7 +3825,7 @@ InstallMethod( PositionNonZero, "default method with start", [IsHomogeneousList,
if Length(l) = 0 then
return from+1;
fi;
return PositionNot(l, Zero(l[1]), from);
return POSITION_NOT(l, Zero(l[1]), from);
end);


Expand Down
4 changes: 1 addition & 3 deletions lib/mat8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1050,11 +1050,9 @@ InstallMethod(DeterminantMatDestructive,
##


InstallMethod(RankMatDestructive,
InstallOtherMethod(RankMatDestructive,
"kernel method for plain list of GF2 vectors",
true,
[IsMatrix and IsPlistRep and IsFFECollColl and IsMutable],
0,
RANK_LIST_VEC8BITS);

InstallMethod(NestingDepthM, [Is8BitMatrixRep], m->2);
Expand Down
8 changes: 4 additions & 4 deletions lib/matblock.gi
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end );
##
#M Length( <blockmat> ) . . . . . . . . . . . . . . . . for a block matrix
##
InstallMethod( Length,
InstallOtherMethod( Length,
"for an ordinary block matrix",
[ IsOrdinaryMatrix and IsBlockMatrixRep ],
blockmat -> blockmat!.nrb * blockmat!.rpb );
Expand All @@ -142,7 +142,7 @@ InstallMethod( Length,
##
#M \[\]( <blockmat>, <n> ) . . . . . . . . . . . . . . . for a block matrix
##
InstallMethod( \[\],
InstallOtherMethod( \[\],
"for an ordinary block matrix and a positive integer",
[ IsOrdinaryMatrix and IsBlockMatrixRep, IsPosInt ],
function( blockmat, n )
Expand Down Expand Up @@ -195,7 +195,7 @@ InstallOtherMethod( \[\],
##
#M TransposedMat( <blockmat> ) . . . . . . . . . . . . . for a block matrix
##
InstallMethod( TransposedMat,
InstallOtherMethod( TransposedMat,
"for an ordinary block matrix",
[ IsOrdinaryMatrix and IsBlockMatrixRep ],
m -> BlockMatrix( List( m!.blocks, i -> [ i[2], i[1],
Expand Down Expand Up @@ -668,7 +668,7 @@ InstallMethod( PrintObj,
##
#M DimensionsMat( <blockmat> ) . . . . . . . . . . . . . for a block matrix
##
InstallMethod( DimensionsMat,
InstallOtherMethod( DimensionsMat,
"for an ordinary block matrix",
[ IsOrdinaryMatrix and IsBlockMatrixRep ],
m -> [ m!.nrb * m!.rpb, m!.ncb * m!.cpb ] );
Expand Down
Loading