org.apache.commons.math.linear

## Class OpenMapRealVector

- java.lang.Object
- - org.apache.commons.math.linear.AbstractRealVector
  - - org.apache.commons.math.linear.OpenMapRealVector

All Implemented Interfaces:
  Serializable, RealVector, SparseRealVector

    public class OpenMapRealVector
    extends AbstractRealVector
    implements SparseRealVector, Serializable

This class implements the `RealVector` interface with a `OpenIntToDoubleHashMap` backing store.

Since:
  2.0
Version:
  $Revision: 1073262 $ $Date: 2011-02-22 10:02:25 +0100 (mar. 22 févr. 2011) $
See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`protected class` `OpenMapRealVector.OpenMapEntry` Implementation of `Entry` optimized for OpenMap.
`protected class` `OpenMapRealVector.OpenMapSparseIterator` Iterator class to do iteration over just the non-zero elements.

### Nested classes/interfaces inherited from class org.apache.commons.math.linear.AbstractRealVector

`AbstractRealVector.EntryImpl, AbstractRealVector.SparseEntryIterator`

### Nested classes/interfaces inherited from interface org.apache.commons.math.linear.RealVector

`RealVector.Entry`

### Field Summary

Fields
`static double` `DEFAULT_ZERO_TOLERANCE` Default Tolerance for having a value considered zero.
`private OpenIntToDoubleHashMap` `entries` Entries of the vector.
`private double` `epsilon` Tolerance for having a value considered zero.
`private static long` `serialVersionUID` Serializable version identifier.
`private int` `virtualSize` Dimension of the vector.

### Constructor Summary

Constructors
`` `OpenMapRealVector()` Build a 0-length vector.
`` `OpenMapRealVector(double[] values)` Create from a double array.
`` `OpenMapRealVector(Double[] values)` Create from a Double array.
`` `OpenMapRealVector(double[] values, double epsilon)` Create from a double array, specifying zero tolerance.
`` `OpenMapRealVector(Double[] values, double epsilon)` Create from a Double array.
`` `OpenMapRealVector(int dimension)` Construct a (dimension)-length vector of zeros.
`` `OpenMapRealVector(int dimension, double epsilon)` Construct a (dimension)-length vector of zeros, specifying zero tolerance.
`` `OpenMapRealVector(int dimension, int expectedSize)` Build a vector with known the sparseness (for advanced use only).
`` `OpenMapRealVector(int dimension, int expectedSize, double epsilon)` Build a vector with known the sparseness and zero tolerance setting (for advanced use only).
`` `OpenMapRealVector(OpenMapRealVector v)` Copy constructor.
`protected` `OpenMapRealVector(OpenMapRealVector v, int resize)` Build a resized vector, for use with append.
`` `OpenMapRealVector(RealVector v)` Generic copy constructor.

### Method Summary

