vector(3) UNIX System V (Nov 25, 1998) vector(3)
Vector
Inherits from:
CAObject
Maturity Index:
Relatively mature
Class Description
A vector consists of a number of scalars that can be
arbitrary Computer Algebra Kit objects, but they currently
have to be either floating-point or elements of a field (see
inField ) or elements of an integral domain (see
inIntegralDomain ).
There are methods to access, insert and remove scalars.
It's also possible to place or replace a scalar directly at
a given index. See the documentation on eachScalar to
access the scalar at a given index.
Note:
Vector objects are meant for computational tasks. They are
no substitute for List or Collection objects, that are
better suited for the purpose of storing objects.
Method types
Creation
* collection:
* scalarZero:numScalars:
* copy
* deepCopy
* clear
Identity
* scalarZero
* numScalars
* hash
* isEqual:
Insertion Scalars
* insertScalar:
* insertScalar:at:
Removing Scalars
* removeScalar
* removeScalarAt:
* freeScalarAt:
Placing and Replacing
* placeScalar:at:
Page 1 (printed 6/28/99)
vector(3) UNIX System V (Nov 25, 1998) vector(3)
* replaceScalarAt:with:
* asCollection
* asNumerical
* asModp:
* onCommonDenominator:
Accessing Scalars
* eachScalar
* floatValueAt:
* intValueAt:
Addition
* zero
* isZero
* isOpposite:
* negate
* double
* add:
* subtract:
* addScalar:at:
* subtractScalar:at:
Scalar Multiplication
* multiplyScalar:
* divideScalar:
Multiplication
* dotSquare
* dotMultiply:
* multiplyLeftMatrix:
Printing
* printOn:
Methods
collection:
+ collection : aCltn
Creates a vector containing references to the scalars from
aCltn . The collection must not be empty. You remain
responsible for freeing the collection.
scalarZero:numScalars:
+ scalarZero : aScalarZero numScalars :(int) numScalars
Creates a new vector with numScalars zero scalars.
copy
- copy
Returns a new vector. Sends cheapCopy messages to the
scalars in the vector.
Page 2 (printed 6/28/99)
vector(3) UNIX System V (Nov 25, 1998) vector(3)
deepCopy
- deepCopy
Returns a new vector. Sends deepCopy messages to the
scalars in the vector.
clear
- clear
Sends free messages to the scalars in the vector.
scalarZero
- scalarZero
Returns the zero scalar element. You may not free or modify
the object returned by this method.
numScalars
- ( int ) numScalars
Returns the number of scalar objects in the vector. Returns
0 if the vector is empty. The first scalar in the vector is
at index 0, the last scalar at numScalars minus one.
insertScalar:
- insertScalar : aScalar
Inserts aScalar as first entry and returns self . The
object aScalar belongs to the vector after insertion, and is
not necessarily copied. To insert a scalar, the reference
count of the vector should be equal to one.
insertScalar:at:
- insertScalar : aScalar at :(int) i
Inserts aScalar as i-th entry and returns self . The object
aScalar belongs to the vector after insertion, and is not
necessarily copied. If i is equal to zero, this method is
identical to -insertScalar: . If i is equal to numScalars
, this method inserts the scalar as last element. The
reference count of the vector should be equal to one.
removeScalar
- removeScalar
Removes (and returns) the first scalar in the vector (the
scalar at index 0). Returns nil if there were no more
elements left. This can be used in the following way :
while (c = [vector removeScalar]) { /* do something with
c */ }
Page 3 (printed 6/28/99)
vector(3) UNIX System V (Nov 25, 1998) vector(3)
To remove a scalar, the reference count of the vector should
be equal to one.
removeScalarAt:
- removeScalarAt :(int) i
Removes and returns the i-th scalar in the vector. If i is
zero, this method is identical to removeScalar . The
reference count of the vector should be equal to one.
Unlike removeScalar , which returns nil if there are no more
scalars in the vector, this method generates an error
message if you attempt to remove a scalar at an illegal
index.
freeScalarAt:
- freeScalarAt :(int) i
Removes and frees the i-th scalar in the vector. The
reference count of the vector should be equal to one.
Returns self .
placeScalar:at:
- placeScalar : aScalar at :(int) i
Frees the scalar at position i and replaces it by the scalar
object aScalar . Returns self . The scalar aScalar belongs
to the receiving vector object; it is not necessarily
copied. This is similar to List's -addObject: method. It
is an error to use an illegal index i or to attempt to set a
scalar in a vector whose reference count is not equal to
one.
replaceScalarAt:with:
- replaceScalarAt :(int) i with : aScalar
Similar to placeScalar:at: but returns, rather than frees,
the scalar at position i after replacing it by aScalar . It
is an error to use an illegal index i or to attempt to
replace a scalar in a vector whose reference count is not
equal to one.
asCollection
- asCollection
Returns a new collection containing new references to the
scalars in the vector.
asNumerical
- asNumerical
Returns a new vector, whose scalars are the numerical value
of the scalars of the original vector.
Page 4 (printed 6/28/99)
vector(3) UNIX System V (Nov 25, 1998) vector(3)
asModp:
- asModp :(unsigned short) p
Returns a new vector, whose scalars are the value of the
scalars of the original vector mod p .
onCommonDenominator:
- onCommonDenominator :(id *) denominator
Puts a vector with fractional scalars on a common
denominator. Returns a new vector with integral scalars,
and, by reference, the common denominator of the scalars in
the vector.
eachScalar
- eachScalar
Returns a new sequence object that gives access to the
scalars of the vector.
floatValueAt:
- ( float ) floatValueAt :(int) i
Returns the floatValue of the scalar at the i -th position.
intValueAt:
- ( int ) intValueAt :(int) i
Returns the intValue of the scalar at the i -th position.
zero
- zero
Returns a vector of the same dimension as the object that
receives the message, but all filled with zero scalars.
addScalar:at:
- addScalar : s at :(int) i
Returns a new vector. Adds s to the scalar at position i ,
and replaces the scalar by the sum. i must be between 0 and
the number of scalars in the vector. This method is not an
insertion method.
See also:
insertScalar:at:, replaceScalar:at:
subtractScalar:at:
- subtractScalar : s at :(int) i
Returns a new vector. Subtracts s from the scalar at
Page 5 (printed 6/28/99)
vector(3) UNIX System V (Nov 25, 1998) vector(3)
position i . i must be between 0 and the number of scalars
in the vector. This method is not an insertion method.
dotSquare
- dotSquare
Returns a new scalar product, the dot product of the vector
by itself, defined as the sum of squares of the scalars in
the vector.
dotMultiply:
- dotMultiply : aVector
Returns a new scalar product, the dot product of the vector
self by aVector , defined as the sum of the products of the
scalars in the vectors.
multiplyLeftMatrix:
- multiplyLeftMatrix : aMatrix
Returns a new vector, the product of aMatrix by the column
vector self .
printOn:
- printOn :(IOD) aFile
Prints, between braces, a comma separated list of the
scalars (by sending printOn: messages to the scalars).
Page 6 (printed 6/28/99)