Skip to content

Commit dbc9466

Browse files
committed
MatrixObj: Doc, Code and Tests for MultRowVector
- Split MultRowVector to MultRowVectorLeft / MultRowVectorRight. The reason being that MultRowVector( v, s ) is already defined and performs s * v. - MultRowVectorLeft is declared a synonym for MultRowVector. - MultRowVectorOp is renamed to MultRowVectorLeftOp on the C level. - Add four argument declarations for MultRowVectorLeft( vec, mul, from, to ) and ..Right - Remove the five argument version of MultRowVector in MatrixObj. Deprecate it also in the library. This version was not used anywhere in the library or packages - Use IsMultElement instead of IsObject as a filter for operations doing multiplication with scalars - Add generic and plist implementations of MultRowVector where necessary - Implement and declare ..Left and ..Right versions in matrixobj* - Only do the ..Left version in listcoef.g?. The methods from listcoef.gi are only used for integers and FFEs in the library. Adding the ..Right versions would only introduce lots of unused code. People wanting to use the ..Right versions should use vector objs. - Have a kernel function MULT_ROW_VECTOR_LEFT_RIGHT_2 which is called by MULT_ROW_VECTOR_LEFT_2 and ..RIGHT_2 - Tests for MultRowVector
1 parent a50c701 commit dbc9466

10 files changed

Lines changed: 269 additions & 139 deletions

File tree

lib/listcoef.gd

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,28 @@ DeclareOperation(
9797

9898
#############################################################################
9999
##
100-
#O MultRowVector( <list1>, <poss1>, <list2>, <poss2>, <mul> )
101-
#O MultRowVector( <list>, <mul> )
100+
#O MultRowVectorLeft( <list>, <mul> )
102101
##
103-
## <#GAPDoc Label="MultRowVector">
102+
## <#GAPDoc Label="MultRowVectorLeft">
104103
## <ManSection>
105-
## <Oper Name="MultRowVector" Arg='list1, [poss1, list2, poss2, ]mul'/>
104+
## <Oper Name="MultRowVector" Arg='list1, mul'/>
105+
## <Oper Name="MultRowVectorLeft" Arg='list1, mul'/>
106+
## <Returns>nothing</Returns>
106107
##
107108
## <Description>
108-
## The five argument version of this operation replaces
109-
## <A>list1</A><C>[</C><A>poss1</A><C>[</C><M>i</M><C>]]</C> by
110-
## <C><A>mul</A>*<A>list2</A>[<A>poss2</A>[</C><M>i</M><C>]]</C> for <M>i</M>
111-
## between <M>1</M> and <C>Length( <A>poss1</A> )</C>.
109+
## This operation calculates <A>mul</A>*<A>list1</A> in-place.
112110
## <P/>
113-
## The two-argument version simply multiplies each element of <A>list1</A>,
114-
## in-place, by <A>mul</A>.
111+
## Note that <C>MultRowVector</C> is just a synonym for
112+
## <C>MultRowVectorLeft</C>.
115113
## </Description>
116114
## </ManSection>
117115
## <#/GAPDoc>
118116
##
119117
DeclareOperation(
120-
"MultRowVector",
121-
[ IsMutable and IsList,
122-
IsList, IsList, IsList, IsMultiplicativeElement ] );
123-
118+
"MultRowVectorLeft",
119+
[ IsMutable and IsList,
120+
IsMultiplicativeElement ] );
121+
DeclareSynonym( "MultRowVector", MultRowVectorLeft );
124122

125123
#############################################################################
126124
##

lib/listcoef.gi

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -262,73 +262,50 @@ end );
262262