Methods
`OpenMapRealVector` `add(OpenMapRealVector v)` Optimized method to add two OpenMapRealVectors.
`RealVector` `add(RealVector v)` Compute the sum of this vector and `v`.
`OpenMapRealVector` `append(double d)` Construct a vector by appending a double to this vector.
`OpenMapRealVector` `append(double[] a)` Construct a vector by appending a double array to this vector.
`OpenMapRealVector` `append(OpenMapRealVector v)` Optimized method to append a OpenMapRealVector.
`OpenMapRealVector` `append(RealVector v)` Construct a vector by appending a vector to this vector.
`OpenMapRealVector` `copy()` Returns a (deep) copy of this vector.
`double` `dotProduct(OpenMapRealVector v)` Optimized method to compute the dot product with an OpenMapRealVector.
`double` `dotProduct(RealVector v)` Compute the dot product.
`OpenMapRealVector` `ebeDivide(double[] v)` Element-by-element division.
`OpenMapRealVector` `ebeDivide(RealVector v)` Element-by-element division.
`OpenMapRealVector` `ebeMultiply(double[] v)` Element-by-element multiplication.
`OpenMapRealVector` `ebeMultiply(RealVector v)` Element-by-element multiplication.
`boolean` `equals(Object obj)` Implementation Note: This performs an exact comparison, and as a result it is possible for `a.subtract(b`} to be the zero vector, while `a.equals(b) == false`.
`double[]` `getData()` Returns vector entries as a double array.
`int` `getDimension()` Returns the size of the vector.
`double` `getDistance(double[] v)` Distance between two vectors.
`double` `getDistance(OpenMapRealVector v)` Optimized method to compute distance.
`double` `getDistance(RealVector v)` Distance between two vectors.
`private OpenIntToDoubleHashMap` `getEntries()` Get the entries of this instance.
`double` `getEntry(int index)` Returns the entry in the specified index.
`double` `getL1Distance(double[] v)` Distance between two vectors.
`double` `getL1Distance(OpenMapRealVector v)` Distance between two vectors.
`double` `getL1Distance(RealVector v)` Distance between two vectors.
`double` `getLInfDistance(double[] v)` Distance between two vectors.
`private double` `getLInfDistance(OpenMapRealVector v)` Optimized method to compute LInfDistance.
`double` `getLInfDistance(RealVector v)` Distance between two vectors.
`double` `getSparcity()` Deprecated. as of 2.2 replaced by the correctly spelled `getSparsity()`
`double` `getSparsity()`
`OpenMapRealVector` `getSubVector(int index, int n)` Get a subvector from consecutive elements.
`int` `hashCode()`
`protected boolean` `isDefaultValue(double value)` Determine if this value is within epsilon of zero.
`boolean` `isInfinite()` Check whether any coordinate of this vector is infinite and none are `NaN`.
`boolean` `isNaN()` Check whether any coordinate of this vector is `NaN`.
`OpenMapRealVector` `mapAdd(double d)` Add a value to each entry.
`OpenMapRealVector` `mapAddToSelf(double d)` Add a value to each entry.
`RealMatrix` `outerProduct(double[] v)` Compute the outer product.
`OpenMapRealVector` `projection(double[] v)` Find the orthogonal projection of this vector onto another vector.
`RealVector` `projection(RealVector v)` Find the orthogonal projection of this vector onto another vector.
`void` `set(double value)` Set all elements to a single value.
`void` `setEntry(int index, double value)` Set a single element.
`void` `setSubVector(int index, double[] v)` Set a set of consecutive elements.
`void` `setSubVector(int index, RealVector v)` Set a set of consecutive elements.
`Iterator<RealVector.Entry>` `sparseIterator()` Specialized implementations may choose to not iterate over all dimensions, either because those values are unset, or are equal to defaultValue(), or are small enough to be ignored for the purposes of iteration.
`OpenMapRealVector` `subtract(double[] v)` Subtract `v` from this vector.
`OpenMapRealVector` `subtract(OpenMapRealVector v)` Optimized method to subtract OpenMapRealVectors.
`OpenMapRealVector` `subtract(RealVector v)` Subtract `v` from this vector.
`double[]` `toArray()` Convert the vector to a double array.
`void` `unitize()` Converts this vector into a unit vector.
`OpenMapRealVector` `unitVector()` Creates a unit vector pointing in the direction of this vector.

### Methods inherited from class org.apache.commons.math.linear.AbstractRealVector

`add, checkIndex, checkVectorDimensions, checkVectorDimensions, dotProduct, getL1Norm, getLInfNorm, getMaxIndex, getMaxValue, getMinIndex, getMinValue, getNorm, iterator, map, mapAbs, mapAbsToSelf, mapAcos, mapAcosToSelf, mapAsin, mapAsinToSelf, mapAtan, mapAtanToSelf, mapCbrt, mapCbrtToSelf, mapCeil, mapCeilToSelf, mapCos, mapCosh, mapCoshToSelf, mapCosToSelf, mapDivide, mapDivideToSelf, mapExp, mapExpm1, mapExpm1ToSelf, mapExpToSelf, mapFloor, mapFloorToSelf, mapInv, mapInvToSelf, mapLog, mapLog10, mapLog10ToSelf, mapLog1p, mapLog1pToSelf, mapLogToSelf, mapMultiply, mapMultiplyToSelf, mapPow, mapPowToSelf, mapRint, mapRintToSelf, mapSignum, mapSignumToSelf, mapSin, mapSinh, mapSinhToSelf, mapSinToSelf, mapSqrt, mapSqrtToSelf, mapSubtract, mapSubtractToSelf, mapTan, mapTanh, mapTanhToSelf, mapTanToSelf, mapToSelf, mapUlp, mapUlpToSelf, outerProduct`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.commons.math.linear.RealVector

