org.jscience.mathematics.algebraic.matrices
Class IntegerSparseVector

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.AbstractVector
              extended by org.jscience.mathematics.algebraic.matrices.AbstractIntegerVector
                  extended by org.jscience.mathematics.algebraic.matrices.IntegerSparseVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Vector, Member

public class IntegerSparseVector
extends AbstractIntegerVector
implements java.lang.Cloneable, java.io.Serializable

The IntegerSparseVector class encapsulates sparse vectors. Uses Morse-coding.

See Also:
Serialized Form

Constructor Summary
IntegerSparseVector(AbstractIntegerVector vec)
          Constructs a vector by copying a vector.
IntegerSparseVector(int dim)
          Constructs an empty vector.
IntegerSparseVector(int[] array)
          Constructs a vector from an array.
 
Method Summary
 AbelianGroup.Member add(AbelianGroup.Member v)
          Returns the addition of this vector and another.
 AbstractIntegerVector add(AbstractIntegerVector v)
          Returns the addition of this vector and another.
 IntegerSparseVector add(IntegerSparseVector v)
          Returns the addition of this vector and another.
 IntegerVector add(IntegerVector v)
          DOCUMENT ME!
 java.lang.Object clone()
          Clone vector into a new vector.
 boolean equals(java.lang.Object obj, double tol)
          Compares two vectors for equality.
 int getPrimitiveElement(int n)
          Returns a component of this vector.
 AbstractDoubleVector mapElements(PrimitiveMapping f)
          Applies a function on all the vector components.
 int mass()
          Returns the mass.
 AbelianGroup.Member negate()
          Returns the negative of this vector.
 double norm()
          Returns the l2-norm (magnitude).
 AbstractIntegerVector scalarMultiply(int x)
          Returns the multiplication of this vector by a scalar.
 Module.Member scalarMultiply(Ring.Member x)
          Returns the multiplication of this vector by a scalar.
 int scalarProduct(AbstractIntegerVector v)
          Returns the scalar product of this vector and another.
 int scalarProduct(IntegerSparseVector v)
          Returns the scalar product of this vector and another.
 int scalarProduct(IntegerVector v)
          DOCUMENT ME!
 void setElement(int n, int x)
          Sets the value of a component of this vector.
 void setElements(int r)
          Sets the value of all elements of the vector.
 AbelianGroup.Member subtract(AbelianGroup.Member v)
          Returns the subtraction of this vector by another.
 AbstractIntegerVector subtract(AbstractIntegerVector v)
          Returns the subtraction of this vector by another.
 IntegerSparseVector subtract(IntegerSparseVector v)
          Returns the subtraction of this vector by another.
 IntegerVector subtract(IntegerVector v)
          DOCUMENT ME!
 int sumSquares()
          Returns the sum of the squares of the components.
 IntegerSparseMatrix tensorProduct(IntegerSparseVector v)
          Returns the tensor product of this vector and another.
 AbstractComplexVector toComplexVector()
          Converts this vector to a complex vector.
 AbstractDoubleVector toDoubleVector()
          Converts this vector to a double vector.
 int[] toPrimitiveArray()
          Projects the vector to an array.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractIntegerVector
abs, equals, getColumn, getElement, getRow, getSubVector, hashCode, infNorm, max, mean, min, multiply, norm, read, reverse, scalarDivide, setAllElements, setColumn, setElement, setRow, setSubVector, standardDeviation, tensorProduct, toMatrix, toString, transpose, variance
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractVector
getDimension, getElement, getInvalidElementMsg, toArray, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Matrix
numColumns, numRows, toArray
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, getElement, numDimensions, numElements, numElements, toArray
 

Constructor Detail

IntegerSparseVector

public IntegerSparseVector(int dim)
Constructs an empty vector.

Parameters:
dim - the dimension of the vector.

IntegerSparseVector

public IntegerSparseVector(int[] array)
Constructs a vector from an array.

Parameters:
array - DOCUMENT ME!

IntegerSparseVector

public IntegerSparseVector(AbstractIntegerVector vec)
Constructs a vector by copying a vector.

Parameters:
vec - an assigned value
Method Detail

equals

public boolean equals(java.lang.Object obj,
                      double tol)
Compares two vectors for equality.

Overrides:
equals in class AbstractIntegerVector
Parameters:
obj - a Integer sparse vector
tol - DOCUMENT ME!
Returns:
DOCUMENT ME!

