Class VectorFactory
- java.lang.Object
-
- dev.nm.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 Static Methods Concrete Methods Modifier and Type Method Description 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
concat(Collection<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
foreach(Vector vector, DoubleUnaryOperator 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 aRealScalarFunction
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 aRealScalarFunction
to each row of an input matrix.static Vector
foreachVector(Vector[] vectors, RealScalarFunction f)
Applies aRealScalarFunction
on each input vector.static Vector[]
foreachVector(Vector[] vectors, RealVectorFunction f)
Applies a real vector function on each input vector.static Vector
foreachVector(Collection<Vector> vectors, RealScalarFunction f)
Applies aRealScalarFunction
on each input vector.static Vector[]
foreachVector(Collection<Vector> vectors, RealVectorFunction f)
Applies a real vector function on each input vector.static Vector[]
get0s(int dimension, int n)
Getsn
0 vectors.static Vector
getCoordinate(Vector[] vectors, int i)
Gets the vector entries from a particular coordinate.static Vector
getCoordinate(Collection<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 vectorv0
, the deltadv
, and the range[a, b]
, the offset vectors are: v0 + a * dv, v0 + (a + 1) * dv, ..., v0 + b * dv.static Vector
replaceInPlace(Vector original, int from, Vector replacement)
Replaces a sub-vector with a given smaller vector.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
subVector(Vector vector, List<Integer> indices)
Gets a sub-vector from a vector according to a given array of ordered indices (repetition allowed).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.
-
-
-
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, ...)\)
-
replaceInPlace
public static Vector replaceInPlace(Vector original, int from, Vector replacement)
Replaces a sub-vector with a given smaller vector.- Parameters:
original
- the original vectorfrom
- the beginning entry index to replacereplacement
- the vector to be inserted to the original vector- Returns:
- the modified vector
-
foreach
public static Vector foreach(Vector vector, DoubleUnaryOperator f)
Constructs a new vector in which each entry is the result of applying a function to the corresponding entry of a vector. For example,Vector v1 = foreach(v0, x -> 2 * x); // double each entry in v0
- Parameters:
f
- the function to be applied to each entry of a vectorvector
- a vector- Returns:
- [f(vi)] for all is
-
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 vectorvector
- 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 vectorvector
- 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 vectorfrom
- the beginning indexto
- 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 vectorfrom
- the beginning indexto
- the ending index- Returns:
v[from : to]
-
subVector
public static Vector subVector(Vector vector, List<Integer> indices)
Gets a sub-vector from a vector according to a given array of ordered indices (repetition allowed).- Parameters:
vector
- a vectorindices
- the list of ordered indices (repetition allowed)- Returns:
- a sub-vector
-
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 vectorindices
- 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 aRealScalarFunction
to each row of an input matrix.- Parameters:
matrix
- the input matrixf
- 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 aRealScalarFunction
to each column of an input matrix.- Parameters:
matrix
- the input matrixf
- the real scalar function- Returns:
- the vector containing the results
-
foreachVector
public static Vector foreachVector(Vector[] vectors, RealScalarFunction f)
Applies aRealScalarFunction
on each input vector.- Parameters:
vectors
- the input vectorsf
- the real scalar function- Returns:
- the values after applying
f
on the vectors
-
foreachVector
public static Vector foreachVector(Collection<Vector> vectors, RealScalarFunction f)
Applies aRealScalarFunction
on each input vector.- Parameters:
vectors
- the input vectorsf
- 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 vectorsf
- 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 vectorsf
- 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 vectorsi
- 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 vectorsi
- 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 vectorv0
, the deltadv
, and the range[a, b]
, the offset vectors are:v0 + a * dv, v0 + (a + 1) * dv, ..., v0 + b * dv.
- Parameters:
v0
- the reference vectorv0
dv
- the change (base offset) made to the vector at each stepdv
a
- the minimum multiple ofdv
that is added tov0
b
- the maximum multiple ofdv
that is added tov0
- 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)
Getsn
0 vectors.- Parameters:
dimension
- the dimension of the vectorsn
- the number of 0 vectors- Returns:
n
0 vectors
-
-