`add, dotProduct, getL1Norm, getLInfNorm, getNorm, iterator, map, mapAbs, mapAbsToSelf, mapAcos, mapAcosToSelf, mapAsin, mapAsinToSelf, mapAtan, mapAtanToSelf, mapCbrt, mapCbrtToSelf, mapCeil, mapCeilToSelf, mapCos, mapCosh, mapCoshToSelf, mapCosToSelf, mapDivide, mapDivideToSelf, mapExp, mapExpm1, mapExpm1ToSelf, mapExpToSelf, mapFloor, mapFloorToSelf, mapInv, mapInvToSelf, mapLog, mapLog10, mapLog10ToSelf, mapLog1p, mapLog1pToSelf, mapLogToSelf, mapMultiply, mapMultiplyToSelf, mapPow, mapPowToSelf, mapRint, mapRintToSelf, mapSignum, mapSignumToSelf, mapSin, mapSinh, mapSinhToSelf, mapSinToSelf, mapSqrt, mapSqrtToSelf, mapSubtract, mapSubtractToSelf, mapTan, mapTanh, mapTanhToSelf, mapTanToSelf, mapToSelf, mapUlp, mapUlpToSelf, outerProduct`

### Field Detail

#### DEFAULT_ZERO_TOLERANCE

    public static final double DEFAULT_ZERO_TOLERANCE

Default Tolerance for having a value considered zero.

See Also:
  Constant Field Values

#### serialVersionUID

    private static final long serialVersionUID

Serializable version identifier.

See Also:
  Constant Field Values

#### entries

    private final OpenIntToDoubleHashMap entries

Entries of the vector.

#### virtualSize

    private final int virtualSize

Dimension of the vector.

#### epsilon

    private final double epsilon

Tolerance for having a value considered zero.

### Constructor Detail

#### OpenMapRealVector

    public OpenMapRealVector()

Build a 0-length vector.

Zero-length vectors may be used to initialized construction of vectors by data gathering. We start with zero-length and use either the `OpenMapRealVector(OpenMapRealVector, int)` constructor or one of the `append` method (`append(double)`, `append(double[])`, `append(RealVector)`) to gather data into this vector.

#### OpenMapRealVector

    public OpenMapRealVector(int dimension)

Construct a (dimension)-length vector of zeros.

Parameters:
  `dimension` - size of the vector

#### OpenMapRealVector

    public OpenMapRealVector(int dimension,
                     double epsilon)

Construct a (dimension)-length vector of zeros, specifying zero tolerance.

Parameters:
  `dimension` - Size of the vector
  `epsilon` - The tolerance for having a value considered zero

#### OpenMapRealVector

    protected OpenMapRealVector(OpenMapRealVector v,
                     int resize)

Build a resized vector, for use with append.

Parameters:
  `v` - The original vector
  `resize` - The amount to resize it

#### OpenMapRealVector

    public OpenMapRealVector(int dimension,
                     int expectedSize)

Build a vector with known the sparseness (for advanced use only).

Parameters:
  `dimension` - The size of the vector
  `expectedSize` - The expected number of non-zero entries

#### OpenMapRealVector

    public OpenMapRealVector(int dimension,
                     int expectedSize,
                     double epsilon)

Build a vector with known the sparseness and zero tolerance setting (for advanced use only).

Parameters:
  `dimension` - The size of the vector
  `expectedSize` - The expected number of non-zero entries
  `epsilon` - The tolerance for having a value considered zero

#### OpenMapRealVector

    public OpenMapRealVector(double[] values)

Create from a double array. Only non-zero entries will be stored

Parameters:
  `values` - The set of values to create from

#### OpenMapRealVector

    public OpenMapRealVector(double[] values,
                     double epsilon)

Create from a double array, specifying zero tolerance. Only non-zero entries will be stored

Parameters:
  `values` - The set of values to create from
  `epsilon` - The tolerance for having a value considered zero

