Class CooVector
- All Implemented Interfaces:
Serializable
,RealTensorMixin<CooVector,
,CooCVector> SparseTensorMixin
,TensorComparisonsMixin
,TensorManipulationsMixin<CooVector>
,TensorOperationsMixin<CooVector,
,Vector, CooCVector, CVector, CooVector, Double> TensorPropertiesMixin
,VectorComparisonsMixin
,VectorManipulationsMixin<CooMatrix>
,VectorMixin<CooVector,
,Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> VectorOperationsMixin<CooVector,
,Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> VectorPropertiesMixin
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal int[]
Indices of non-zero entries in this sparse vector.final int
The size of this vector.Fields inherited from class org.flag4j.core.sparse_base.SparseTensorBase
nnz
Fields inherited from class org.flag4j.core.TensorBase
DEFAULT_ROUND_TO_ZERO_THRESHOLD, entries, shape
-
Constructor Summary
ConstructorDescriptionCooVector
(int size) Creates a sparse vector of specified size filled with zeros.CooVector
(int size, double[] nonZeroEntries, int[] indices) Creates a sparse vector of specified size along with non-zero entries and their indices.CooVector
(int size, int[] nonZeroEntries, int[] indices) Creates a sparse vector of specified size filled with zeros.Creates a sparse vector of specified size, non-zero entries, and non-zero indices.Constructs a sparse vector whose non-zero values, indices, and size are specified by another sparse vector. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double a) Adds specified value to all entries of this tensor.Computes the element-wise addition between this vector and the specified vector.Computes the element-wise addition between this vector and the specified vector.add
(CooCVector B) Computes the element-wise addition between this vector and the specified vector.Computes the element-wise addition between two tensors of the same rank.Adds specified value to all entries of this tensor.boolean
Checks if all entries of this tensor are close to the entries of the argumenttensor
.copy()
Creates a copy of this tensor.div
(double divisor) Computes the scalar division of a tensor.Computes the scalar division of a tensor.Computes the element-wise division (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise division (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication between two tensors.boolean
Checks if an object is equal to this sparse COO vector.extend
(int n, int axis) Extends a vector a specified number of times to a matrix.flatten()
Flattens tensor to single dimension.flatten
(int axis) Flattens a tensor along the specified axis.static CooVector
Creates a sparse tensor from a dense tensor.get
(int... indices) Gets the element in this tensor at the specified indices.protected CooVector
getSelf()
Simply returns a reference of this tensor.Computes the inner product between two vectors.Computes the inner product between two vectors.inner
(CooCVector b) Computes the inner product between two vectors.Computes the inner product between two vectors.boolean
isParallel
(Vector b) Checks if a vector is parallel to this vector.boolean
Checks if a vector is perpendicular to this vector.Joins specified vector with this vector.Joins specified vector with this vector.join
(CooCVector b) Joins specified vector with this vector.Joins specified vector with this vector.int
length()
Gets the length of a vector.protected CooCVector
makeComplexTensor
(Shape shape, CNumber[] entries, int[][] indices) A factory for creating a complex sparse tensor.protected Vector
makeDenseTensor
(Shape shape, double[] entries) A factory for creating a real dense tensor.protected CooVector
makeTensor
(Shape shape, double[] entries, int[][] indices) A factory for creating a real sparse tensor.Computes a unit vector in the same direction as this vector.Computes the outer product of two vectors.Computes the outer product of two vectors.outer
(CooCVector b) Computes the outer product of two vectors.Computes the outer product of two vectors.repeat
(int n, int axis) Repeats a vectorn
times along a certain axis to create a matrix.Copies and reshapes tensor if possible.set
(double value, int... indices) Sets an index of a copy of this vector to a specified value.int
size()
gets the size of this vector.void
Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.Stacks two vectors along columns as if they were row vectors.Stacks two vectors along specified axis.Stacks two vectors along columns as if they were row vectors.Stacks two vectors along specified axis.stack
(CooCVector b) Stacks two vectors along columns as if they were row vectors.stack
(CooCVector b, int axis) Stacks two vectors along specified axis.Stacks two vectors along columns as if they were row vectors.Stacks two vectors along specified axis.sub
(double a) Adds specified value to all entries of this tensor.Computes the element-wise subtraction between this vector and the specified vector.Computes the element-wise subtraction between this vector and the specified vector.sub
(CooCVector B) Computes the element-wise subtraction between this vector and the specified vector.Computes the element-wise subtraction between two tensors of the same rank.Subtracts a specified value from all entries of this tensor.T()
Computes the transpose of a tensor.Converts this tensor to an equivalent complex tensor.toDense()
Converts this sparse tensor to an equivalent dense tensor.toMatrix()
Converts this vector to an equivalent matrix as if it were a column vector.toMatrix
(boolean columVector) Converts a vector to an equivalent matrix representing either a row or column vector.toString()
Formats this tensor as a human-readable string.toTensor()
Converts this vector to an equivalent tensor.Methods inherited from class org.flag4j.core.sparse_base.RealSparseTensorBase
abs, argMax, argMin, isNeg, isOnes, isPos, isZeros, max, maxAbs, min, minAbs, mult, mult, nonZeroEntries, recip, reshape, round, round, roundToZero, roundToZero, sqrt, sum
Methods inherited from class org.flag4j.core.sparse_base.SparseTensorBase
density, sparsity
Methods inherited from class org.flag4j.core.TensorBase
allClose, getEntries, getRank, getShape, sameLength, sameShape, tensorEquals, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.flag4j.core.TensorOperationsMixin
transpose
Methods inherited from interface org.flag4j.core.VectorPropertiesMixin
maxAbs
-
Field Details
-
size
public final int sizeThe size of this vector. That is, the number of entries in this vector. -
indices
public final int[] indicesIndices of non-zero entries in this sparse vector.
-
-
Constructor Details
-
CooVector
public CooVector(int size) Creates a sparse vector of specified size filled with zeros.- Parameters:
size
- The size of the sparse vector. i.e. the total number of entries in the sparse vector.
-
CooVector
public CooVector(int size, int[] nonZeroEntries, int[] indices) Creates a sparse vector of specified size filled with zeros.- Parameters:
size
- The size of the sparse vector. i.e. the total number of entries in the sparse vector.nonZeroEntries
- The nonZero entries of this sparse vector.indices
- Indices of the nonZero entries. Indices are assumed to be sorted in lexicographical order but this is not enforced. However, many algorithms assume the indices to be sorted. If they are not, use- Throws:
IllegalArgumentException
- If the lengths of nonZeroEntries and indices arrays are not equal or if the length of the nonZeroEntries array is greater than the size.
-
CooVector
public CooVector(int size, double[] nonZeroEntries, int[] indices) Creates a sparse vector of specified size along with non-zero entries and their indices.- Parameters:
size
- The size of the sparse vector. i.e. the total number of entries in the sparse vector.nonZeroEntries
- The nonZero entries of this sparse vector. Entries assumed to be sorted by indices (not enforced).indices
- Indices of the nonZero entries. Assumed to be sorted (not enforced).- Throws:
IllegalArgumentException
- If the lengths of nonZeroEntries and indices arrays are not equal or if the length of the nonZeroEntries array is greater than the size.
-
CooVector
Constructs a sparse vector whose non-zero values, indices, and size are specified by another sparse vector.- Parameters:
a
- Sparse vector to copy
-
CooVector
Creates a sparse vector of specified size, non-zero entries, and non-zero indices.- Parameters:
size
- Full size, including zeros, of the sparse vector.entries
- Non-zero entries of the sparse vector.indices
- Non-zero indices of the sparse vector.
-
-
Method Details
-
equals
Checks if an object is equal to this sparse COO vector.- Specified by:
equals
in interfaceTensorComparisonsMixin
- Overrides:
equals
in classObject
- Parameters:
object
- Object to compare this sparse COO vector to.- Returns:
- True if the object is a
CooVector
, has the same shape as this vector, and is element-wise equal to this vector.
-
set
Sets an index of a copy of this vector to a specified value. Creates a copy of this vector and sets an index to the specified value. Note, unlike the dense version of this method, this does not affect this vector.- Specified by:
set
in interfaceTensorManipulationsMixin<CooVector>
- Parameters:
value
- Value to set.indices
- The index of for which to set the value.- Returns:
- A copy of this vector with the specified index set to the specified value.
- Throws:
IllegalArgumentException
- If the number of indices provided is greater than 1.IllegalArgumentException
- If the index is negative or larger than the total vector size.
-
reshape
Copies and reshapes tensor if possible. The total number of entries in this tensor must match the total number of entries in the reshaped tensor.- Specified by:
reshape
in interfaceTensorManipulationsMixin<CooVector>
- Parameters:
shape
- Shape of the new tensor.- Returns:
- A tensor which is equivalent to this tensor but with the specified shape.
- Throws:
IllegalArgumentException
- If this tensor cannot be reshaped to the specified dimensions.
-
flatten
Flattens tensor to single dimension. To flatten tensor along a single axis.- Specified by:
flatten
in interfaceTensorManipulationsMixin<CooVector>
- Returns:
- The flattened tensor.
-
join
Joins specified vector with this vector.- Specified by:
join
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to join with this vector.- Returns:
- A vector resulting from joining the specified vector with this vector.
-
join
Joins specified vector with this vector.- Specified by:
join
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to join with this vector.- Returns:
- A vector resulting from joining the specified vector with this vector.
-
join
Joins specified vector with this vector.- Specified by:
join
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to join with this vector.- Returns:
- A vector resulting from joining the specified vector with this vector.
-
join
Joins specified vector with this vector.- Specified by:
join
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to join with this vector.- Returns:
- A vector resulting from joining the specified vector with this vector.
-
stack
Stacks two vectors along columns as if they were row vectors.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector
b
. - Throws:
IllegalArgumentException
-
- If the number of entries in this vector is different from the number of entries in the vectorb
.
-
stack
Stacks two vectors along columns as if they were row vectors.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector
b
. - Throws:
IllegalArgumentException
-
- If the number of entries in this vector is different from the number of entries in the vectorb
.
-
stack
Stacks two vectors along columns as if they were row vectors.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector
b
. - Throws:
IllegalArgumentException
-
- If the number of entries in this vector is different from the number of entries in the vectorb
.
-
stack
Stacks two vectors along columns as if they were row vectors.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector
b
. - Throws:
IllegalArgumentException
-
- If the number of entries in this vector is different from the number of entries in the vectorb
.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
add
Computes the element-wise addition between this vector and the specified vector.- Specified by:
add
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
add
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Specified by:
add
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
add
Computes the element-wise addition between this vector and the specified vector.- Specified by:
add
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
add
Computes the element-wise addition between this vector and the specified vector.- Specified by:
add
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
sub
Computes the element-wise subtraction between this vector and the specified vector.- Specified by:
sub
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
add
Adds specified value to all entries of this tensor.- Specified by:
add
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
add
Adds specified value to all entries of this tensor. If zeros are introduced, they will be explicitly stored.- Specified by:
add
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
sub
Computes the element-wise subtraction between two tensors of the same rank.- Specified by:
sub
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Specified by:
sub
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to subtract from this vector.- Returns:
- The result of the element-wise vector subtraction.
- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
sub
Computes the element-wise subtraction between this vector and the specified vector.- Specified by:
sub
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to subtract from this vector.- Returns:
- The result of the element-wise vector subtraction.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
sub
Computes the element-wise subtraction between this vector and the specified vector.- Specified by:
sub
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to subtract from this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
sub
Adds specified value to all entries of this tensor.- Specified by:
sub
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
sub
Subtracts a specified value from all entries of this tensor.- Specified by:
sub
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Parameters:
a
- Value to subtract from all entries of this tensor.- Returns:
- The result of subtracting the specified value from each entry of this tensor.
-
elemMult
Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemMult
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to element-wise multiply to this vector.- Returns:
- The vector resulting from the element-wise multiplication.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
div
Computes the scalar division of a tensor.- Specified by:
div
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Overrides:
div
in classRealSparseTensorBase<CooVector,
Vector, CooCVector, CVector> - Parameters:
divisor
- The scalar value to divide tensor by.- Returns:
- The result of dividing this tensor by the specified scalar.
- Throws:
ArithmeticException
- If divisor is zero.
-
div
Computes the scalar division of a tensor.- Specified by:
div
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Overrides:
div
in classRealSparseTensorBase<CooVector,
Vector, CooCVector, CVector> - Parameters:
divisor
- The scalar value to divide tensor by.- Returns:
- The result of dividing this tensor by the specified scalar.
- Throws:
ArithmeticException
- If divisor is zero.
-
T
Computes the transpose of a tensor. Same asTensorOperationsMixin.transpose()
. Since a vector is a rank 1 tensor, this just * copies the vector.- Specified by:
T
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Returns:
- The transpose of this tensor.
-
get
Gets the element in this tensor at the specified indices. This sparse vectors indices are assumed to be sorted lexicographically. If this is not the case callthis.sparseSort()
before calling this method.- Specified by:
get
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Parameters:
indices
- Indices of element.- Returns:
- The element at the specified indices.
- Throws:
IllegalArgumentException
- If the number of indices does not match the rank of this tensor.
-
copy
Creates a copy of this tensor.- Specified by:
copy
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Returns:
- A copy of this tensor.
-
elemMult
Computes the element-wise multiplication between two tensors.- Specified by:
elemMult
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Specified by:
elemMult
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Tensor to element-wise multiply to this tensor.- Returns:
- The result of the element-wise tensor multiplication.
- Throws:
IllegalArgumentException
- If this tensor andB
do not have the same shape.
-
elemMult
Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemMult
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to element-wise multiply to this vector.- Returns:
- The vector resulting from the element-wise multiplication.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
elemMult
Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemMult
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
B
- Vector to element-wise multiply to this vector.- Returns:
- The vector resulting from the element-wise multiplication.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
elemDiv
Computes the element-wise division (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemDiv
in interfaceTensorOperationsMixin<CooVector,
Vector, CooCVector, CVector, CooVector, Double> - Specified by:
elemDiv
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to element-wise divide this vector by.- Returns:
- The vector resulting from the element-wise division.
- Throws:
IllegalArgumentException
- If this vector andb
do not have the same size.
-
elemDiv
Computes the element-wise division (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemDiv
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to element-wise divide this vector by.- Returns:
- The vector resulting from the element-wise division.
- Throws:
IllegalArgumentException
- If this vector andb
do not have the same size.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
normalize
Computes a unit vector in the same direction as this vector.- Specified by:
normalize
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Returns:
- A unit vector with the same direction as this vector.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
isParallel
Checks if a vector is parallel to this vector. This sparse vectors indices are assumed to be sorted lexicographically. If this is not the case callthis.sparseSort()
before calling this method.- Specified by:
isParallel
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to compare to this vector.- Returns:
- True if the vector
b
is parallel to this vector and the same size. Otherwise, returns false.
-
isPerp
Checks if a vector is perpendicular to this vector.- Specified by:
isPerp
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
b
- Vector to compare to this vector.- Returns:
- True if the vector
b
is perpendicular to this vector and the same size. Otherwise, returns false.
-
toMatrix
Converts this vector to an equivalent matrix as if it were a column vector.- Specified by:
toMatrix
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Returns:
- A matrix equivalent to this vector as if the vector is a column vector.
- See Also:
-
toMatrix
Converts a vector to an equivalent matrix representing either a row or column vector.- Specified by:
toMatrix
in interfaceVectorOperationsMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
columVector
- Flag for choosing whether to convert this vector to a matrix representing a row or column vector.If true, the vector will be converted to a matrix representing a column vector.
If false, The vector will be converted to a matrix representing a row vector.
- Returns:
- A matrix equivalent to this vector.
- See Also:
-
toTensor
Converts this vector to an equivalent tensor.- Returns:
- A tensor which is equivalent to this vector.
-
extend
Extends a vector a specified number of times to a matrix.- Specified by:
extend
in interfaceVectorManipulationsMixin<CooMatrix>
- Parameters:
n
- The number of times to extend this vector. Must be a positive value.axis
- Axis along which to extend. Ifaxis=0
, then the vector will be treated as a row vector. Ifaxis=1
then the vector will be treated as a column vector.- Returns:
- A matrix which is the result of extending a vector
n
times.
-
length
public int length()Gets the length of a vector.- Specified by:
length
in interfaceVectorPropertiesMixin
- Returns:
- The length, i.e. the number of entries, in this vector.
-
makeTensor
A factory for creating a real sparse tensor.- Specified by:
makeTensor
in classRealSparseTensorBase<CooVector,
Vector, CooCVector, CVector> - Parameters:
shape
- Shape of the sparse tensor to make.entries
- Non-zero entries of the sparse tensor to make.indices
- Non-zero indices of the sparse tensor to make.- Returns:
- A tensor created from the specified parameters.
-
makeDenseTensor
A factory for creating a real dense tensor.- Specified by:
makeDenseTensor
in classRealSparseTensorBase<CooVector,
Vector, CooCVector, CVector> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the dense tensor to make.- Returns:
- A tensor created from the specified parameters.
-
makeComplexTensor
A factory for creating a complex sparse tensor.- Specified by:
makeComplexTensor
in classRealSparseTensorBase<CooVector,
Vector, CooCVector, CVector> - Parameters:
shape
- Shape of the tensor to make.entries
- Non-zero entries of the sparse tensor to make.indices
- Non-zero indices of the sparse tensor to make.- Returns:
- A tensor created from the specified parameters.
-
sortIndices
public void sortIndices()Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.- Specified by:
sortIndices
in interfaceSparseTensorMixin
- Overrides:
sortIndices
in classRealSparseTensorBase<CooVector,
Vector, CooCVector, CVector>
-
toComplex
Converts this tensor to an equivalent complex tensor. That is, the entries of the resultant tensor will be exactly the same value but will have typeCNumber
rather thanDouble
.- Specified by:
toComplex
in interfaceRealTensorMixin<CooVector,
CooCVector> - Returns:
- A complex matrix which is equivalent to this matrix.
-
flatten
Flattens a tensor along the specified axis. This simply copies the vector since it is rank 1.- Specified by:
flatten
in interfaceTensorManipulationsMixin<CooVector>
- Parameters:
axis
- Axis along which to flatten tensor. Must be 0.- Throws:
IllegalArgumentException
- If the axis is not positive or larger thanthis.
.TensorBase.getRank()
-1
-
size
public int size()gets the size of this vector.- Specified by:
size
in interfaceVectorMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Returns:
- The number of total entries (including zeros) of this vector.
-
repeat
Repeats a vectorn
times along a certain axis to create a matrix.- Specified by:
repeat
in interfaceVectorMixin<CooVector,
Vector, CooVector, CooCVector, Double, CooMatrix, Matrix, CooCMatrix> - Parameters:
n
- Number of times to repeat vector.axis
- Axis along which to repeat vector. Ifaxis=0
then each row of the resulting matrix will be equivalent to this vector. Ifaxis=1
then each column of the resulting matrix will be equivalent to this vector.- Returns:
- A matrix whose rows/columns are this vector repeated.
-
getSelf
Simply returns a reference of this tensor.- Specified by:
getSelf
in classTensorBase<CooVector,
Vector, CooCVector, CVector, CooVector, double[], Double> - Returns:
- A reference to this tensor.
-
allClose
Description copied from class:TensorBase
Checks if all entries of this tensor are close to the entries of the argumenttensor
.- Specified by:
allClose
in classTensorBase<CooVector,
Vector, CooCVector, CVector, CooVector, double[], Double> - Parameters:
tensor
- Tensor to compare this tensor to.relTol
- Relative tolerance.absTol
- Absolute tolerance.- Returns:
- True if the argument
tensor
is the same shape as this tensor and all entries are 'close', i.e. elementsa
andb
at the same positions in the two tensors respectively satisfy|a-b| <= (atol + rtol*|b|)
. Otherwise, returns false. - See Also:
-
toDense
Converts this sparse tensor to an equivalent dense tensor.- Specified by:
toDense
in classSparseTensorBase<CooVector,
Vector, CooCVector, CVector, CooVector, double[], Double> - Returns:
- A dense tensor which is equivalent to this sparse tensor.
-
fromDense
-
toString
-