SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.algebra.linear.vector.doubles.operation

Class VectorFactory

• java.lang.Object
• com.numericalmethod.suanshu.algebra.linear.vector.doubles.operation.VectorFactory

• public class VectorFactory
extends Object
These are the utility functions that create new instances of vectors from existing ones.
• Method Summary

All Methods
Modifier and Type Method and Description
static Vector concat(Collection<Vector> vectors)
Concatenates an array of vectors into one vector.
static SparseVector concat(SparseVector... vectors)
Concatenates an array of sparse vectors into one sparse vector.
static Vector concat(Vector... vectors)
Concatenates an array of vectors into one vector.
static Vector[] cumsum(Vector[] arr)
Gets the cumulative sums.
static Vector diagonal(Matrix A)
Gets the diagonal of a matrix as a vector.
static SparseVector diagonal(SparseMatrix A)
Gets the diagonal of a sparse matrix as a sparse vector.
static SparseVector foreach(SparseVector vector, UnivariateRealFunction f)
Constructs a new vector in which each entry is the result of applying a function to the corresponding entry of a sparse vector.
static Vector foreach(Vector vector, UnivariateRealFunction f)
Constructs a new vector in which each entry is the result of applying a function to the corresponding entry of a vector.
static Vector foreachColumn(Matrix matrix, RealScalarFunction f)
Constructs a vector in which each entry is the result of applying a RealScalarFunction to each column of an input matrix.
static Vector foreachRow(Matrix matrix, RealScalarFunction f)
Constructs a vector in which each entry is the result of applying a RealScalarFunction to each row of an input matrix.
static Vector foreachVector(Collection<Vector> vectors, RealScalarFunction f)
Applies a RealScalarFunction on each input vector.
static Vector[] foreachVector(Collection<Vector> vectors, RealVectorFunction f)
Applies a real vector function on each input vector.
static Vector foreachVector(Vector[] vectors, RealScalarFunction f)
Applies a RealScalarFunction on each input vector.
static Vector[] foreachVector(Vector[] vectors, RealVectorFunction f)
Applies a real vector function on each input vector.
static Vector[] get0s(int dimension, int n)
Gets n 0 vectors.
static Vector getCoordinate(Collection<Vector> vectors, int i)
Gets the vector entries from a particular coordinate.
static Vector getCoordinate(Vector[] vectors, int i)
Gets the vector entries from a particular coordinate.
static List<Vector> getOffsetVectors(Vector v0, Vector dv, int a, int b)
Given the reference vector v0, the delta dv, and the range [a, b], the offset vectors are: v0 + a * dv, v0 + (a + 1) * dv, ..., v0 + b * dv.
static Vector subDiagonal(Matrix A)
Gets the sub-diagonal of a matrix as a vector.
static SparseVector subDiagonal(SparseMatrix A)
Gets the sub-diagonal of a sparse matrix as a sparse vector.
static SparseVector subVector(SparseVector vector, int from, int to)
Gets a sub-vector from a sparse vector.
static Vector subVector(Vector vector, int[] indices)
Gets a sub-vector from a vector according to a given array of ordered indices (repetition allowed).
static Vector subVector(Vector vector, int from, int to)
Gets a sub-vector from a vector.
static Vector superDiagonal(Matrix A)
Gets the super-diagonal of a matrix as a vector.
static SparseVector superDiagonal(SparseMatrix A)
Gets the super-diagonal of a sparse matrix as a sparse vector.
• Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Method Detail

• concat

public static Vector concat(Vector... vectors)
Concatenates an array of vectors into one vector.
Parameters:
vectors - an array of vectors, e.g., $$(v_1, v_2, v_3, ...)$$.
Returns:
$$c(v_1, v_2, v_3, ...)$$
• concat

public static Vector concat(Collection<Vector> vectors)
Concatenates an array of vectors into one vector.
Parameters:
vectors - an array of vectors, e.g., $$(v_1, v_2, v_3, ...)$$.
Returns:
$$c(v_1, v_2, v_3, ...)$$
• concat

public static SparseVector concat(SparseVector... vectors)
Concatenates an array of sparse vectors into one sparse vector.
Parameters:
vectors - an array of sparse vectors, e.g., $$(v_1, v_2, v_3, ...)$$.
Returns:
$$c(v_1, v_2, v_3, ...)$$
• foreach

public static Vector foreach(Vector vector,
UnivariateRealFunction f)
Constructs a new vector in which each entry is the result of applying a function to the corresponding entry of a vector.
Parameters:
f - the function to be applied to each entry of a vector
vector - a vector
Returns:
[f(vi)] for all is
• foreach

public static SparseVector foreach(SparseVector vector,
UnivariateRealFunction f)
Constructs a new vector in which each entry is the result of applying a function to the corresponding entry of a sparse vector. Note that this operation may not preserve sparsity.
Parameters:
f - the function to be applied to each entry of a vector
vector - a sparse vector
Returns:
[f(vi)] for all is
• subVector