#### OpenMapRealVector

    public OpenMapRealVector(Double[] values)

Create from a Double array. Only non-zero entries will be stored

Parameters:
  `values` - The set of values to create from

#### OpenMapRealVector

    public OpenMapRealVector(Double[] values,
                     double epsilon)

Create from a Double array. Only non-zero entries will be stored

Parameters:
  `values` - The set of values to create from
  `epsilon` - The tolerance for having a value considered zero

#### OpenMapRealVector

    public OpenMapRealVector(OpenMapRealVector v)

Copy constructor.

Parameters:
  `v` - The instance to copy from

#### OpenMapRealVector

    public OpenMapRealVector(RealVector v)

Generic copy constructor.

Parameters:
  `v` - The instance to copy from

### Method Detail

#### getEntries

    private OpenIntToDoubleHashMap getEntries()

Get the entries of this instance.

Returns:
  entries of this instance

#### isDefaultValue

    protected boolean isDefaultValue(double value)

Determine if this value is within epsilon of zero.

Parameters:
  `value` - The value to test
Returns:
  `true` if this value is within epsilon to zero, `false` otherwise
Since:
  2.1

#### add

    public RealVector add(RealVector v)
                   throws IllegalArgumentException

Compute the sum of this vector and `v`.

Specified by:
  `add` in interface `RealVector`
Overrides:
  `add` in class `AbstractRealVector`
Parameters:
  `v` - Vector to be added.
Returns:
  `this` + `v`.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### add

    public OpenMapRealVector add(OpenMapRealVector v)
                          throws IllegalArgumentException

Optimized method to add two OpenMapRealVectors. Copies the larger vector, iterates over the smaller.

Parameters:
  `v` - Vector to add with
Returns:
  The sum of `this` with `v`
Throws:
  `IllegalArgumentException` - If the dimensions don't match

#### append

    public OpenMapRealVector append(OpenMapRealVector v)

Optimized method to append a OpenMapRealVector.

Parameters:
  `v` - vector to append
Returns:
  The result of appending `v` to self

#### append

    public OpenMapRealVector append(RealVector v)

Construct a vector by appending a vector to this vector.

Specified by:
  `append` in interface `RealVector`
Parameters:
  `v` - vector to append to this one.
Returns:
  a new vector

#### append

    public OpenMapRealVector append(double d)

Construct a vector by appending a double to this vector.

Specified by:
  `append` in interface `RealVector`
Parameters:
  `d` - double to append.
Returns:
  a new vector

#### append

    public OpenMapRealVector append(double[] a)

Construct a vector by appending a double array to this vector.

Specified by:
  `append` in interface `RealVector`
Parameters:
  `a` - double array to append.
Returns:
  a new vector

#### copy

    public OpenMapRealVector copy()

Returns a (deep) copy of this vector.

Specified by:
  `copy` in interface `RealVector`
Specified by:
  `copy` in class `AbstractRealVector`
Returns:
  a vector copy.
Since:
  2.1

#### dotProduct

    public double dotProduct(OpenMapRealVector v)
                      throws IllegalArgumentException

Optimized method to compute the dot product with an OpenMapRealVector. Iterates over the smaller of the two.

Parameters:
  `v` - The vector to compute the dot product with
Returns:
  The dot product of `this` and `v`
Throws:
  `IllegalArgumentException` - If the dimensions don't match

#### dotProduct

    public double dotProduct(RealVector v)
                      throws IllegalArgumentException

Compute the dot product.

Specified by:
  `dotProduct` in interface `RealVector`
Overrides:
  `dotProduct` in class `AbstractRealVector`
Parameters:
  `v` - vector with which dot product should be computed
Returns:
  the scalar dot product between instance and v
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### ebeDivide

    public OpenMapRealVector ebeDivide(RealVector v)
                                throws IllegalArgumentException

Element-by-element division.

Specified by:
  `ebeDivide` in interface `RealVector`
Parameters:
  `v` - vector by which instance elements must be divided
Returns:
  a vector containing this[i] / v[i] for all i
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### ebeDivide

    public OpenMapRealVector ebeDivide(double[] v)
                                throws IllegalArgumentException

Element-by-element division.

Specified by:
  `ebeDivide` in interface `RealVector`
