
| Current Path : /usr/share/gap/doc/ref/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //usr/share/gap/doc/ref/chap26.txt |
[1X26 [33X[0;0YVector and Matrix Objects[133X[101X
[33X[0;0YThis chapter is work in progress. It will eventually describe the new
interface to vector and matrix objects.[133X
[33X[0;0YTraditionally, vectors in [5XGAP[105X have been lists and matrices have been lists
of lists (of equal length). Unfortunately, such lists cannot store their
type and so it is impossible to use the full advantages of [5XGAP[105X's method
selection on them. This situation is unsustainable in the long run since
more special representations (compressed, sparse, etc.) have already been
and even more will be implemented. To eventually solve this problem, this
chapter describes a new programming interface to vectors and matrices.[133X
[1X26.1 [33X[0;0YFundamental Ideas and Rules[133X[101X
[33X[0;0YThe whole idea of this interface is that vectors and matrices must be proper
objects with a stored type (i.e. created by Objectify allowing inheritance)
to benefit from method selection. We therefore refer to the new style
vectors and matrices as [21Xvector objects[121X and [21Xmatrix objects[121X respectively.[133X
[33X[0;0YIt should be possible to write (efficient) code that is independent of the
actual representation (in the sense of [5XGAP[105X's representation filters) and
preserves it.[133X
[33X[0;0YThis latter requirement makes it necessary to distinguish between (at least)
two classes of matrices:[133X
[30X [33X[0;6Y[21XRowList[121X-Matrices which behave basically like lists of rows, in
particular are the rows individual [5XGAP[105X objects that can be shared
between different matrix objects.[133X
[30X [33X[0;6Y[21XFlat[121X matrices which behave basically like one [5XGAP[105X object that cannot
be split up further. In particular a row is only a part of a matrix
and no GAP object in itself.[133X
[33X[0;0YFor various reasons these two classes have to be distinguished already with
respect to the definition of the operations for them.[133X
[33X[0;0YIn particular vectors and matrices know their BaseDomain and their
dimensions. Note that the basic condition is that the elements of vectors
and matrices must either lie in the BaseDomain or naturally embed in the
sense that + and * and = automatically work with all elements of the base
domain (example: integers in polynomials over integers).[133X
[33X[0;0YVectors are equal with respect to "=" if they have the same length and the
same entries. It is not necessary that they have the same BaseDomain.
Matrices are equal with respect to "=" if they have the same dimensions and
the same entries. It is possible that not for all pairs of representations
methods exist.[133X
[33X[0;0YIt is not guaranteed that all rows of a matrix have the same vector type! It
is for example thinkable that a matrix stores some of its rows in a sparse
representation and some in a dense one! However, it is guaranteed that the
rows of matrices in the same representation are compatible in the sense that
all vector operations defined in this interface can be applied to them and
that new matrices in the same representation as the original matrix can be
formed out of them.[133X
[33X[0;0YNote that there is neither a default mapping from the set of matrix
representations to the set of vector representations nor one in the reverse
direction! There is nothing like an "associated" vector representation to a
matrix representation or vice versa.[133X
[33X[0;0YThe way to write code that preserves the representation basically works by
using constructing operations that take template objects to decide about the
actual representation of the new object.[133X
[33X[0;0YVectors do not have to be lists in the sense that they do not have to
support all list operations. The same holds for matrices. However, RowList
matrices behave nearly like lists of row vectors that insist on being dense
and containing only vectors of the same length and with the same BaseDomain.[133X
[33X[0;0YThere are some rules embedded in the comments to the following code. They
are marked with the word "Rule". FIXME: Collect all rules here.[133X
[1X26.2 [33X[0;0YCategories of Vectors and Matrices[133X[101X
[1X26.3 [33X[0;0YConstructing Vector and Matrix Objects[133X[101X
[1X26.4 [33X[0;0YOperations for Vector Objects[133X[101X
[1X26.4-1 PositionNonZero[101X
[33X[1;0Y[29X[2XPositionNonZero[102X( [3XV[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10YAn integer[133X
[33X[0;0YReturns the index of the first entry in the vector [3XV[103X which is not zero. If
all entries are zero, the function returns [10XLength([3XV[103X[10X) + 1[110X.[133X
[1X26.4-2 PositionLastNonZero[101X
[33X[1;0Y[29X[2XPositionLastNonZero[102X( [3XV[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10YAn integer[133X
[33X[0;0YReturns the index of the last entry in the vector [3XV[103X which is not zero. If
all entries are zero, the function returns 0.[133X
[1X26.4-3 ListOp[101X
[33X[1;0Y[29X[2XListOp[102X( [3XV[103X[, [3Xfunc[103X] ) [32X operation[133X
[6XReturns:[106X [33X[0;10YA plain list[133X
[33X[0;0YApplies [3Xfunc[103X to each entry of the vector [3XV[103X and returns the results as a
plain list. This allows for calling [2XList[102X ([14X30.3-5[114X) on vectors. If the
argument [3Xfunc[103X is not provided, applies [2XIdFunc[102X ([14X5.4-6[114X) to all entries.[133X
[1X26.4-4 Unpack[101X
[33X[1;0Y[29X[2XUnpack[102X( [3XV[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10YA plain list[133X
[33X[0;0YReturns a new plain list containing the entries of [3XV[103X. Guarantees to return a
new list which can be manipulated without changing [3XV[103X. The entries itself are
not copied.[133X
[1X26.4-5 ConcatenationOfVectors[101X
[33X[1;0Y[29X[2XConcatenationOfVectors[102X( [3XV1[103X, [3XV2[103X, [3X...[103X ) [32X function[133X
[33X[1;0Y[29X[2XConcatenationOfVectors[102X( [3XVlist[103X ) [32X function[133X
[6XReturns:[106X [33X[0;10Ya vector object[133X
[33X[0;0YReturns a new vector containing the entries of [3XV1[103X, [3XV2[103X, etc. As prototype [3XV1[103X
is used.[133X
[1X26.4-6 ExtractSubVector[101X
[33X[1;0Y[29X[2XExtractSubVector[102X( [3XV[103X, [3Xl[103X ) [32X function[133X
[6XReturns:[106X [33X[0;10Ya vector object[133X
[33X[0;0YReturns a new vector containing the entries of [3XV[103X at the positions in [3Xl[103X.[133X
[1X26.4-7 ZeroVector[101X
[33X[1;0Y[29X[2XZeroVector[102X( [3Xl[103X, [3XV[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10Ya vector object[133X
[33X[0;0YReturns a new vector of length [3Xl[103X in the same representation as [3XV[103X containing
only zeros.[133X
[1X26.4-8 ConstructingFilter[101X
[33X[1;0Y[29X[2XConstructingFilter[102X( [3XV[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10Ya filter[133X
[33X[0;0YReturns a filter [10Xf[110X such that if [10XNewVector[110X is called with [10Xf[110X a vector in the
same representation as [3XV[103X is produced.[133X
[1X26.4-9 Randomize[101X
[33X[1;0Y[29X[2XRandomize[102X( [3XV[103X ) [32X operation[133X
[33X[1;0Y[29X[2XRandomize[102X( [3XV[103X, [3XRs[103X ) [32X operation[133X
[33X[0;0YReplaces every entry in [3XV[103X with a random one from the base domain. If given,
the random source [3XRs[103X is used to compute the random elements. Note that in
this case, the random function for the base domain must support the random
source argument.[133X
[1X26.4-10 WeightOfVector[101X
[33X[1;0Y[29X[2XWeightOfVector[102X( [3XV[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10Yan integer[133X
[33X[0;0YComputes the Hamming weight of the vector [3XV[103X, i.e., the number of nonzero
entries.[133X
[1X26.4-11 DistanceOfVectors[101X
[33X[1;0Y[29X[2XDistanceOfVectors[102X( [3XV1[103X, [3XV2[103X ) [32X operation[133X
[6XReturns:[106X [33X[0;10Yan integer[133X
[33X[0;0YComputes the Hamming distance of the vectors [3XV1[103X and [3XV2[103X, i.e., the number of
entries in which the vectors differ. The vectors must be of equal length.[133X
[1X26.5 [33X[0;0YOperations for Row List Matrix Objects[133X[101X
[1X26.6 [33X[0;0YOperations for Flat Matrix Objects[133X[101X