public static Vector subVector(Vector vector,
int from,
int to)
Gets a sub-vector from a vector.
Parameters:
vector - a vector
from - the beginning index
to - the ending index
Returns:
v[from : to]
• subVector

public static SparseVector subVector(SparseVector vector,
int from,
int to)
Gets a sub-vector from a sparse vector.
Parameters:
vector - a sparse vector
from - the beginning index
to - the ending index
Returns:
v[from : to]
• subVector

public static Vector subVector(Vector vector,
int[] indices)
Gets a sub-vector from a vector according to a given array of ordered indices (repetition allowed).
Parameters:
vector - a vector
indices - the array of ordered indices (repetition allowed)
Returns:
a sub-vector
• diagonal

public static Vector diagonal(Matrix A)
Gets the diagonal of a matrix as a vector.
Parameters:
A - a matrix
Returns:
a vector whose entries are Ai
• diagonal

public static SparseVector diagonal(SparseMatrix A)
Gets the diagonal of a sparse matrix as a sparse vector.
Parameters:
A - a sparse matrix
Returns:
a sparse vector whose entries are Ai
• superDiagonal

public static Vector superDiagonal(Matrix A)
Gets the super-diagonal of a matrix as a vector.
Parameters:
A - a matrix
Returns:
a vector whose entries are Ai,i+1
• superDiagonal

public static SparseVector superDiagonal(SparseMatrix A)
Gets the super-diagonal of a sparse matrix as a sparse vector.
Parameters:
A - a sparse matrix
Returns:
a sparse vector whose entries are Ai,i+1
• subDiagonal

public static Vector subDiagonal(Matrix A)
Gets the sub-diagonal of a matrix as a vector.
Parameters:
A - a matrix
Returns:
a vector whose entries are Ai+1,i
• subDiagonal

public static SparseVector subDiagonal(SparseMatrix A)
Gets the sub-diagonal of a sparse matrix as a sparse vector.
Parameters:
A - a sparse matrix
Returns:
a sparse vector whose entries are Ai+1,i
• foreachRow

public static Vector foreachRow(Matrix matrix,
RealScalarFunction f)
Constructs a vector in which each entry is the result of applying a RealScalarFunction to each row of an input matrix.
Parameters:
matrix - the input matrix
f - the real scalar function
Returns:
the vector containing the results
• foreachColumn

public static Vector foreachColumn(Matrix matrix,
RealScalarFunction f)
Constructs a vector in which each entry is the result of applying a RealScalarFunction to each column of an input matrix.
Parameters:
matrix - the input matrix
f - the real scalar function
Returns:
the vector containing the results
• foreachVector

public static Vector foreachVector(Vector[] vectors,
RealScalarFunction f)
Applies a RealScalarFunction on each input vector.
Parameters:
vectors - the input vectors
f - the real scalar function
Returns:
the values after applying f on the vectors
• foreachVector

public static Vector foreachVector(Collection<Vector> vectors,
RealScalarFunction f)
Applies a RealScalarFunction on each input vector.
Parameters:
vectors - the input vectors
f - the real scalar function
Returns:
the values after applying f on the vectors
• foreachVector

public static Vector[] foreachVector(Vector[] vectors,
RealVectorFunction f)
Applies a real vector function on each input vector.
Parameters:
vectors - the input vectors
f - the real vector function
Returns:
the output vectors after applying the function
• foreachVector

public static Vector[] foreachVector(Collection<Vector> vectors,
RealVectorFunction f)
Applies a real vector function on each input vector.
Parameters:
vectors - the input vectors
f - the real vector function
Returns:
the output vectors after applying the function
• getCoordinate

public static Vector getCoordinate(Vector[] vectors,
int i)
Gets the vector entries from a particular coordinate. If all input vectors are sparse, then returns a sparse vector.
Parameters:
vectors - the input vectors
i - the index to a vector entry; the coordinate index
Returns:
a vector composed of the entries from a particular coordinate
• getCoordinate

public static Vector getCoordinate(Collection<Vector> vectors,
int i)
Gets the vector entries from a particular coordinate.
Parameters:
vectors - the input vectors
i - the index to a vector entry; the coordinate index
Returns:
a vector composed of the entries from a particular coordinate
• getOffsetVectors

public static List<Vector> getOffsetVectors(Vector v0,
Vector dv,
int a,
int b)
Given the reference vector v0, the delta dv, and the range [a, b], the offset vectors are:
v0 + a * dv, v0 + (a + 1) * dv, ..., v0 + b * dv.
Parameters:
v0 - the reference vector v0
dv - the change (base offset) made to the vector at each step dv
a - the minimum multiple of dv that is added to v0
b - the maximum multiple of dv that is added to v0
Returns:
a list containing the vector
• cumsum

public static Vector[] cumsum(Vector[] arr)
Gets the cumulative sums.
Parameters:
arr - an array of vectors
Returns:
the cumulative sum, element-by-element
• get0s

public static Vector[] get0s(int dimension,
int n)
Gets n 0 vectors.
Parameters:
dimension - the dimension of the vectors
n - the number of 0 vectors
Returns:
n 0 vectors