toDoubleVector

public AbstractDoubleVector toDoubleVector()
Converts this vector to a double vector.

Overrides:
toDoubleVector in class AbstractIntegerVector
Returns:
a double vector

toComplexVector

public AbstractComplexVector toComplexVector()
Converts this vector to a complex vector.

Overrides:
toComplexVector in class AbstractIntegerVector
Returns:
a complex vector

getPrimitiveElement

public int getPrimitiveElement(int n)
Returns a component of this vector.

Specified by:
getPrimitiveElement in class AbstractIntegerVector
Parameters:
n - index of the vector component
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If attempting to access an invalid component.

setElement

public void setElement(int n,
                       int x)
Sets the value of a component of this vector.

Specified by:
setElement in class AbstractIntegerVector
Parameters:
n - index of the vector component
x - a number
Throws:
IllegalDimensionException - If attempting to access an invalid component.

setElements

public void setElements(int r)
Sets the value of all elements of the vector. You should think about using a IntegerVector.

Parameters:
r - a int element

norm

public double norm()
Returns the l2-norm (magnitude).

Overrides:
norm in class AbstractIntegerVector
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

sumSquares

public int sumSquares()
Returns the sum of the squares of the components.

Overrides:
sumSquares in class AbstractIntegerVector
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

mass

public int mass()
Returns the mass.

Overrides:
mass in class AbstractIntegerVector
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

negate

public AbelianGroup.Member negate()
Returns the negative of this vector.

Specified by:
negate in interface AbelianGroup.Member
Returns:
DOCUMENT ME!

add

public AbelianGroup.Member add(AbelianGroup.Member v)
Returns the addition of this vector and another.

Specified by:
add in interface AbelianGroup.Member
Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

add

public AbstractIntegerVector add(AbstractIntegerVector v)
Returns the addition of this vector and another.

Overrides:
add in class AbstractIntegerVector
Parameters:
v - an integer vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

add

public IntegerVector add(IntegerVector v)
DOCUMENT ME!

Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

add

public IntegerSparseVector add(IntegerSparseVector v)
Returns the addition of this vector and another.

Parameters:
v - an integer sparse vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

subtract

public AbelianGroup.Member subtract(AbelianGroup.Member v)
Returns the subtraction of this vector by another.

Specified by:
subtract in interface AbelianGroup.Member
Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

subtract

public AbstractIntegerVector subtract(AbstractIntegerVector v)
Returns the subtraction of this vector by another.

Overrides:
subtract in class AbstractIntegerVector
Parameters:
v - an integer vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

subtract

public IntegerVector subtract(IntegerVector v)
DOCUMENT ME!

Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

subtract

public IntegerSparseVector subtract(IntegerSparseVector v)
Returns the subtraction of this vector by another.

Parameters:
v - an integer sparse vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

scalarMultiply

public Module.Member scalarMultiply(Ring.Member x)
Returns the multiplication of this vector by a scalar.

Specified by:
scalarMultiply in interface Module.Member
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

scalarMultiply

public AbstractIntegerVector scalarMultiply(int x)
Returns the multiplication of this vector by a scalar.

Overrides:
scalarMultiply in class AbstractIntegerVector
Parameters:
x - an integer
Returns:
DOCUMENT ME!

scalarProduct

public int scalarProduct(AbstractIntegerVector v)
Returns the scalar product of this vector and another.

Overrides:
scalarProduct in class AbstractIntegerVector
Parameters:
v - an integer vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

scalarProduct

public int scalarProduct(IntegerVector v)
DOCUMENT ME!

Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

scalarProduct

public int scalarProduct(IntegerSparseVector v)
Returns the scalar product of this vector and another.

Parameters:
v - an integer sparse vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

tensorProduct

public IntegerSparseMatrix tensorProduct(IntegerSparseVector v)
Returns the tensor product of this vector and another.

Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!

mapElements

public AbstractDoubleVector mapElements(PrimitiveMapping f)
Applies a function on all the vector components.

Overrides:
mapElements in class AbstractIntegerVector
Parameters:
f - a user-defined function
Returns:
an integer sparse vector

toPrimitiveArray

public int[] toPrimitiveArray()
Projects the vector to an array.

Overrides:
toPrimitiveArray in class AbstractIntegerVector
Returns:
an integer array.

clone

public java.lang.Object clone()
Clone vector into a new vector.

Overrides:
clone in class java.lang.Object
Returns:
the cloned vector.