Overrides:
  `ebeDivide` in class `AbstractRealVector`
Parameters:
  `v` - vector by which instance elements must be divided
Returns:
  a vector containing this[i] / v[i] for all i
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### ebeMultiply

    public OpenMapRealVector ebeMultiply(RealVector v)
                                  throws IllegalArgumentException

Element-by-element multiplication.

Specified by:
  `ebeMultiply` in interface `RealVector`
Parameters:
  `v` - vector by which instance elements must be multiplied
Returns:
  a vector containing this[i] * v[i] for all i
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### ebeMultiply

    public OpenMapRealVector ebeMultiply(double[] v)
                                  throws IllegalArgumentException

Element-by-element multiplication.

Specified by:
  `ebeMultiply` in interface `RealVector`
Overrides:
  `ebeMultiply` in class `AbstractRealVector`
Parameters:
  `v` - vector by which instance elements must be multiplied
Returns:
  a vector containing this[i] * v[i] for all i
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### getSubVector

    public OpenMapRealVector getSubVector(int index,
                                 int n)
                                   throws MatrixIndexException

Get a subvector from consecutive elements.

Specified by:
  `getSubVector` in interface `RealVector`
Parameters:
  `index` - index of first element.
  `n` - number of elements to be retrieved.
Returns:
  a vector containing n elements.
Throws:
  `MatrixIndexException`

#### getData

    public double[] getData()

Returns vector entries as a double array.

Specified by:
  `getData` in interface `RealVector`
Overrides:
  `getData` in class `AbstractRealVector`
Returns:
  double array of entries

#### getDimension

    public int getDimension()

Returns the size of the vector.

Specified by:
  `getDimension` in interface `RealVector`
Returns:
  size

#### getDistance

    public double getDistance(OpenMapRealVector v)
                       throws IllegalArgumentException

Optimized method to compute distance.

Parameters:
  `v` - The vector to compute distance to
Returns:
  The distance from `this` and `v`
Throws:
  `IllegalArgumentException` - If the dimensions don't match

#### getDistance

    public double getDistance(RealVector v)
                       throws IllegalArgumentException

Distance between two vectors.

This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.

Specified by:
  `getDistance` in interface `RealVector`
Overrides:
  `getDistance` in class `AbstractRealVector`
Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`
See Also:
  `RealVector.getL1Distance(RealVector)`, `RealVector.getLInfDistance(RealVector)`, `RealVector.getNorm()`

#### getDistance

    public double getDistance(double[] v)
                       throws IllegalArgumentException

Distance between two vectors.

This method computes the distance consistent with the L2 norm, i.e. the square root of the sum of elements differences, or euclidian distance.

Specified by:
  `getDistance` in interface `RealVector`
Overrides:
  `getDistance` in class `AbstractRealVector`
Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`
See Also:
  `RealVector.getL1Distance(double[])`, `RealVector.getLInfDistance(double[])`, `RealVector.getNorm()`

#### getEntry

    public double getEntry(int index)
                    throws MatrixIndexException

Returns the entry in the specified index.

Specified by:
  `getEntry` in interface `RealVector`
Parameters:
  `index` - Index location of entry to be fetched.
Returns:
  the vector entry at `index`.
Throws:
  `MatrixIndexException`
See Also:
  `RealVector.setEntry(int, double)`

#### getL1Distance

    public double getL1Distance(OpenMapRealVector v)

Distance between two vectors.

This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.

Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.

#### getL1Distance

    public double getL1Distance(RealVector v)
                         throws IllegalArgumentException

Distance between two vectors.

This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.

Specified by:
  `getL1Distance` in interface `RealVector`
Overrides:
  `getL1Distance` in class `AbstractRealVector`
Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`
See Also:
  `RealVector.getDistance(RealVector)`, `RealVector.getLInfDistance(RealVector)`, `RealVector.getL1Norm()`

#### getL1Distance

    public double getL1Distance(double[] v)
                         throws IllegalArgumentException

Distance between two vectors.

This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.

Specified by:
  `getL1Distance` in interface `RealVector`
Overrides:
  `getL1Distance` in class `AbstractRealVector`
Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`
See Also:
  `RealVector.getDistance(double[])`, `RealVector.getLInfDistance(double[])`, `RealVector.getL1Norm()`

