Top Description Fields Constructors Methods
org.apache.commons.math3.linear

public Class ArrayRealVector

extends RealVector
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.Arrays, .Iterator, org.apache.commons.math3.analysis.UnivariateFunction, org.apache.commons.math3.exception.NotPositiveException, .NullArgumentException, .DimensionMismatchException, .NumberIsTooLargeException, .NumberIsTooSmallException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.MathUtils, .FastMath

This class implements the RealVector interface with a double array.
Since
2.0

Field Summary

Modifier and TypeField and Description
private double[]
data

Entries of the vector.

private static final RealVectorFormat
DEFAULT_FORMAT

Default format.

private static final long
serialVersionUID

Serializable version identifier.

Constructor Summary

AccessConstructor and Description
public
ArrayRealVector()

Build a 0-length vector.

public
ArrayRealVector(int
Size of the vector.
size
)

Construct a vector of zeroes.

public
ArrayRealVector(int
Size of the vector
size
,
double
All entries will be set with this value.
preset
)

Construct a vector with preset values.

public
ArrayRealVector(double[]
Array.
d
)

Construct a vector from an array, copying the input array.

public
ArrayRealVector(double[]
Data for the new vector.
d
,
boolean
if true, the input array will be copied, otherwise it will be referenced.
copyArray
)

Create a new ArrayRealVector using the input array as the underlying data array.

public
ArrayRealVector(double[]
Array.
d
,
int
Position of first entry.
pos
,
int
Number of entries to copy.
size
)

Construct a vector from part of a array.

public
ArrayRealVector(Double[]
Array of Doubles.
d
)

Construct a vector from an array.

public
ArrayRealVector(Double[]
Array.
d
,
int
Position of first entry.
pos
,
int
Number of entries to copy.
size
)

Construct a vector from part of an array.

public
ArrayRealVector(RealVector
vector to copy.
v
)

Construct a vector from another vector, using a deep copy.

public
ArrayRealVector(ArrayRealVector
Vector to copy.
v
)

Construct a vector from another vector, using a deep copy.

public
ArrayRealVector(ArrayRealVector
Vector to copy.
v
,
boolean
If true perform a deep copy, otherwise perform a shallow copy.
deep
)

Construct a vector from another vector.

public
ArrayRealVector(ArrayRealVector
First vector (will be put in front of the new vector).
v1
,
ArrayRealVector
Second vector (will be put at back of the new vector).
v2
)

Construct a vector by appending one vector to another vector.

public
ArrayRealVector(ArrayRealVector
First vector (will be put in front of the new vector).
v1
,
RealVector
Second vector (will be put at back of the new vector).
v2
)

Construct a vector by appending one vector to another vector.

public
ArrayRealVector(RealVector
First vector (will be put in front of the new vector).
v1
,
ArrayRealVector
Second vector (will be put at back of the new vector).
v2
)

Construct a vector by appending one vector to another vector.

public
ArrayRealVector(ArrayRealVector
First vector (will be put in front of the new vector).
v1
,
double[]
Second vector (will be put at back of the new vector).
v2
)

Construct a vector by appending one vector to another vector.

public
ArrayRealVector(double[]
First vector (will be put in front of the new vector).
v1
,
ArrayRealVector
Second vector (will be put at back of the new vector).
v2
)

Construct a vector by appending one vector to another vector.

public
ArrayRealVector(double[]
first vector (will be put in front of the new vector)
v1
,
double[]
second vector (will be put at back of the new vector)
v2
)

Construct a vector by appending one vector to another vector.

Method Summary

Modifier and TypeMethod and Description
public ArrayRealVector
add(RealVector
Vector to be added.
v
)

Overrides org.apache.commons.math3.linear.RealVector.add.

Compute the sum of this vector and v.

public void
addToEntry(int
Index location of entry to be set.
index
,
double
Value to add to the vector entry.
increment
)

Overrides org.apache.commons.math3.linear.RealVector.addToEntry.

Change an entry at the specified index.

