public abstract class BaseVector<V extends BaseVector<V>> extends java.lang.Object implements IArchive, java.io.Serializable
Class Vector
is the abstract base class for matrix
objects supported in the XAL tools packages.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTR_DATA
attribute marker for data
|
Modifier | Constructor and Description |
---|---|
protected |
BaseVector(int intSize)
Creates a new, uninitialized instance of a vector with the given
size.
|
protected |
BaseVector(int intSize,
DataAdaptor daSource)
Initializing constructor for
BaseVector . |
protected |
BaseVector(int intSize,
double[] arrVals)
Initializing constructor for bases class
Vector . |
protected |
BaseVector(int intSize,
java.lang.String strTokens)
Parsing Constructor - creates an instance of the child class and initialize it
according to a token string of element values.
|
protected |
BaseVector(V vecParent)
Copy constructor for
Vector . |
Modifier and Type | Method and Description |
---|---|
void |
assignUnity()
Assign this matrix to be the unity vector, the
with all 1's.
|
void |
assignZero()
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.
|
V |
copyVector()
Perform a deep copy of this Vector object and return it.
|
<U extends BaseVector<U>> |
embedIn(U vecSup)
Embeds this vector into the larger super-space represented by
the given vector.
|
double[] |
getArrayCopy()
Returns a copy of the internal Java array containing
the vector elements.
|
double |
getElem(IIndex iIndex)
Returns the vector component at the position indicated by the
given index in the
IIndex interface. |
double |
getElem(int iIndex)
Get individual element of a vector at specified index
|
int |
getSize()
Get size of Vector (number of elements)
|
int |
hashCode()
"Borrowed" implementation from AffineTransform, since it is based on
double attribute values.
|
double |
innerProd(V v)
Vector inner product.
|
boolean |
isEquivalentTo(V vecTest)
Checks if the given vector is algebraically equivalent to this
vector.
|
<M extends SquareMatrix<M>> |
leftMultiply(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
PhaseVector from the
contents of a data archive. |
V |
minus(V vecSub)
Vector subtraction without destruction
|
void |
minusEquals(V vecSub)
Vector in-place subtraction.
|
V |
negate()
Element by element negation.
|
void |
negateEquals()
In place element-by-element negation of this vector.
|
protected abstract V |
newInstance()
Creates a new, uninitialized instance of this vector type.
|
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.
|
V |
plus(V vecAdd)
Vector addition without destruction
|
void |
plusEquals(V vecAdd)
Vector in-place addition.
|
void |
print()
Print the vector contents to standard output.
|
void |
print(java.io.PrintWriter os)
Print the vector contents to an output stream,
does not add new line.
|
void |
println(java.io.PrintWriter os)
Print the vector contents to an output stream,
add new line character.
|
<U extends BaseVector<U>> |
projectOnto(U vecSub)
Projects this vector onto the smaller subspace represented by
the given vector.
|
<M extends SquareMatrix<M>> |
rightMultiply(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
PhaseVector to disk. |
void |
setElem(IIndex iIndex,
double dblVal)
Set individual element of a vector to given value.
|
void |
setElem(int intIndex,
double dblVal)
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 |
setVector(java.lang.String strValues)
Parsing assignment - set the
PhaseMatrix value
according to a token string of element values. |
void |
setVector(V vecParent)
Sets the entire vector to the values given to the value of the new
vector.
|
V |
times(double s)
Scalar multiplication
|
void |
timesEquals(double s)
In place scalar multiplication
|
java.lang.String |
toString()
Convert the contents of the matrix to a string representation.
|
public static final java.lang.String ATTR_DATA
protected BaseVector(int intSize)
intSize
- the vector size of this objectjava.lang.UnsupportedOperationException
- base class has not defined a public, zero-argument constructorprotected BaseVector(V vecParent) throws java.lang.UnsupportedOperationException
Vector
. Creates a deep
copy of the given object. The dimensions are set and the
internal array is cloned.vecParent
- the vector to be clonedjava.lang.UnsupportedOperationException
- base class has not defined a public, zero-argument constructorprotected BaseVector(int intSize, java.lang.String strTokens) throws java.lang.IllegalArgumentException, java.lang.NumberFormatException
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).
intSize
- the matrix size of this objectstrTokens
- token vector of getSize() numeric valuesjava.lang.IllegalArgumentException
- wrong number of token stringsjava.lang.NumberFormatException
- bad number format, unparseableprotected BaseVector(int intSize, double[] arrVals) throws java.lang.ArrayIndexOutOfBoundsException
Initializing constructor for bases class Vector
.
Sets the entire matrix to the values given in the Java primitive type
double array. The argument itself remains unchanged.
The dimensions of the given Java double array must be consistent with the size of the matrix. Thus, if the arguments are inconsistent, an exception is thrown.
intSize
- the vector size of this objectarrMatrix
- Java primitive array containing new vector valuesjava.lang.ArrayIndexOutOfBoundsException
- the argument must have the same dimensions as this matrixprotected BaseVector(int intSize, DataAdaptor daSource)
BaseVector
. The vector values
are taken from the data source provided.intSize
- size of this vectordaSource
- data source containing the initial values of this vectorpublic void setVector(double[] arrVector) throws java.lang.ArrayIndexOutOfBoundsException
arrVector
- Java primitive array containing new vector valuesjava.lang.ArrayIndexOutOfBoundsException
- the argument must have the same dimensions as this matrixpublic void setVector(V vecParent)
arrVector
- Java primitive array containing new vector valuesjava.lang.ArrayIndexOutOfBoundsException
- the argument must have the same dimensions as this matrixpublic void setVector(java.lang.String strValues) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException
PhaseMatrix
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).strValues
- token vector of SIZE2 numeric valuesjava.lang.IllegalArgumentException
- wrong number of token stringsjava.lang.NumberFormatException
- bad number format, unparseablepublic void setElem(int intIndex, double dblVal) throws java.lang.ArrayIndexOutOfBoundsException
intIndex
- index of elementdblVal
- new value of elementjava.lang.ArrayIndexOutOfBoundsException
- iIndex is larger than the vectorpublic void setElem(IIndex iIndex, double dblVal) throws java.lang.ArrayIndexOutOfBoundsException
IIndex
interface. That interface
interface belongs to the BaseMatrix
namespace. In this manner
matrix indices can be used to set vector component values.iIndex
- index of element taken from the interface IIndex
of class BaseMatrix
dblVal
- new value of elementjava.lang.ArrayIndexOutOfBoundsException
- iIndex is larger than the vectorpublic int getSize()
public double getElem(int iIndex) throws java.lang.ArrayIndexOutOfBoundsException
iIndex
- data source providing index of elementjava.lang.ArrayIndexOutOfBoundsException
- iIndex is larger than vector sizepublic double getElem(IIndex iIndex) throws java.lang.ArrayIndexOutOfBoundsException
Returns the vector component at the position indicated by the
given index in the IIndex
interface. That
interface belongs to the BaseMatrix
namespace.
In this way matrix indices can be used to get vector component values.
IIndex
interface is an enumeration
class restricting the number of possible index values.
iIndex
- source containing the vector indexjava.lang.ArrayIndexOutOfBoundsException
- iIndex is larger than the vectorpublic double[] getArrayCopy()
getSize()
. The returned array is
a copy of this vector thus manipulation with not affect
the parent object.public abstract V clone()
clone
in class java.lang.Object
Object.clone()
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
Object
.hashCode
in class java.lang.Object
public V copyVector()
public void assignZero()
public void assignUnity()
public <U extends BaseVector<U>> void projectOnto(U vecSub) throws java.lang.IllegalArgumentException
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.
vecSub
- The vector to receive the projection of this vector (determines size)java.lang.IllegalArgumentException
- Thrown if the given vector is larger than this one.public <U extends BaseVector<U>> void embedIn(U vecSup) throws java.lang.IllegalArgumentException
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.
vecSup
- The vector to receive the embedding of this vectorjava.lang.IllegalArgumentException
- Thrown if the given vector is smaller than this one.public boolean isEquivalentTo(V vecTest)
vecTest
- vector under equivalency testtrue
if the argument is equivalent to this vector,
false
if otherwisepublic V negate()
public void negateEquals()
public void plusEquals(V vecAdd)
vecAdd
- Vector to add to this vector (addend)public V plus(V vecAdd)
vecAdd
- vector added to this one (addend)java.lang.IllegalArgumentException
- argument is not same dimension as thispublic void minusEquals(V vecSub)
vecSub
- Vector to subtract from this vector (subtrahend)public V minus(V vecSub)
vecSub
- vector subtracted from this one (subtrahend)java.lang.IllegalArgumentException
- argument is not same dimension as thispublic V times(double s)
s
- scalar valuepublic void timesEquals(double s)
s
- scalarpublic double innerProd(V v) throws java.lang.IllegalArgumentException
v
- second vectorjava.lang.IllegalArgumentException
- dimensions must agreepublic <M extends SquareMatrix<M>> V leftMultiply(M mat) throws java.lang.IllegalArgumentException
mat
- matrix operatorjava.lang.IllegalArgumentException
- dimensions must agreepublic <M extends SquareMatrix<M>> V rightMultiply(M mat) throws java.lang.IllegalArgumentException
mat
- matrix operatorjava.lang.IllegalArgumentException
- dimensions must agreepublic double norm1()
public double norm2()
public double normInf()
public void save(DataAdaptor daptArchive)
PhaseVector
to disk.save
in interface IArchive
daptArchive
- interface to data sinkIArchive.save(xal.tools.data.DataAdaptor)
public void load(DataAdaptor daptArchive) throws DataFormatException
PhaseVector
from the
contents of a data archive.load
in interface IArchive
daptArchive
- interface to data sourceDataFormatException
- malformed dataIArchive.load(xal.tools.data.DataAdaptor)
public void print()
public void print(java.io.PrintWriter os)
os
- output stream objectpublic void println(java.io.PrintWriter os)
os
- output stream objectprotected abstract V newInstance()
V