#### getLInfDistance

    private double getLInfDistance(OpenMapRealVector v)

Optimized method to compute LInfDistance.

Parameters:
  `v` - The vector to compute from
Returns:
  the LInfDistance

#### getLInfDistance

    public double getLInfDistance(RealVector v)
                           throws IllegalArgumentException

Distance between two vectors.

This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.

Specified by:
  `getLInfDistance` in interface `RealVector`
Overrides:
  `getLInfDistance` in class `AbstractRealVector`
Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`
See Also:
  `RealVector.getDistance(RealVector)`, `RealVector.getL1Distance(RealVector)`, `RealVector.getLInfNorm()`

#### getLInfDistance

    public double getLInfDistance(double[] v)
                           throws IllegalArgumentException

Distance between two vectors.

This method computes the distance consistent with L∞ norm, i.e. the max of the absolute values of elements differences.

Specified by:
  `getLInfDistance` in interface `RealVector`
Overrides:
  `getLInfDistance` in class `AbstractRealVector`
Parameters:
  `v` - vector to which distance is requested
Returns:
  distance between two vectors.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`
See Also:
  `RealVector.getDistance(double[])`, `RealVector.getL1Distance(double[])`, `RealVector.getLInfNorm()`

#### isInfinite

    public boolean isInfinite()

Check whether any coordinate of this vector is infinite and none are `NaN`.

Specified by:
  `isInfinite` in interface `RealVector`
Returns:
  `true` if any coordinate of this vector is infinite and none are `NaN`, `false` otherwise.

#### isNaN

    public boolean isNaN()

Check whether any coordinate of this vector is `NaN`.

Specified by:
  `isNaN` in interface `RealVector`
Returns:
  `true` if any coordinate of this vector is `NaN`, `false` otherwise.

#### mapAdd

    public OpenMapRealVector mapAdd(double d)

Add a value to each entry.

Specified by:
  `mapAdd` in interface `RealVector`
Overrides:
  `mapAdd` in class `AbstractRealVector`
Parameters:
  `d` - Value to be added to each entry.
Returns:
  `this` + `d`.

#### mapAddToSelf

    public OpenMapRealVector mapAddToSelf(double d)

Add a value to each entry. The instance is changed in-place.

Specified by:
  `mapAddToSelf` in interface `RealVector`
Overrides:
  `mapAddToSelf` in class `AbstractRealVector`
Parameters:
  `d` - Value to be added to each entry.
Returns:
  `this`.

#### outerProduct

    public RealMatrix outerProduct(double[] v)
                            throws IllegalArgumentException

Compute the outer product.

Specified by:
  `outerProduct` in interface `RealVector`
Overrides:
  `outerProduct` in class `AbstractRealVector`
Parameters:
  `v` - vector with which outer product should be computed
Returns:
  the square matrix outer product between instance and v
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### projection

    public RealVector projection(RealVector v)
                          throws IllegalArgumentException

Find the orthogonal projection of this vector onto another vector.

Specified by:
  `projection` in interface `RealVector`
Parameters:
  `v` - vector onto which instance must be projected
Returns:
  projection of the instance onto v
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### projection

    public OpenMapRealVector projection(double[] v)
                                 throws IllegalArgumentException

Find the orthogonal projection of this vector onto another vector.

Specified by:
  `projection` in interface `RealVector`
Overrides:
  `projection` in class `AbstractRealVector`
Parameters:
  `v` - vector onto which instance must be projected
Returns:
  projection of the instance onto v
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### setEntry

    public void setEntry(int index,
                double value)
                  throws MatrixIndexException

Set a single element.

Specified by:
  `setEntry` in interface `RealVector`
Parameters:
  `index` - element index.
  `value` - new value for the element.
Throws:
  `MatrixIndexException`
See Also:
  `RealVector.getEntry(int)`

#### setSubVector

    public void setSubVector(int index,
                    RealVector v)
                      throws MatrixIndexException

Set a set of consecutive elements.

Specified by:
  `setSubVector` in interface `RealVector`
Overrides:
  `setSubVector` in class `AbstractRealVector`
