Class BaseVector<V extends BaseVector<V>>
- All Implemented Interfaces:
Serializable
,IArchive
- Direct Known Subclasses:
EnergyVector
,GenericVector
,PhaseVector
,R3
,R4
,R6
,Rn
Class Vector
is the abstract base class for matrix objects
supported in the XAL tools packages.
- Since:
- Aug, 2002
- Version:
- Oct, 2013
- Author:
- Christopher K. Allen, Blaz Kranjc
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseVector
(double[] arrVals) Initializing constructor for bases classBaseVector
.protected
BaseVector
(int intSize) Creates a new, uninitialized instance of a vector with the given size.protected
BaseVector
(int intSize, String strTokens) Parsing Constructor - creates an instance of the child class and initialize it according to a token string of element values.protected
BaseVector
(int intSize, DataAdaptor daSource) Initializing constructor forBaseVector
.protected
BaseVector
(V vecParent) Copy constructor forVector
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Assign this matrix to be the unity vector, the with all 1's.void
Assign this vector to be the zero vector, specifically the vector containing all 0's.abstract V
clone()
Base classes must override the clone operation in order to make deep copies of the current object.Perform a deep copy of this Vector object and return it.<U extends BaseVector<U>>
voidembedIn
(U vecSup) Embeds this vector into the larger super-space represented by the given vector.boolean
"Borrowed" implementation from AffineTransform, since it is based on double attribute values.double[]
Returns a copy of the internal Java array containing the vector elements.double
getElem
(int iIndex) Get individual element of a vector at specified indexdouble
Returns the vector component at the position indicated by the given index in theIIndex
interface.int
getSize()
Get size of Vector (number of elements)protected org.ejml.data.DenseMatrix64F
Return the internal matrix representation.int
hashCode()
"Borrowed" implementation from AffineTransform, since it is based on double attribute values.double
Vector inner product.boolean
isEquivalentTo
(V vecTest) Checks if the given vector is algebraically equivalent to this vector.<M extends SquareMatrix<M>>
VleftMultiply
(M mat) Vector left multiplication, or covariant operation of matrix on this vector (post-multiply vector by matrix).void
load
(DataAdaptor daptArchive) Restore the value of the this vector from the contents of a data archive.Vector subtraction without destructionvoid
minusEquals
(V vecSub) Vector in-place subtraction.negate()
Element by element negation.void
In place element-by-element negation of this vector.protected abstract V
newInstance
(double[] arrVecInt) Creates a new instance of this vector type with the given Java array as the internal representation.protected abstract V
newInstance
(int size) Creates a new, uninitialized instance of this vector type.protected V
newInstance
(org.ejml.data.DenseMatrix64F vecInit) Creates a new instance of this vector type initialized to the given implementation matrix.double
norm1()
Return the l1 norm of the vector.double
norm2()
Return the l2 norm of the vector.double
normInf()
Return the l∞ norm of the vector.Vector addition without destructionvoid
plusEquals
(V vecAdd) Vector in-place addition.void
print()
Print the vector contents to standard output.void
print
(PrintWriter os) Print the vector contents to an output stream, does not add new line.void
println
(PrintWriter os) Print the vector contents to an output stream, add new line character.<U extends BaseVector<U>>
voidprojectOnto
(U vecSub) Projects this vector onto the smaller subspace represented by the given vector.<M extends SquareMatrix<M>>
VrightMultiply
(M mat) Vector right multiplication, or contra-variant operation of the matrix on this vector (pre-multiply vector by matrix).void
save
(DataAdaptor daptArchive) Save the value of this vector to disk.void
setElem
(int intIndex, double dblVal) Set individual element of a vector to given valuevoid
Set individual element of a vector to given value.void
setVector
(double[] arrVector) Sets the entire vector to the values given in the Java primitive type double array.void
Parsing assignment - set the vector value according to a token string of element values.void
Sets the entire vector to the values given to the value of the new vector.times
(double s) Scalar multiplicationvoid
timesEquals
(double s) In place scalar multiplicationtoString()
Convert the contents of the matrix to a string representation.
-
Field Details
-
ATTR_DATA
attribute marker for data- See Also:
-
-
Constructor Details
-
BaseVector
protected BaseVector(int intSize) Creates a new, uninitialized instance of a vector with the given size. The vector contains all zeros.- Parameters:
intSize
- the vector size of this object- Throws:
UnsupportedOperationException
- base class has not defined a public, zero-argument constructor
-
BaseVector
Copy constructor forVector
. Creates a deep copy of the given object. The dimensions are set and the internal array is cloned.- Parameters:
vecParent
- the vector to be cloned- Throws:
UnsupportedOperationException
- base class has not defined a public, zero-argument constructor- Since:
- Sep 25, 2013
-
BaseVector
Parsing Constructor - creates an instance of the child class and initialize it according to a token string of element values.
The token string argument is assumed to be one-dimensional and delimited by any of the characters " ,()[]{}" Repeated, contiguous delimiters are parsed together. This conditions allows a variety of parseable string representations. For example,
{ 1, 2, 3, 4 }
and
[1 2 3 4]
would parse to the same homogeneous vector (1, 2, 3, 4 | 1).- Parameters:
intSize
- the matrix size of this objectstrTokens
- token vector of getSize() numeric values- Throws:
NumberFormatException
- bad number format, unparseable
-
BaseVector
protected BaseVector(double[] arrVals) Initializing constructor for bases class
BaseVector
. Sets the entire matrix to the values given in the Java primitive type double array. The argument itself remains unchanged.The dimensions of the new vector will be the length of the given Java double array.
- Parameters:
arrVals
- Java primitive array containing new vector values- Since:
- Oct 4, 2013
-
BaseVector
Initializing constructor forBaseVector
. The vector values are taken from the data source provided.- Parameters:
intSize
- size of this vectordaSource
- data source containing the initial values of this vector- Since:
- Nov 5, 2013
-
-
Method Details
-
setVector
Sets the entire vector to the values given in the Java primitive type double array.NOTE!
TODO This is not going to work for homogeneous coordinates!
- Parameters:
arrVector
- Java primitive array containing new vector values- Throws:
IllegalArgumentException
- the argument must have the same dimensions as this matrix- Since:
- Oct 4, 2013
-
setVector
Sets the entire vector to the values given to the value of the new vector.- Parameters:
vecParent
- Java primitive array containing new vector values- Throws:
ArrayIndexOutOfBoundsException
- the argument must have the same dimensions as this matrix- Since:
- Oct 4, 2013
-
setVector
Parsing assignment - set the vector value according to a token string of element values. The token string argument is assumed to be one-dimensional and packed by column (aka FORTRAN).NOTE!
TODO This is not going to work for homogeneous coordinates!
- Parameters:
strValues
- token vector of SIZE2 numeric values- Throws:
NumberFormatException
- bad number format, unparseable
-
setElem
Set individual element of a vector to given value- Parameters:
intIndex
- index of elementdblVal
- new value of element- Throws:
ArrayIndexOutOfBoundsException
- iIndex is larger than the vector
-
setElem
Set individual element of a vector to given value. The index is assumed to be an enumeration exposing theIIndex
interface. That interface interface belongs to theBaseMatrix
namespace. In this manner matrix indices can be used to set vector component values.- Parameters:
iIndex
- index of element taken from the interfaceIIndex
of classBaseMatrix
dblVal
- new value of element- Throws:
ArrayIndexOutOfBoundsException
- iIndex is larger than the vector
-
getSize
public int getSize()Get size of Vector (number of elements)- Returns:
- vector length
-
getElem
Get individual element of a vector at specified index- Parameters:
iIndex
- data source providing index of element- Returns:
- value of element at given index
- Throws:
ArrayIndexOutOfBoundsException
- iIndex is larger than vector size
-
getElem
Returns the vector component at the position indicated by the given index in the
IIndex
interface. That interface belongs to theBaseMatrix
namespace. In this way matrix indices can be used to get vector component values.NOTES
· It is expected that the object exposing theIIndex
interface is an enumeration class restricting the number of possible index values.
· Consequently we do not declare a thrown exception assuming that that enumeration class eliminates the possibility of an out of bounds error.- Parameters:
iIndex
- source containing the vector index- Returns:
- value of the matrix element at the given row and column
- Throws:
ArrayIndexOutOfBoundsException
- iIndex is larger than the vector
-
getArrayCopy
public double[] getArrayCopy()Returns a copy of the internal Java array containing the vector elements. The array dimensions are given by the size of this matrix, available from
. The returned array is a copy of this vector thus manipulation with not affect the parent object.getSize()
- Returns:
- copied array of vector values
- Since:
- Sep 25, 2013
-
clone
Base classes must override the clone operation in order to make deep copies of the current object. This operation cannot be done without the exact type. -
toString
Convert the contents of the matrix to a string representation. The format is similar to that of Mathematica. Specifically,
{ a b c d } -
hashCode
public int hashCode()"Borrowed" implementation from AffineTransform, since it is based on double attribute values. Must implement hashCode to be consistent with equals as specified by contract of hashCode inObject
. -
equals
"Borrowed" implementation from AffineTransform, since it is based on double attribute values. Must implement hashCode to be consistent with equals as specified by contract of hashCode inObject
. -
copyVector
Perform a deep copy of this Vector object and return it.- Returns:
- a cloned copy of this vector
-
assignZero
public void assignZero()Assign this vector to be the zero vector, specifically the vector containing all 0's.- Since:
- Oct 3, 2013
-
assignUnity
public void assignUnity()Assign this matrix to be the unity vector, the with all 1's.- Since:
- Oct 3, 2013
-
projectOnto
Projects this vector onto the smaller subspace represented by the given vector. For example, say this vector v is an element of Rn and the given vector u is an element of Rm where m ≤ n. Then v decomposes as v = (v1 v2) ∈ Rm × Rn-m. That component v1 that lives in the subspace Rm is projected onto the given vector.
To make it simple, the first m components of this vector are used to set all the values of the given vector, in respective order. If the give vector is larger than this vector an exception is thrown.
- Parameters:
vecSub
- The vector to receive the projection of this vector (determines size)- Since:
- Oct 18, 2013
-
embedIn
Embeds this vector into the larger super-space represented by the given vector. For example, say this vector v is an element of Rm and the given vector u is an element of Rn where m ≤ n. Then u decomposes as u = (u1 u2) ∈ Rm × Rn-m. This vector v is embedded as that component u1 that lives in the sub-space Rm ⊂Rm × Rn-m.
To make it simple, the first m components of the given vector are set to the components of this vector, in respective order. If the give vector is smaller than this vector an exception is thrown.
- Parameters:
vecSup
- The vector to receive the embedding of this vector- Since:
- Oct 18, 2013
-
isEquivalentTo
Checks if the given vector is algebraically equivalent to this vector. That is, it is equal in size and element values.- Parameters:
vecTest
- vector under equivalency test- Returns:
true
if the argument is equivalent to this vector,false
if otherwise- Since:
- Oct 1, 2013
-
negate
Element by element negation. A new object is returned and the current one is unmodified.- Returns:
- antipodal vector of the current object
- Since:
- Oct 10, 2013
-
negateEquals
public void negateEquals()In place element-by-element negation of this vector.- Since:
- Oct 10, 2013
-
plusEquals
Vector in-place addition. Add the given vector to this vector which then takes on the summed value.- Parameters:
vecAdd
- Vector to add to this vector (addend)
-
plus
Vector addition without destruction- Parameters:
vecAdd
- vector added to this one (addend)- Returns:
- sum of this vector and given vector,
-
minusEquals
Vector in-place subtraction. Subtracts the given vector from this vector which then takes the new value.- Parameters:
vecSub
- Vector to subtract from this vector (subtrahend)
-
minus
Vector subtraction without destruction- Parameters:
vecSub
- vector subtracted from this one (subtrahend)- Returns:
- difference of this vector and the given vector,
-
times
Scalar multiplication- Parameters:
s
- scalar value- Returns:
- result of scalar multiplication
-
timesEquals
public void timesEquals(double s) In place scalar multiplication- Parameters:
s
- scalar
-
innerProd
Vector inner product. Computes the inner product of of this vector with the given vector.- Parameters:
v
- second vector- Returns:
- inner product of this vector and argument
-
leftMultiply
Vector left multiplication, or covariant operation of matrix on this vector (post-multiply vector by matrix).- Parameters:
mat
- matrix operator- Returns:
- result of vector-matrix product
-
rightMultiply
Vector right multiplication, or contra-variant operation of the matrix on this vector (pre-multiply vector by matrix).- Parameters:
mat
- matrix operator- Returns:
- result of vector-matrix product
-
norm1
public double norm1()Return the l1 norm of the vector.- Returns:
- ||z||1 = Σi |zi|
-
norm2
public double norm2()Return the l2 norm of the vector.- Returns:
- ||z||2 = [ Σi zi2 ]1/2
-
normInf
public double normInf()Return the l∞ norm of the vector.- Returns:
- ||z||∞ = supi |zi|
-
save
Save the value of this vector to disk. -
load
Restore the value of the this vector from the contents of a data archive.- Specified by:
load
in interfaceIArchive
- Parameters:
daptArchive
- interface to data source- Throws:
DataFormatException
- malformed data- See Also:
-
print
public void print()Print the vector contents to standard output. -
print
Print the vector contents to an output stream, does not add new line.- Parameters:
os
- output stream object
-
println
Print the vector contents to an output stream, add new line character.- Parameters:
os
- output stream object
-
getVector
protected org.ejml.data.DenseMatrix64F getVector()Return the internal matrix representation.- Returns:
- the internal implementation matrix object
-
newInstance
Creates a new, uninitialized instance of this vector type.- Returns:
- uninitialized vector object of type
V
- Since:
- Oct 1, 2013
-
newInstance
Creates a new instance of this vector type with the given Java array as the internal representation.- Parameters:
arrVecInt
- new vector's guts- Returns:
- new instance of this vector type with the internal representation
- Since:
- Jul 24, 2015 by Christopher K. Allen
-
newInstance
Creates a new instance of this vector type initialized to the given implementation matrix.- Parameters:
vecInit
- implementation vector containing initialization values- Returns:
- initialized vector object of type
V
- Since:
- Oct 1, 2013
-