Skip to content

Commit

Permalink
Use internal PLAIN_LIST_COPY to implement PlainListCopy, and document
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Mar 24, 2021
1 parent 91fd3e5 commit 3ee9a09
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 171 deletions.
1 change: 1 addition & 0 deletions doc/ref/lists.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ for example when one installs a method for a particular operation,
where an argument is required to be a list in a particular representation.

<#Include Label="IsPlistRep">
<#Include Label="PlainListCopy">

</Section>
</Chapter>
Expand Down
13 changes: 0 additions & 13 deletions hpcgap/lib/vec8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,6 @@ InstallMethod( \+, "for an 8 bit vector of char 2 and a GF2 vector",
fi;
end);

#############################################################################
##
#M `PlainListCopyOp( <vec> )
##
## Make the vector into a plain list (in place)
##

InstallMethod( PlainListCopyOp, "for an 8 bit vector",
true, [IsSmallList and Is8BitVectorRep], 0,
function (v)
PLAIN_VEC8BIT(v);
return v;
end);

#############################################################################
##
Expand Down
26 changes: 0 additions & 26 deletions hpcgap/lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1767,32 +1767,6 @@ function(f,v)
return Immutable(v);
end);


#############################################################################
##
#M PlainListCopyOp( <v> )
##

InstallMethod( PlainListCopyOp, "for a GF2 vector",
true, [IsGF2VectorRep and IsSmallList ],
0, function( v )
PLAIN_GF2VEC(v);
return v;
end);

#############################################################################
##
#M PlainListCopyOp( <m> )
##

InstallMethod( PlainListCopyOp, "for a GF2 matrix",
true, [IsSmallList and IsGF2MatrixRep ],
0, function( m )
PLAIN_GF2MAT(m);
return m;
end);


#############################################################################
##
#M MultVector( <vl>, <mul>)
Expand Down
26 changes: 5 additions & 21 deletions lib/list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2376,35 +2376,19 @@ DeclareGlobalFunction( "ListWithIdenticalEntries" );
##
#F PlainListCopy( <list> ) . . . . . . . . make a plain list copy of a list
##
## <#GAPDoc Label="PlainListCopy">
## <ManSection>
## <Func Name="PlainListCopy" Arg='list'/>
##
## <Description>
## This function returns a list equal to its argument, in a plain list
## representation (see <Ref Filt="IsPlistRep"/>).
## This is intended for use in certain rare situations,
## such as before objectifying.
## Normally, <C>ConstantAccessTimeList</C> should be enough.
## </Description>
## </ManSection>
##
DeclareGlobalFunction("PlainListCopy");


#############################################################################
##
#O PlainListCopyOp( <list> ) . . . . . . . .return a plain version of a list
##
## <ManSection>
## <Oper Name="PlainListCopyOp" Arg='list'/>
##
## <Description>
## This operation returns a list equal to its argument, in a plain list
## representation. This may be the argument converted in place, or
## may be new. It is only intended to be called by <C>PlainListCopy</C>.
## such as before objectifying, or calling some kernel functions.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation("PlainListCopyOp", [IsSmallList]);


#############################################################################
##
Expand Down
33 changes: 0 additions & 33 deletions lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3890,39 +3890,6 @@ InstallMethod( ViewObj,
Print( " ]" );
end );


#############################################################################
##
#F PlainListCopy( <list> ) . . . . . . . . . . make a plain list copy of
## a list
##
## This is intended for use in certain rare situations, such as before
## Objectifying. Normally, ConstantAccessTimeList should be enough
##
## This function guarantees that the result will be a plain list, distinct
## from the input object.
##
InstallGlobalFunction(PlainListCopy, function( list )
local tnum, copy;

if not IsSmallList( list ) then
Error("PlainListCopy: argument must be a small list");
fi;

# This is enough much of the time
copy := ShallowCopy(list);

# now do a cheap check on copy
tnum := TNUM_OBJ(copy);
if FIRST_LIST_TNUM > tnum or LAST_LIST_TNUM < tnum then
copy := PlainListCopyOp( copy );
fi;
Assert(2, not IsIdenticalObj(list,copy));
Assert(2, TNUM_OBJ(copy) >= FIRST_LIST_TNUM);
Assert(2, TNUM_OBJ(copy) <= LAST_LIST_TNUM);
return copy;
end);

#############################################################################
##
#M PositionNot( <list>, <obj>, <from-minus-one> ) . . . . . . default method
Expand Down
15 changes: 0 additions & 15 deletions lib/mat8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,6 @@ InstallMethod( \-, "for two 8 bit matrices in same characteristic",
);


#############################################################################
##
#M `PlainListCopyOp( <mat> )
##
## Make the matrix into a plain list
##

InstallMethod( PlainListCopyOp, "for an 8 bit vector",
true, [IsSmallList and Is8BitMatrixRep], 0,
function (m)
PLAIN_MAT8BIT(m);
return m;
end);