Parameters:
  `index` - index of first element to be set.
  `v` - vector containing the values to set.
Throws:
  `MatrixIndexException`
See Also:
  `RealVector.setSubVector(int, double[])`

#### setSubVector

    public void setSubVector(int index,
                    double[] v)
                      throws MatrixIndexException

Set a set of consecutive elements.

Specified by:
  `setSubVector` in interface `RealVector`
Overrides:
  `setSubVector` in class `AbstractRealVector`
Parameters:
  `index` - index of first element to be set.
  `v` - vector containing the values to set.
Throws:
  `MatrixIndexException`
See Also:
  `RealVector.setSubVector(int, RealVector)`

#### set

    public void set(double value)

Set all elements to a single value.

Specified by:
  `set` in interface `RealVector`
Overrides:
  `set` in class `AbstractRealVector`
Parameters:
  `value` - single value to set for all elements

#### subtract

    public OpenMapRealVector subtract(OpenMapRealVector v)
                               throws IllegalArgumentException

Optimized method to subtract OpenMapRealVectors.

Parameters:
  `v` - The vector to subtract from `this`
Returns:
  The difference of `this` and `v`
Throws:
  `IllegalArgumentException` - If the dimensions don't match

#### subtract

    public OpenMapRealVector subtract(RealVector v)
                               throws IllegalArgumentException

Subtract `v` from this vector.

Specified by:
  `subtract` in interface `RealVector`
Overrides:
  `subtract` in class `AbstractRealVector`
Parameters:
  `v` - Vector to be subtracted.
Returns:
  `this` - `v`.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### subtract

    public OpenMapRealVector subtract(double[] v)
                               throws IllegalArgumentException

Subtract `v` from this vector.

Specified by:
  `subtract` in interface `RealVector`
Overrides:
  `subtract` in class `AbstractRealVector`
Parameters:
  `v` - Vector to be subtracted.
Returns:
  `this` - `v`.
Throws:
  `DimensionMismatchException` - if `v` is not the same size as this vector.
  `IllegalArgumentException`

#### unitVector

    public OpenMapRealVector unitVector()

Creates a unit vector pointing in the direction of this vector.

The instance is not changed by this method.

Specified by:
  `unitVector` in interface `RealVector`
Overrides:
  `unitVector` in class `AbstractRealVector`
Returns:
  a unit vector pointing in direction of this vector

#### unitize

    public void unitize()

Converts this vector into a unit vector.

The instance itself is changed by this method.

Specified by:
  `unitize` in interface `RealVector`
Overrides:
  `unitize` in class `AbstractRealVector`

#### toArray

    public double[] toArray()

Convert the vector to a double array.

The array is independent from vector data, it's elements are copied.

Specified by:
  `toArray` in interface `RealVector`
Overrides:
  `toArray` in class `AbstractRealVector`
Returns:
  array containing a copy of vector elements

#### hashCode

    public int hashCode()

Implementation Note: This works on exact values, and as a result it is possible for `a.subtract(b)` to be the zero vector, while `a.hashCode() != b.hashCode()`.

Overrides:
  `hashCode` in class `Object`

#### equals

    public boolean equals(Object obj)

Implementation Note: This performs an exact comparison, and as a result it is possible for `a.subtract(b`} to be the zero vector, while `a.equals(b) == false`.

Overrides:
  `equals` in class `Object`

#### getSparcity

    @Deprecated
    public double getSparcity()

Deprecated. as of 2.2 replaced by the correctly spelled `getSparsity()`

Returns:
  the percentage of none zero elements as a decimal percent.

#### getSparsity

    public double getSparsity()

Returns:
  the percentage of none zero elements as a decimal percent.
Since:
  2.2

#### sparseIterator

    public Iterator<RealVector.Entry> sparseIterator()

Specialized implementations may choose to not iterate over all dimensions, either because those values are unset, or are equal to defaultValue(), or are small enough to be ignored for the purposes of iteration. No guarantees are made about order of iteration. In dense implementations, this method will often delegate to `RealVector.iterator()`.

Specified by:
  `sparseIterator` in interface `RealVector`
Overrides:
  `sparseIterator` in class `AbstractRealVector`
Returns:
  a sparse iterator