public RealVector
append(RealVector
vector to append to this one.
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.append.

Construct a new vector by appending a vector to this vector.

public ArrayRealVector

Returns:

a new vector.
append
(ArrayRealVector
Vector to append to this one.
v
)

Construct a vector by appending a vector to this vector.

public RealVector
append(double
double to append.
in
)

Implements abstract org.apache.commons.math3.linear.RealVector.append.

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

protected void
checkVectorDimensions(RealVector
Vector to compare instance with.
v
)

Overrides org.apache.commons.math3.linear.RealVector.checkVectorDimensions.

Check if instance and specified vectors have the same dimension.

protected void
checkVectorDimensions(int
Expected dimension.
n
)

Overrides org.apache.commons.math3.linear.RealVector.checkVectorDimensions.

Check if instance dimension is equal to some expected value.

public ArrayRealVector
combine(double
Coefficient of this.
a
,
double
Coefficient of y.
b
,
RealVector
Vector with which this is linearly combined.
y
)

Overrides org.apache.commons.math3.linear.RealVector.combine.

Returns a new vector representing a * this + b * y, the linear combination of this and y.

public ArrayRealVector
combineToSelf(double
Weight of this.
a
,
double
Weight of y.
b
,
RealVector
Vector with which this is linearly combined.
y
)

Overrides org.apache.commons.math3.linear.RealVector.combineToSelf.

Updates this with the linear combination of this and y.

public ArrayRealVector
copy()

Implements abstract org.apache.commons.math3.linear.RealVector.copy.

Returns a (deep) copy of this vector.

public double
dotProduct(RealVector
Vector with which dot product should be computed
v
)

Overrides org.apache.commons.math3.linear.RealVector.dotProduct.

Compute the dot product of this vector with v.

public ArrayRealVector
ebeDivide(RealVector
Vector by which instance elements must be divided.
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.ebeDivide.

Element-by-element division.

public ArrayRealVector
ebeMultiply(RealVector
Vector by which instance elements must be multiplied
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.ebeMultiply.

Element-by-element multiplication.

public boolean
equals(Object
Object to test for equality.
other
)

Overrides org.apache.commons.math3.linear.RealVector.equals.

Test for the equality of two real vectors.

public double[]

Returns:

the array of entries.
getDataRef
()

Get a reference to the underlying data array.

public int
getDimension()

Implements abstract org.apache.commons.math3.linear.RealVector.getDimension.

Returns the size of the vector.

public double
getDistance(RealVector
Vector to which distance is requested.
v
)

Overrides org.apache.commons.math3.linear.RealVector.getDistance.

Distance between two vectors.

public double
getEntry(int
Index location of entry to be fetched.
index
)

Implements abstract org.apache.commons.math3.linear.RealVector.getEntry.

Return the entry at the specified index.

public double
getL1Distance(RealVector
Vector to which distance is requested.
v
)

Overrides org.apache.commons.math3.linear.RealVector.getL1Distance.

Distance between two vectors.

public double
getL1Norm()

Overrides org.apache.commons.math3.linear.RealVector.getL1Norm.

Returns the L1 norm of the vector.

public double
getLInfDistance(RealVector
Vector to which distance is requested.
v
)

Overrides org.apache.commons.math3.linear.RealVector.getLInfDistance.

Distance between two vectors.

public double
getLInfNorm()

Overrides org.apache.commons.math3.linear.RealVector.getLInfNorm.

Returns the L∞ norm of the vector.

public double
getNorm()

Overrides org.apache.commons.math3.linear.RealVector.getNorm.

Returns the L2 norm of the vector.

public RealVector
getSubVector(int
index of first element.
index
,
int
number of elements to be retrieved.
n
)

Implements abstract org.apache.commons.math3.linear.RealVector.getSubVector.

Get a subvector from consecutive elements.

public int
hashCode()

Overrides org.apache.commons.math3.linear.RealVector.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if any coordinate of this vector is infinite and none are NaN, false otherwise.
isInfinite
()

Implements abstract org.apache.commons.math3.linear.RealVector.isInfinite.

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

public boolean

Returns:

true if any coordinate of this vector is NaN, false otherwise.
isNaN
()

Implements abstract org.apache.commons.math3.linear.RealVector.isNaN.

Check if any coordinate of this vector is NaN.

public ArrayRealVector
map(UnivariateFunction
Function to apply to each entry.
function
)

Overrides org.apache.commons.math3.linear.RealVector.map.

Acts as if implemented as:

 return copy().mapToSelf(function);
public RealVector
mapAddToSelf(double
Value to be added to each entry.
d
)

Overrides org.apache.commons.math3.linear.RealVector.mapAddToSelf.

Add a value to each entry.

public RealVector
mapDivideToSelf(double
Value to divide by.
d
)

Overrides org.apache.commons.math3.linear.RealVector.mapDivideToSelf.

Divide each entry by the argument.

public RealVector
mapMultiplyToSelf(double
Multiplication factor.
d
)

Overrides org.apache.commons.math3.linear.RealVector.mapMultiplyToSelf.

Multiply each entry.

public RealVector
mapSubtractToSelf(double
Value to be subtracted.
d
)

Overrides org.apache.commons.math3.linear.RealVector.mapSubtractToSelf.

Subtract a value from each entry.

public ArrayRealVector
mapToSelf(UnivariateFunction
Function to apply to each entry.
function
)

Overrides org.apache.commons.math3.linear.RealVector.mapToSelf.

Acts as if it is implemented as:

 Entry e = null;
 for(Iterator<entry> it = iterator(); it.hasNext(); e = it.next()) {
     e.setValue(function.value(e.getValue()));
 }
public RealMatrix
outerProduct(RealVector
Vector with which outer product should be computed.
v
)

Overrides org.apache.commons.math3.linear.RealVector.outerProduct.

Compute the outer product.

public void
set(double
Single value to set for all elements.
value
)

Overrides org.apache.commons.math3.linear.RealVector.set.

Set all elements to a single value.

public void
setEntry(int
element index.
index
,
double
new value for the element.
value
)

Implements abstract org.apache.commons.math3.linear.RealVector.setEntry.

Set a single element.

public void
setSubVector(int
index of first element to be set.
index
,
RealVector
vector containing the values to set.
v
)

Implements abstract org.apache.commons.math3.linear.RealVector.setSubVector.

Set a sequence of consecutive elements.

public void
setSubVector(int
Index of first element to be set.
index
,
double[]
Vector containing the values to set.
v
)

Set a set of consecutive elements.

public ArrayRealVector
subtract(RealVector
Vector to be subtracted.
v
)

Overrides org.apache.commons.math3.linear.RealVector.subtract.

Subtract v from this vector.

public double[]
toArray()

Overrides org.apache.commons.math3.linear.RealVector.toArray.

Convert the vector to an array of doubles.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public double
walkInDefaultOrder(final RealVectorPreservingVisitor
the visitor to be used to process the entries of this vector
visitor
)

Overrides org.apache.commons.math3.linear.RealVector.walkInDefaultOrder.

Visits (but does not alter) all entries of this vector in default order (increasing index).

public double
walkInDefaultOrder(final RealVectorPreservingVisitor
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Overrides org.apache.commons.math3.linear.RealVector.walkInDefaultOrder.

Visits (but does not alter) some entries of this vector in default order (increasing index).

public double
walkInDefaultOrder(final RealVectorChangingVisitor
the visitor to be used to process and modify the entries of this vector
visitor
)

Overrides org.apache.commons.math3.linear.RealVector.walkInDefaultOrder.

Visits (and possibly alters) all entries of this vector in default order (increasing index).

public double
walkInDefaultOrder(final RealVectorChangingVisitor
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Overrides org.apache.commons.math3.linear.RealVector.walkInDefaultOrder.

Visits (and possibly alters) some entries of this vector in default order (increasing index).

public double
walkInOptimizedOrder(final RealVectorPreservingVisitor
the visitor to be used to process the entries of this vector
visitor
)

Overrides org.apache.commons.math3.linear.RealVector.walkInOptimizedOrder.

Visits (but does not alter) all entries of this vector in optimized order.

public double
walkInOptimizedOrder(final RealVectorPreservingVisitor
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Overrides org.apache.commons.math3.linear.RealVector.walkInOptimizedOrder.

Visits (but does not alter) some entries of this vector in optimized order.

public double
walkInOptimizedOrder(final RealVectorChangingVisitor
the visitor to be used to process the entries of this vector
visitor
)

Overrides org.apache.commons.math3.linear.RealVector.walkInOptimizedOrder.

Visits (and possibly alters) all entries of this vector in optimized order.

public double
walkInOptimizedOrder(final RealVectorChangingVisitor
visitor to be used to process the entries of this vector
visitor
,
final int
the index of the first entry to be visited
start
,
final int
the index of the last entry to be visited (inclusive)
end
)

Overrides org.apache.commons.math3.linear.RealVector.walkInOptimizedOrder.

Visits (and possibly change) some entries of this vector in optimized order.

Inherited from org.apache.commons.math3.linear.RealVector:
checkIndexcheckIndicescosinegetMaxIndexgetMaxValuegetMinIndexgetMinValueiteratormapAddmapDividemapMultiplymapSubtractprojectionsparseIteratorunitizeunitVectorunmodifiableRealVector