#############################################################################
##
#M ConvertToMatrixRepNC( <list>, <fieldsize )
Expand Down
24 changes: 0 additions & 24 deletions lib/sparselistgen.gi
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,6 @@ InstallMethod(ViewObj, "sparse lists", [IsSparseList and IsDenseList],
Print(" >>");
end);

#############################################################################
##
#M PlainListCopyOp( <sl> ) make a copy which will really be a plain list
##

InstallMethod(PlainListCopyOp, "sparse list", [IsSparseList and IsSmallList],
function(sl)
local l, i, ss;
ss := SparseStructureOfList(sl);
if IsBound(ss[1]) then
l := ListWithIdenticalEntries(Length(sl), ss[1]);
else
l := [];
fi;
for i in [1..Length(ss[2])] do
if IsBound(ss[3][i]) then
l[ss[2][i]] := ss[3][i];
else
Unbind(l[ss[2][i]]);
fi;
od;
return l;
end);

#############################################################################
##
#F PLAIN_SL ( <sl> ) convert a sparse list in place to a plain list
Expand Down
14 changes: 0 additions & 14 deletions lib/vec8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,6 @@ InstallMethod( \+, "for an 8 bit vector of char 2 and a GF2 vector",
fi;
end);

#############################################################################
##
#M `PlainListCopyOp( <vec> )
##
## Make the vector into a plain list (in place)
##

InstallMethod( PlainListCopyOp, "for an 8 bit vector",
true, [IsSmallList and Is8BitVectorRep], 0,
function (v)
PLAIN_VEC8BIT(v);
return v;
end);

#############################################################################
##
#M DegreeFFE( <vector> )
Expand Down
25 changes: 0 additions & 25 deletions lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1579,31 +1579,6 @@ function(f,v)
end);


#############################################################################
##
#M PlainListCopyOp( <v> )
##

InstallMethod( PlainListCopyOp, "for a GF2 vector",
true, [IsGF2VectorRep and IsSmallList ],
0, function( v )
PLAIN_GF2VEC(v);
return v;
end);

#############################################################################
##
#M PlainListCopyOp( <m> )
##

InstallMethod( PlainListCopyOp, "for a GF2 matrix",
true, [IsSmallList and IsGF2MatrixRep ],
0, function( m )
PLAIN_GF2MAT(m);
return m;
end);


#############################################################################
##
#M MultVector( <vl>, <mul>)
Expand Down
7 changes: 7 additions & 0 deletions src/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,12 @@ Obj PLAIN_LIST_COPY(Obj list)
return res;
}

Obj FuncPlainListCopy(Obj self, Obj list)
{
RequireSmallList(SELF_NAME, list);
return PLAIN_LIST_COPY(list);
}


/****************************************************************************
**
Expand Down Expand Up @@ -1856,6 +1862,7 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC_1ARGS(IS_SSORT_LIST_DEFAULT, list),
GVAR_FUNC_1ARGS(IS_POSS_LIST_DEFAULT, list),
GVAR_FUNC_3ARGS(POS_LIST_DEFAULT, list, obj, start),
GVAR_FUNC_1ARGS(PlainListCopy, list),
{ 0, 0, 0, 0, 0 }

};
Expand Down
33 changes: 33 additions & 0 deletions tst/testinstall/list.tst
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,39 @@ gap> l;
gap> TNAM_OBJ(l);
"plain list (rectangular table)"

# Check PlainListCopy
gap> checkPlainListCopy := function(l)
> local copy, tnum;
> tnum := TNUM_OBJ(l);
> copy := PlainListCopy(l);
> return IsPlistRep(copy) and l = copy and
> not IsIdenticalObj(l,copy) and TNUM_OBJ(l) = tnum;
> end;;
gap> checkPlainListCopy([]);
true
gap> checkPlainListCopy([1, ,()]);
true
gap> checkPlainListCopy([1..5]);
true
gap> checkPlainListCopy([10,8..-4]);
true
gap> checkPlainListCopy("");
true
gap> checkPlainListCopy("abc");
true
gap> checkPlainListCopy(ListWithIdenticalEntries(3, false));
true
gap> checkPlainListCopy(NewZeroVector(IsGF2VectorRep, GF(2), 10));
true
gap> checkPlainListCopy(NewZeroVector(Is8BitVectorRep, GF(3), 10));
true
gap> PlainListCopy(6);
Error, PlainListCopy: <list> must be a small list (not the integer 6)
gap> PlainListCopy((1,2,3));
Error, PlainListCopy: <list> must be a small list (not a permutation (small))
gap> PlainListCopy(Group((1,2)));
Error, PlainListCopy: <list> must be a small list (not a component object)

# Check TNUM behaviours
gap> x := [1,,"cheese"];;
gap> x[2] := 2;;
Expand Down

0 comments on commit 3ee9a09

Please sign in to comment.