public class Vectors extends Object
Vector
instances, following a format similar to that of Collections
.
Unless otherwise noted, all returned Vector
instances implement
Serializable
.
Modifier and Type | Method and Description |
---|---|
static SparseDoubleVector |
asDouble(SparseIntegerVector v) |
static DoubleVector |
asDouble(Vector v)
Returns a view over the given
Vector as a DoubleVector . |
static DoubleVector |
asVector(double[] array)
Returns a vector backed by the specified array.
|
static IntegerVector |
asVector(int[] array)
Returns a vector backed by the specified array.
|
static DoubleVector |
atomic(DoubleVector vector)
Returns a thread-safe version of a
DoubleVector that guarantees
atomic access to all operations. |
static Vector |
copy(Vector dest,
Vector source)
Copies all of the values from one
Vector into another. |
static DoubleVector |
copyOf(DoubleVector source)
Creates a copy of a given
DoubleVector with the same type as the
original. |
static IntegerVector |
copyOf(IntegerVector source)
Creates a copy of a given
IntegerVector with the same type as the
original. |
static Vector |
copyOf(Vector source)
Creates a copy of a given
Vector . |
static boolean |
equals(DoubleVector v1,
DoubleVector v2)
Returns
true if the two vectors are equal to one another. |
static boolean |
equals(IntegerVector v1,
IntegerVector v2)
Returns
true if the two integer vectors are equal to one another. |
static boolean |
equals(Vector v1,
Vector v2)
Returns
true if the two vectors are equal to one another. |
static DoubleVector |
immutable(DoubleVector vector)
Returns an immutable view of the given
DoubleVector . |
static IntegerVector |
immutable(IntegerVector vector)
Returns an immutable view of the given
IntegerVector . |
static SparseDoubleVector |
immutable(SparseDoubleVector vector)
Returns an immutable view of the given
SparseDoubleVector . |
static SparseIntegerVector |
immutable(SparseIntegerVector vector)
Returns an immutable view of the given
SparseIntegerVector . |
static Vector |
immutable(Vector vector)
Returns an immutable view of the given
Vector . |
static <T extends Vector> |
instanceOf(T vector)
Creates a
Vector instance of the same type and length of the
provided vector. |
static DoubleVector |
scaleByMagnitude(DoubleVector vector) |
static DoubleVector |
scaleByMagnitude(SparseDoubleVector vector) |
static DoubleVector |
subview(DoubleVector vector,
int offset,
int length)
Returns a subview for the given
DoubleVector with a specified
offset and length. |
static IntegerVector |
subview(IntegerVector vector,
int offset,
int length)
Returns a subview for the given
IntegerVector with a specified
offset and length. |
static SparseDoubleVector |
subview(SparseDoubleVector vector,
int offset,
int length)
Returns a subview for the given
SparseDoubleVector with a
specified offset and length. |
static SparseIntegerVector |
subview(SparseIntegerVector vector,
int offset,
int length)
Returns a subview for the given
IntegerVector with a specified
offset and length. |
static DoubleVector |
synchronizedVector(DoubleVector vector)
Returns a syncrhonized view of a given
DoubleVector . |
public static DoubleVector asDouble(Vector v)
Vector
as a DoubleVector
.
The returned vector is mutable but any changes will be converted into its
internal data-type, e.g. int
, which may result in information
loss.v
- The Vector
to return as a DoubleVector
.DoubleVector
view of v
public static SparseDoubleVector asDouble(SparseIntegerVector v)
public static DoubleVector asVector(double[] array)
Vector
-based computation.array
- the array backing the vectorVector
view of the arraypublic static IntegerVector asVector(int[] array)
Vector
-based computation.array
- the array backing the vectorVector
view of the arraypublic static boolean equals(DoubleVector v1, DoubleVector v2)
true
if the two vectors are equal to one another. Two
Vector
insances are considered equal if they contain the same
number of elements and all corresponding pairs of double
values
are equal.public static boolean equals(IntegerVector v1, IntegerVector v2)
true
if the two integer vectors are equal to one another.
Two Vector
insances are considered equal if they contain the same
number of elements and all corresponding pairs of int
values
are equal.public static boolean equals(Vector v1, Vector v2)
true
if the two vectors are equal to one another. Two
Vector
insances are considered equal if they contain the same
number of elements and all corresponding pairs of Number
values
are equal. Two values n1
and n2
are considered equal if
n1.equals(n2)
.public static DoubleVector immutable(DoubleVector vector)
DoubleVector
.vector
- The DoubleVector
to decorate as immutable.vector
.public static SparseDoubleVector immutable(SparseDoubleVector vector)
SparseDoubleVector
.vector
- The DoubleVector
to decorate as immutable.vector
.public static IntegerVector immutable(IntegerVector vector)
IntegerVector
.vector
- The IntegerVector
to decorate as immutable.vector
.public static SparseIntegerVector immutable(SparseIntegerVector vector)
SparseIntegerVector
.vector
- The IntegerVector
to decorate as immutable.vector
.public static Vector immutable(Vector vector)
Vector
.vector
- The DoubleVector
to decorate as immutable.vector
.public static DoubleVector atomic(DoubleVector vector)
DoubleVector
that guarantees
atomic access to all operations. The returned vector allows concurrent
read access.vector
- The DoubleVector
to decorate as atomic.vector
.public static DoubleVector synchronizedVector(DoubleVector vector)
DoubleVector
. This may
show slightly better performance than using an AtomicVector
in
some use cases.vector
- The DoubleVector
to decorate as synchronized.vector
.public static DoubleVector scaleByMagnitude(DoubleVector vector)
public static DoubleVector scaleByMagnitude(SparseDoubleVector vector)
public static DoubleVector subview(DoubleVector vector, int offset, int length)
DoubleVector
with a specified
offset and length.vector
- the Vector
whose values will be shown in the viewoffset
- the index of v
at which the first index of this
view startslength
- the length of this view.IllegalArgumentException
- if offset
is
negativelength
is less than zerooffset
plus length
is greater than the length of vector
public static SparseDoubleVector subview(SparseDoubleVector vector, int offset, int length)
SparseDoubleVector
with a
specified offset and length.vector
- the Vector
whose values will be shown in the viewoffset
- the index of v
at which the first index of this
view startslength
- the length of this view.IllegalArgumentException
- if offset
is
negativelength
is less than zerooffset
plus length
is greater than the length of vector
public static IntegerVector subview(IntegerVector vector, int offset, int length)
IntegerVector
with a specified
offset and length.vector
- the Vector
whose values will be shown in the viewoffset
- the index of v
at which the first index of this
view startslength
- the length of this view.IllegalArgumentException
- if offset
is
negativelength
is less than zerooffset
plus length
is greater than the length of vector
public static SparseIntegerVector subview(SparseIntegerVector vector, int offset, int length)
IntegerVector
with a specified
offset and length.vector
- the Vector
whose values will be shown in the viewoffset
- the index of v
at which the first index of this
view startslength
- the length of this view.IllegalArgumentException
- if offset
is
negativelength
is less than zerooffset
plus length
is greater than the length of vector
public static Vector copy(Vector dest, Vector source)
Vector
into another. After the
operation, all of the values in dest
will be the same as that of
source
. The legnth of dest
must be as long as the length
of source
. Once completed dest
is returned.dest
- The Vector
to copy values into.source
- The Vector
to copy values from.dest
after being copied from source
.IllegalArgumentException
- if the length of dest
is less
than that of source
.public static DoubleVector copyOf(DoubleVector source)
DoubleVector
with the same type as the
original.source
- The Vector
to copy.source
with the same type.public static Vector copyOf(Vector source)
Vector
.source
- The Vector
to copy.source
with the same type.public static IntegerVector copyOf(IntegerVector source)
IntegerVector
with the same type as the
original.source
- The Vector
to copy.source
with the same type.public static <T extends Vector> T instanceOf(T vector)
Vector
instance of the same type and length of the
provided vector.vector
- a vector whose type and length should be used when creating
a new vector with the same propertiesCopyright © 2012. All Rights Reserved.