263263
#############################################################################
264264
##
265-
#M MultRowVector( <list1>, <poss1>, <list2>, <poss2>, <mult> )
265+
#M MultRowVectorLeft( <list>, <mul> )
266266
##
267-
InstallMethod( MultRowVector,"generic method",
267+
InstallMethod( MultRowVectorLeft,
268+
"for a mutable dense list, and a multiplicative element",
268269
true,
269270
[ IsDenseList and IsMutable,
270-
IsDenseList,
271-
IsDenseList,
272-
IsDenseList,
273271
IsMultiplicativeElement ],
274272
0,
275-
276-
function( l1, p1, l2, p2, m )
277-
l1{p1} := m * l2{p2};
278-
end );
279-
280-
InstallOtherMethod( MultRowVector,"error if immutable",true,
281-
[ IsList,IsObject,IsObject,IsObject,IsObject],0,
282-
L1_IMMUTABLE_ERROR);
283-
284-
#############################################################################
285-
##
286-
#M MultRowVector( <list>, <mul> )
287-
##
288-
InstallOtherMethod( MultRowVector,
289-
"two argument generic method",
290-
true,
291-
[ IsDenseList and IsMutable,
292-
IsMultiplicativeElement ],
293-
0,
294-
295273
function( l, m )
296274
local i;
297-
298275
for i in [ 1 .. Length(l) ] do
299276
l[i] := m * l[i];
300277
od;
301278
end );
302-
303-
InstallOtherMethod( MultRowVector,"error if immutable",true,
304-
[ IsList,IsObject],0,
279+
InstallOtherMethod( MultRowVectorLeft, "error if immutable", true,
280+
[ IsList, IsMultiplicativeElement ],
281+
0,
305282
L1_IMMUTABLE_ERROR);
306283

307-
InstallOtherMethod( MultRowVector,
308-
"Two argument kernel method for small list",
284+
InstallMethod( MultRowVectorLeft,
285+
"kernel method for a mutable dense small list, and a \
286+
multiplicative element",
309287
IsCollsElms,
310288
[ IsSmallList and IsDenseList and IsMutable,
311289
IsMultiplicativeElement ],
312290
0,
313-
MULT_ROW_VECTOR_2
291+
MULT_ROW_VECTOR_LEFT_2
314292
);
315-
316-
InstallOtherMethod( MultRowVector,
317-
"Two argument kernel method for plain list of cyclotomics and an integer",
293+
InstallMethod( MultRowVector,
294+
"kernel method for a mutable dense plain list of \
295+
cyclotomics, and a cyclotomic",
318296
IsCollsElms,
319-
[ IsSmallList and IsDenseList and IsMutable and IsPlistRep and
320-
IsCyclotomicCollection,
297+
[ IsDenseList and IsMutable and IsPlistRep and IsCyclotomicCollection,
321298
IsCyclotomic ],
322299
0,
323-
MULT_ROW_VECTOR_2_FAST
300+
MULT_ROW_VECTOR_2_FAST
324301
);
325-
326-
InstallOtherMethod( MultRowVector,
327-
"kernel method for vecffe (2 args)",
328-
IsCollsElms,
329-
[ IsRowVector and IsMutable and IsPlistRep and IsFFECollection,
330-
IsFFE],0,
331-
MULT_ROWVECTOR_VECFFES );
302+
InstallMethod( MultRowVector,
303+
"kernel method for a mutable row vector of ffes in \
304+
plain list rep, and an ffe",
305+
IsCollsElms,
306+
[ IsRowVector and IsMutable and IsPlistRep and IsFFECollection,
307+
IsFFE],0,
308+
MULT_ROWVECTOR_VECFFES );
332309

333310

334311
#############################################################################

lib/matobj.gi

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,51 @@ InstallMethod( Randomize,
568568
od;
569569
end );
570570

571+
############################################################################
572+
# Arithmetical operations:
573+
############################################################################
574+
InstallMethod( MultRowVectorLeft,
575+
"generic method for a mutable vector, and a multiplicative element",
576+
[ IsVectorObj and IsMutable, IsMultiplicativeElement ],
577+
function( v, s )
578+
local i;
579+
for i in [1 .. Length(v)] do
580+
v[i] := s * v[i];
581+
od;
582+
end );
583+
584+
InstallMethod( MultRowVectorRight,
585+
"generic method for a mutable vector, and a multiplicative element",
586+
[ IsVectorObj and IsMutable, IsMultiplicativeElement ],
587+
function( v, s )
588+
local i;
589+
for i in [1 .. Length(v)] do
590+
v[i] := v[i] * s;
591+
od;
592+
end );
593+
594+
InstallMethod( MultRowVectorLeft,
595+
"generic method for a mutable vector, a multiplicative element, an int, \
596+
and an int",
597+
[ IsVectorObj and IsMutable, IsMultiplicativeElement, IsInt, IsInt ],
598+
function( v, s, from, to )
599+
local i;
600+
for i in [from .. to] do
601+
v[i] := s * v[i];
602+
od;
603+
end );
604+
605+
InstallMethod( MultRowVectorRight,
606+
"generic method for a mutable vector, a multiplicative element, an int, \
607+
and an int",
608+
[ IsVectorObj and IsMutable, IsMultiplicativeElement, IsInt, IsInt ],
609+
function( v, s, from, to )
610+
local i;
611+
for i in [from .. to] do
612+
v[i] := v[i] * s;
613+
od;
614+
end );
615+
571616
#
572617
# Compatibility code: Install MatrixObj methods for IsMatrix.
573618
#

lib/matobj2.gd

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -350,23 +350,47 @@ DeclareOperation( "AddRowVector",
350350

351351
# TODO: rename MultRowVector to MultVector; but keep in mind that
352352
# historically there already was MultRowVector, so be careful to not break that
353-
DeclareOperation( "MultRowVector",
354-
[ IsVectorObj and IsMutable, IsObject ] );
355-
356-
#
357-
# Also, make it explicit from which side we multiply
358-
# DeclareOperation( "MultRowVectorFromLeft",
359-
# [ IsVectorObj and IsMutable, IsObject ] );
360-
# DeclareOperation( "MultRowVectorFromRight",
361-
# [ IsVectorObj and IsMutable, IsObject ] );
362-
#DeclareSynonym( "MultRowVector", MultRowVectorFromRight );
363-
364-
# do we really need the following? for what? is any code using this right now?
365-
# ( a, pa, b, pb, s ) -> a{pa} := b{pb} * s;
366-
DeclareOperation( "MultRowVector",
367-
[ IsVectorObj and IsMutable, IsList, IsVectorObj, IsList, IsObject ] );
368-
369-
# maybe have this: vec := vec{[from..to]} * scal ?? cvec has it
353+
#############################################################################
354+
##
355+
#O MultRowVector( <vec>, <mul>[, <from>, <to>] )
356+
#O MultRowVectorLeft( <vec>, <mul>[, <from>, <to>] )
357+
#O MultRowVectorRight( <vec>, <mul>[, <from>, <to>] )
358+
##
359+
## <#GAPDoc Label="MatObj_MultRowVector">
360+
## <#GAPDoc Label="MatObj_MultRowVectorLeft">
361+
## <#GAPDoc Label="MatObj_MultRowVectorRight">
362+
## <ManSection>
363+
## <Oper Name="MultRowVectorLeft" Arg='vec, mul[, from, to]'/>
364+
## <Oper Name="MultRowVectorRight" Arg='vec, mul[, from, to]'/>
365+
## <Returns>nothing</Returns>
366+
##
367+
## <Description>
368+
## Note that <C>MultRowVector</C> is only a Synonym for
369+
## <C>MultRowVectorLeft</C>.
370+
## </P>
371+
## These operations multiply <A>vec</A> with <A>mul</A> in-place and write
372+
## the result to <A>vec</A>.
373+
## <C>MultRowVectorLeft</C> multiplies <A>mul</A> to <A>vec</A> from the
374+
## left. <C>MultRowVectorRight</C> does so from the right.
375+
## </P>
376+
## The optional parameters <A>from</A> and <A>to</A> can be used to restrict
377+
## the effect of the operation to the entries
378+
## <C><A>vec</A>{[<A>from</A>..<A>to</A>]}.
379+
## This can be helpful if entries of <A>vec</A> are known to be zero.
380+
## </Description>
381+
## </ManSection>
382+
## <#/GAPDoc>
383+
##
384+
DeclareOperation( "MultRowVectorLeft",
385+
[ IsVectorObj and IsMutable, IsMultiplicativeElement ] );
386+
DeclareOperation( "MultRowVectorRight",
387+
[ IsVectorObj and IsMutable, IsMultiplicativeElement ] );
388+
DeclareOperation( "MultRowVectorLeft",
389+
[ IsVectorObj and IsMutable, IsMultiplicativeElement, IsInt, IsInt ] );
390+
DeclareOperation( "MultRowVectorRight",
391+
[ IsVectorObj and IsMutable, IsMultiplicativeElement, IsInt, IsInt ] );
392+
# Note that MultRowVector is declared a Synonym for MultRowVectorLeft in
393+
# listcoef.gd
370394

371395

372396
# The following operations for scalars and vectors are possible for scalars in the BaseDomain

lib/matobjplist.gi

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -532,57 +532,28 @@ InstallMethod( AddRowVector,
532532
fi;
533533
end );
534534

535-
InstallMethod( MultRowVector, "for a plist vector, and a scalar",
536-
[ IsPlistVectorRep and IsMutable, IsObject ],
535+
InstallMethod( MultRowVectorLeft,
536+
"for a plist vector, and a multiplicative element",
537+
[ IsPlistVectorRep and IsMutable, IsMultiplicativeElement ],
537538
function( v, s )
538-
MULT_ROW_VECTOR_2(v![ELSPOS],s);
539+
MULT_ROW_VECTOR_LEFT_2(v![ELSPOS],s);
539540
end );
540541

541-
InstallMethod( MultRowVector, "for a checking plist vector, and a scalar",
542-
[ IsPlistVectorRep and IsCheckingVector and IsMutable, IsObject ],
542+
InstallMethod( MultRowVectorRight,
543+
"for a plist vector, and a multiplicative element",
544+
[ IsPlistVectorRep and IsMutable, IsMultiplicativeElement ],
543545
function( v, s )
544-
if not s in v![BDPOS] then
545-
ErrorNoReturn("MultRowVector: Scalar is not in base domain");
546-
fi;
547-
MULT_ROW_VECTOR_2(v![ELSPOS],s);
546+
MULT_ROW_VECTOR_RIGHT_2(v![ELSPOS],s);
548547
end );
549548

550-
InstallMethod( MultRowVector, "for a plist vector, and a scalar",
551-
[ IsPlistVectorRep and IsIntVector and IsMutable, IsObject ],
549+
InstallOtherMethod( MultRowVector, "for an integer vector, and a small integer",
550+
[ IsPlistVectorRep and IsIntVector and IsMutable, IsSmallIntRep ],
552551
function( v, s )
553-
if IsSmallIntRep(s) then
554-
MULT_ROW_VECTOR_2_FAST(v![ELSPOS],s);
555-
else
556-
MULT_ROW_VECTOR_2(v![ELSPOS],s);
557-
fi;
558-
end );
559-
560-
InstallMethod( MultRowVector,
561-
"for a plist vector, a list, a plist vector, a list, and a scalar",
562-
[ IsPlistVectorRep and IsMutable, IsList,
563-
IsPlistVectorRep, IsList, IsObject ],
564-
function( a, pa, b, pb, s )
565-
a![ELSPOS]{pa} := b![ELSPOS]{pb} * s;
552+
MULT_ROW_VECTOR_2_FAST(v![ELSPOS],s);
566553
end );
567554

568-
InstallMethod( MultRowVector,
569-
"for a checking plist vector, a list, a ch. plist vector, a list, a scalar",
570-
[ IsPlistVectorRep and IsCheckingVector and IsMutable, IsList,
571-
IsPlistVectorRep and IsCheckingVector, IsList, IsObject ],
572-
function( a, pa, b, pb, s )
573-
local l;
574-
l := Length(a![ELSPOS]);
575-
if not ForAll(pa,x->x >= 1 and x <= l) then
576-
ErrorNoReturn("MultRowVector: Positions pa must lie in first vector");
577-
fi;
578-
if not IsIdenticalObj(a![BDPOS],b![BDPOS]) then
579-
ErrorNoReturn("MultRowVector: Cannot add vectors over different base domains");
580-
fi;
581-
if not s in a![BDPOS] then
582-
ErrorNoReturn("MultRowVector: Scalar not in base domain");
583-
fi;
584-
a![ELSPOS]{pa} := b![ELSPOS]{pb} * s;
585-
end );
555+
# The four argument version of MultRowVector uses the generic implementation
556+
# in matobj.gi
586557

587558
InstallMethod( \*, "for a plist vector and a scalar",
588559
[ IsPlistVectorRep, IsScalar ],

lib/obsolete.gd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,31 @@ end);
529529
## still used by GAPDoc (01/2016)
530530
DeclareOperation( "PositionFirstComponent", [IsList,IsObject] );
531531

532+
#############################################################################
533+
##
534+
#O MultRowVector( <list1>, <poss1>, <list2>, <poss2>, <mul> )
535+
##
536+
## <#GAPDoc Label="MultRowVector">
537+
## <ManSection>
538+
## <Oper Name="MultRowVector" Arg='list1, [poss1, list2, poss2, ]mul'/>
539+
## <Returns>nothing</Returns>
540+
##
541+
## <Description>
542+
## The two argument version of this operation is just a synonym for
543+
## <C>MultVectorLeft</C>, which calculates <A>mul</A>*<A>list1</A> in-place.
544+
## <P/>
545+
## <E>The five argument version of this operation is kept for compatibility
546+
## with older versions of &GAP; and will be removed eventually.</E>
547+
## It replaces
548+
## <A>list1</A><C>[</C><A>poss1</A><C>[</C><M>i</M><C>]]</C> by
549+
## <C><A>mul</A>*<A>list2</A>[<A>poss2</A>[</C><M>i</M><C>]]</C> for <M>i</M>
550+
## between <M>1</M> and <C>Length( <A>poss1</A> )</C>.
551+
## </Description>
552+
## </ManSection>
553+
## <#/GAPDoc>
554+
##
555+
DeclareObsoleteSynonym( "MultRowVector", "MultVectorLeft" );
556+
532557
#############################################################################
533558
##
534559
#O ReadTest

lib/obsolete.gi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,28 @@ local lo,up,s;
877877
# fi;
878878
end );
879879

880+
#############################################################################
881+
##
882+
#M MultRowVector( <list1>, <poss1>, <list2>, <poss2>, <mult> )
883+
##
884+
InstallOtherMethod( MultRowVector, "obsolete five argument method",
885+
true,
886+
[ IsDenseList and IsMutable,
887+
IsDenseList,
888+
IsDenseList,
889+
IsDenseList,
890+
IsMultiplicativeElement ],
891+
0,
892+
function( l1, p1, l2, p2, m )
893+
InfoObsolete(1, "This usage of `MultRowVector` is no longer",
894+
"supported and will be removed eventually." );
895+
l1{p1} := m * l2{p2};
896+
end );
897+
898+
InstallOtherMethod( MultRowVector, "error if immutable", true,
899+
[ IsList,IsObject,IsObject,IsObject,IsObject],0,
900+
L1_IMMUTABLE_ERROR);
901+
880902
#############################################################################
881903
##
882904
#F SetUserPreferences

0 commit comments

Comments
 (0)