Class CooVector
- All Implemented Interfaces:
Serializable
,TensorOverField<CooVector,
,CooVector, double[], Double> TensorOverRing<CooVector,
,CooVector, double[], Double> TensorOverSemiring<CooVector,
,CooVector, double[], Double> VectorMixin<CooVector,
CooMatrix, Matrix, Double>
A real sparse vector stored in coordinate list (COO) format. The AbstractTensor.data
of this COO vector are
primitive doubles.
The non-zero data
and non-zero indices
of a COO vector are mutable but the AbstractTensor.shape
and total number of non-zero data is fixed.
Sparse vectors allow for the efficient storage of and ops on vectors that contain many zero values.
COO vectors are optimized for hyper-sparse vectors (i.e. vectors which contain almost all zeros relative to the size of the vector).
A sparse COO vector is stored as:
- The full
AbstractTensor.shape
/VectorMixin.size()
of the vector. - The non-zero
AbstractTensor.data
of the vector. All other data in the vector are assumed to be zero. Zero values can also explicitly be stored inAbstractTensor.data
. - The
indices
of the non-zero values in the sparse vector.
Some ops on sparse tensors behave differently than on dense tensors. For instance, add(Complex128)
will not
add the scalar to all data of the tensor since this would cause catastrophic loss of sparsity. Instead, such non-zero preserving
element-wise ops only act on the non-zero data of the sparse tensor as to not affect the sparsity.
Note: many ops assume that the data of the COO vector are sorted lexicographically. However, this is not explicitly verified. Every operation implemented in this class will preserve the lexicographical sorting.
If indices need to be sorted for any reason, call sortIndices()
.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal int[]
The indices of the non-zero data in this sparse COO vector.final int
The number of non-zero values in this sparse COO vector.final int
The full size of this sparse COO vector (including the zeros.).Fields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape
-
Constructor Summary
ConstructorsConstructorDescriptionCooVector
(int size) Creates a zero vector of the specifiedsize
.CooVector
(int size, double[] entries, int[] indices) Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.CooVector
(int size, int[] entries, int[] indices) Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.Constructs a copy of the specified sparse COO vector. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double b) Adds a scalar value to each non-zero element of this tensor.Adds a scalar field value to each entry of this tensor.add
(Complex128 b) Adds a scalar field value to each non-zero entry of this tensor.add
(CooCVector b) Computes the element-wise sum between two tensors of the same shape.Computes the element-wise sum between two tensors of the same shape.void
Adds a scalar value to each entry of this tensor and stores the result in this tensor.int[]
argmax()
Finds the indices of the maximum value in this tensor.int[]
Finds the indices of the maximum absolute value in this tensor.int[]
argmin()
Finds the indices of the minimum value in this tensor.int[]
Finds the indices of the minimum absolute value in this tensor.coalesce()
Coalesces this sparse COO vector.coalesce
(BinaryOperator<Double> aggregator) Coalesces this sparse COO vector.div
(Complex128 divisor) Divides each element of this sparse COO vector by a complex-valued scalar.Computes the element-wise division of two vectors.Computes the element-wise division of two vectors.Computes the element-wise quotient between two tensors.Computes the dot product between two vectors.Drops any explicit zeros in this sparse COO vector.Computes the element-wise multiplication between this vector and a real dense vector.Computes the element-wise multiplication of two tensors of the same shape.boolean
Checks if an object is equal to this vector object.flatten()
Flattens tensor to single dimension while preserving order of data.flatten
(int axis) Flattens a tensor along the specified axis.static CooVector
Creates a sparse tensor from a dense tensor.get
(int target) Gets the element of this vector at the specified index.get
(int... target) Gets the element of this tensor at the specified target index.H()
Computes the conjugate transpose of a tensor by exchanging the first and last axes of this tensor and conjugating the exchanged values.H
(int... axes) Computes the conjugate transpose of this tensor.H
(int axis1, int axis2) Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.int
hashCode()
Computes the inner product between two vectors.boolean
Checks if a vector is parallel to this vector.boolean
Checks if a vector is perpendicular to this vector.Joints specified vector with this vector.int
length()
Gets the length of a vector.mag()
Computes the magnitude of this vector.makeLikeTensor
(int size, double[] entries, int[] indices) Constructs a vector of the same type as this tensor with the given the shape and data.makeLikeTensor
(Shape shape, double[] entries) Constructs a tensor of the same type as this tensor with the given the shape and data.mult
(Complex128 factor) Multiplies this vector by a complex scalar value.double
norm()
Computes the Euclidean norm of this vector.double
norm
(int p) Computes the p-norm of this vector.Computes a unit vector in the same direction as this vector.Computes the outer product of two vectors.prod()
Computes the product of all non-zero values in this tensor.recip()
Computes the element-wise reciprocals of the non-zero values of this tensor.repeat
(int n, int axis) Repeats a vectorn
times along a certain axis to create a matrix.Copies and reshapes this tensor.Sets the element of this tensor at the specified indices.void
Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.double
sparsity()
The sparsity of this sparse tensor.Stacks two vectors vertically as if they were row vectors to form a matrix with two rows.Stacks two vectors along specified axis.sub
(double b) Subtracts a scalar value non-zero from each element of this tensor.Subtracts a scalar value from each non-zero entry of this tensor.sub
(Complex128 b) Subtracts a scalar value from each non-zero entry of this tensor.Computes the element-wise difference between two tensors of the same shape.void
Subtracts a scalar value from each non-zero entry of this tensor and stores the result in this tensor.T()
Computes the transpose of a tensor by exchanging the first and last axes of this tensor.T
(int... axes) Computes the transpose of this tensor.T
(int axis1, int axis2) Computes the transpose of a tensor by exchangingaxis1
andaxis2
.Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes.tensorTr
(int axis1, int axis2) Computes the generalized trace of this tensor along the specified axes.Converts this vector to an equivalent sparse vector.toDense()
Converts this sparse tensor to an equivalent dense tensor.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 sparse vector to an equivalent tensor.Methods inherited from class org.flag4j.arrays.backend.primitive_arrays.AbstractDoubleTensor
abs, addEq, conj, copy, div, div, divEq, divEq, isFinite, isInfinite, isNaN, isNeg, isOnes, isPos, isZeros, max, maxAbs, min, minAbs, mult, mult, multEq, multEq, round, round, roundToZero, roundToZero, sqrt, subEq, sum
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring
getData, getRank, getShape, tensorDot, tensorDot, tensorDot, tensorTr
Methods inherited from interface org.flag4j.arrays.backend.VectorMixin
size, toMatrix
-
Field Details
-
indices
public final int[] indicesThe indices of the non-zero data in this sparse COO vector. -
size
public final int sizeThe full size of this sparse COO vector (including the zeros.). -
nnz
public final int nnzThe number of non-zero values in this sparse COO vector.
-
-
Constructor Details
-
CooVector
Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.- Parameters:
entries
- The non-zero data of this vector.indices
- The indices of the non-zero values.size
- The size of this vector.
-
CooVector
-
CooVector
public CooVector(int size, double[] entries, int[] indices) Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.- Parameters:
size
- The size of this vector.entries
- The non-zero data of this vector.indices
- The indices of the non-zero values.
-
CooVector
-
CooVector
public CooVector(int size) Creates a zero vector of the specifiedsize
. -
CooVector
public CooVector(int size, int[] entries, int[] indices) Creates sparse COO vector with the specifiedsize
, non-zero data, and non-zero indices.- Parameters:
size
- The size of this vector.entries
- The non-zero data of this vector.indices
- The indices of the non-zero values.
-
CooVector
Constructs a copy of the specified sparse COO vector.- Parameters:
b
- The vector to construct a copy of.
-
-
Method Details
-
fromDense
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given the shape and data.- Specified by:
makeLikeTensor
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Specified by:
makeLikeTensor
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
shape
- Shape of the tensor to construct.entries
- Entries of the tensor to construct.- Returns:
- A tensor of the same type as this tensor with the given the shape and data.
-
makeLikeTensor
Constructs a vector of the same type as this tensor with the given the shape and data.- Parameters:
entries
- Non-zero data of the vector to construct.indices
- Indices of the non-zero values in this vector.shape
- Shape of the vector to construct.- Returns:
- A vector of the same type as this tensor with the given the shape and data.
-
tensorDot
Computes the tensor contraction of this tensor with a specified tensor over the specified set of axes. That is, computes the sum of products between the two tensors along the specified set of axes.- Specified by:
tensorDot
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Parameters:
src2
- Tensor to contract with this tensor.aAxes
- Axes along which to compute products for this tensor.bAxes
- Axes along which to compute products forsrc2
tensor.- Returns:
- The tensor dot product over the specified axes.
- Throws:
IllegalArgumentException
- If the two tensors shapes do not match along the specified axes pairwise inaAxes
andbAxes
.IllegalArgumentException
- IfaAxes
andbAxes
do not match in length, or if any of the axes are out of bounds for the corresponding tensor.
-
T
Computes the transpose of a tensor by exchangingaxis1
andaxis2
.- Specified by:
T
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
axis1
- First axis to exchange.axis2
- Second axis to exchange.- Returns:
- The transpose of this tensor according to the specified axes.
- Throws:
IndexOutOfBoundsException
- If eitheraxis1
oraxis2
are out of bounds for the rank of this tensor.- See Also:
-
T
Computes the transpose of this tensor. That is, permutes the axes of this tensor so that it matches the permutation specified byaxes
.- Specified by:
T
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.- Returns:
- The transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IndexOutOfBoundsException
- If any element ofaxes
is out of bounds for the rank of this tensor.IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.- See Also:
-
join
Joints specified vector with this vector. That is, creates a vector of lengththis.length() + b.length()
containing first the elements of this vector followed by the elements ofb
. -
inner
Computes the inner product between two vectors.
Note: this method is distinct from
dot(CooVector)
. The inner product is equivalent to the dot product of this tensor with the conjugation ofb
.- Specified by:
inner
in interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - 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 vectorb
do not have the same number of data.- See Also:
-
dot
Computes the dot product between two vectors.
Note: this method is distinct from
inner(CooVector)
. The inner product is equivalent to the dot product of this tensor with the conjugation ofb
.- Specified by:
dot
in interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - Parameters:
b
- Second vector in the dot product.- Returns:
- The dot product between this vector and the vector
b
. - Throws:
IllegalArgumentException
- If this vector and vectorb
do not have the same number of data.- See Also:
-
norm
public double norm()Computes the Euclidean norm of this vector.- Returns:
- The Euclidean norm of this vector.
-
norm
public double norm(int p) Computes the p-norm of this vector.- Parameters:
p
-p
value in the p-norm.- Returns:
- The Euclidean norm of this vector.
-
normalize
Computes a unit vector in the same direction as this vector. -
mag
-
get
-
isParallel
Checks if a vector is parallel to this vector.- Parameters:
b
- Vector to compare to this vector.- Returns:
true
if the vectorb
is parallel to this vector and the same size;false
otherwise.- See Also:
-
isPerp
Checks if a vector is perpendicular to this vector.- Parameters:
b
- Vector to compare to this vector.- Returns:
true
if the vectorb
is perpendicular to this vector and the same size;false
otherwise.- See Also:
-
length
-
sparsity
public double sparsity()The sparsity of this sparse tensor. That is, the percentage of elements in this tensor which are zero as a decimal.- Returns:
- The density of this sparse tensor.
-
toDense
Converts this sparse tensor to an equivalent dense tensor.- Returns:
- A dense tensor equivalent to this sparse tensor.
-
sortIndices
public void sortIndices()Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index. -
get
Gets the element of this tensor at the specified target index.- Specified by:
get
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
target
- Index of the element to get.- Returns:
- The element of this tensor at the specified target index.
- Throws:
IllegalArgumentException
- Iftarget.length != 1
.
-
set
Sets the element of this tensor at the specified indices.- Specified by:
set
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
value
- New value to set the specified index of this tensor to.indices
- Indices of the element to set.- Returns:
- A copy of this tensor with the updated value is returned.
- Throws:
IndexOutOfBoundsException
- Ifindices
is not within the bounds of this tensor.
-
flatten
Flattens tensor to single dimension while preserving order of data.- Specified by:
flatten
in classAbstractTensor<CooVector,
double[], Double> - Returns:
- The flattened tensor.
- See Also:
-
flatten
Flattens a tensor along the specified axis.- Specified by:
flatten
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
axis
- Axis along which to flatten tensor.- Throws:
ArrayIndexOutOfBoundsException
- If the axis is not positive or larger thanthis.{@link #getRank()}-1
.- See Also:
-
reshape
Copies and reshapes this tensor.- Specified by:
reshape
in classAbstractTensor<CooVector,
double[], Double> - Parameters:
newShape
- New shape for the tensor.- Returns:
- A copy of this tensor with the new shape.
- Throws:
TensorShapeException
- IfnewShape
is not broadcastable tothis.shape
.
-
sub
Subtracts a scalar value from each non-zero entry of this tensor.- Specified by:
sub
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Overrides:
sub
in classAbstractDoubleTensor<CooVector>
- Parameters:
b
- Scalar value in difference.- Returns:
- The difference of this tensor's non-zero values and the scalar
b
.
-
sub
Subtracts a scalar value from each non-zero entry of this tensor.- Parameters:
b
- Scalar value in difference.- Returns:
- The difference of this tensor's non-zero values and the scalar
b
.
-
subEq
Subtracts a scalar value from each non-zero entry of this tensor and stores the result in this tensor.- Specified by:
subEq
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Overrides:
subEq
in classAbstractDoubleTensor<CooVector>
- Parameters:
b
- Scalar value in difference.
-
add
Adds a scalar field value to each entry of this tensor.- Specified by:
add
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Overrides:
add
in classAbstractDoubleTensor<CooVector>
- Parameters:
b
- Scalar field value in sum.- Returns:
- The sum of this tensor with the scalar
b
.
-
add
Adds a scalar field value to each non-zero entry of this tensor.- Parameters:
b
- Scalar field value in sum.- Returns:
- The sparse COO vector resulting from adding
b
to each non-zero entry of this vector.
-
addEq
Adds a scalar value to each entry of this tensor and stores the result in this tensor.- Specified by:
addEq
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Overrides:
addEq
in classAbstractDoubleTensor<CooVector>
- Parameters:
b
- Scalar field value in sum.
-
add
Computes the element-wise sum between two tensors of the same shape.- Specified by:
add
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Parameters:
b
- Second tensor in the element-wise sum.- Returns:
- The sum of this tensor with
b
. - Throws:
IllegalArgumentException
- If this tensor andb
do not have the same shape.
-
add
Computes the element-wise sum between two tensors of the same shape.- Parameters:
b
- Second tensor in the element-wise sum.- Returns:
- The sum of this tensor with
b
. - Throws:
IllegalArgumentException
- If this tensor andb
do not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Specified by:
sub
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Parameters:
b
- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b
. - Throws:
IllegalArgumentException
- If this tensor andb
do not have the same shape.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- Specified by:
elemMult
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Parameters:
b
- Second tensor in the element-wise product.- Returns:
- The element-wise product between this tensor and
b
. - Throws:
IllegalArgumentException
- If this tensor andb
do not have the same shape.
-
tensorTr
Computes the generalized trace of this tensor along the specified axes.
The generalized tensor trace is the sum along the diagonal values of the 2D sub-arrays of this tensor specified by
axis1
andaxis2
. The shape of the resulting tensor is equal to this tensor with theaxis1
andaxis2
removed.- Specified by:
tensorTr
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Parameters:
axis1
- First axis for 2D sub-array.axis2
- Second axis for 2D sub-array.- Returns:
- The generalized trace of this tensor along
axis1
andaxis2
. This will be a tensor of rankthis.getRank() - 2
with the same shape as this tensor but withaxis1
andaxis2
removed. - Throws:
IndexOutOfBoundsException
- If the two axes are not both larger than zero and less than this tensors rank.IllegalArgumentException
- Ifaxis1 == axis2
orthis.shape.get(axis1) != this.shape.get(axis1)
(i.e. the axes are equal or the tensor does not have the same length along the two axes.)
-
prod
Computes the product of all non-zero values in this tensor.- Specified by:
prod
in interfaceTensorOverSemiring<CooVector,
CooVector, double[], Double> - Overrides:
prod
in classAbstractDoubleTensor<CooVector>
- Returns:
- The product of all non-zero values in this tensor.
-
T
Computes the transpose of a tensor by exchanging the first and last axes of this tensor.- Overrides:
T
in classAbstractTensor<CooVector,
double[], Double> - Returns:
- The transpose of this tensor.
- See Also:
-
H
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.- Specified by:
H
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Overrides:
H
in classAbstractDoubleTensor<CooVector>
- Parameters:
axis1
- First axis to exchange and conjugate.axis2
- Second axis to exchange and conjugate.- Returns:
- The conjugate transpose of this tensor according to the specified axes.
- Throws:
IndexOutOfBoundsException
- If eitheraxis1
oraxis2
are out of bounds for the rank of this tensor.- See Also:
-
H
Computes the conjugate transpose of this tensor. That is, conjugates and permutes the axes of this tensor so that it matches the permutation specified byaxes
.- Specified by:
H
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Overrides:
H
in classAbstractDoubleTensor<CooVector>
- Parameters:
axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IndexOutOfBoundsException
- If any element ofaxes
is out of bounds for the rank of this tensor.IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.- See Also:
-
argmin
public int[] argmin()Finds the indices of the minimum value in this tensor.- Specified by:
argmin
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Returns:
- The indices of the minimum value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
-
argmax
public int[] argmax()Finds the indices of the maximum value in this tensor.- Specified by:
argmax
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Returns:
- The indices of the maximum value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
-
argminAbs
public int[] argminAbs()Finds the indices of the minimum absolute value in this tensor.- Specified by:
argminAbs
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Returns:
- The indices of the minimum absolute value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
-
argmaxAbs
public int[] argmaxAbs()Finds the indices of the maximum absolute value in this tensor.- Specified by:
argmaxAbs
in interfaceTensorOverRing<CooVector,
CooVector, double[], Double> - Returns:
- The indices of the maximum absolute value in this tensor. If this value occurs multiple times, the indices of the first entry (in row-major ordering) are returned.
-
recip
Computes the element-wise reciprocals of the non-zero values of this tensor.- Specified by:
recip
in interfaceTensorOverField<CooVector,
CooVector, double[], Double> - Overrides:
recip
in classAbstractDoubleTensor<CooVector>
- Returns:
- A tensor containing the reciprocal elements of the non-zero values of this tensor.
-
add
Adds a scalar value to each non-zero element of this tensor.- Specified by:
add
in interfaceTensorOverField<CooVector,
CooVector, double[], Double> - Overrides:
add
in classAbstractDoubleTensor<CooVector>
- Parameters:
b
- Value to add to each non-zero entry of this tensor.- Returns:
- The result of adding the specified scalar value to each entry of this tensor.
-
sub
Subtracts a scalar value non-zero from each element of this tensor.- Specified by:
sub
in interfaceTensorOverField<CooVector,
CooVector, double[], Double> - Overrides:
sub
in classAbstractDoubleTensor<CooVector>
- Parameters:
b
- Value to subtract from each non-zero entry of this tensor.- Returns:
- The result of subtracting the specified scalar value from each entry of this tensor.
-
div
Computes the element-wise quotient between two tensors.
WARNING: This method is not supported for sparse vectors. If called on a sparse vector, an
UnsupportedOperationException
will be thrown. Element-wise division is undefined for sparse vectors as it would almost certainly result in a division by zero.- Specified by:
div
in interfaceTensorOverField<CooVector,
CooVector, double[], Double> - Parameters:
b
- Second tensor in the element-wise quotient.- Returns:
- The element-wise quotient of this tensor with
b
.
-
equals
Checks if an object is equal to this vector object. -
hashCode
-
repeat
Repeats a vectorn
times along a certain axis to create a matrix.- Specified by:
repeat
in interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - Parameters:
n
- Number of times to repeat vector.axis
- Axis along which to repeat vector:- If
axis=0
, then the vector will be treated as a row vector and stacked verticallyn
times. - If
axis=1
then the vector will be treated as a column vector and stacked horizontallyn
times.
- If
- Returns:
- A matrix whose rows/columns are this vector repeated.
-
stack
Stacks two vectors vertically as if they were row vectors to form a matrix with two rows.- Specified by:
stack
in interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - Parameters:
b
- Vector to stack below this vector.- Returns:
- The result of stacking this vector and vector
b
. - Throws:
IllegalArgumentException
- If the number of data in this vector is different from the number of data 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 interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - 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 data in this vector is different from the number of data in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - 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 data.
-
toMatrix
Converts a vector to an equivalent matrix representing either a row or column vector.- Specified by:
toMatrix
in interfaceVectorMixin<CooVector,
CooMatrix, Matrix, Double> - Parameters:
columVector
- Flag indicating 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.
-
toComplex
Converts this vector to an equivalent sparse vector.- Returns:
- A complex COO vector equivalent to this vector.
-
elemMult
Computes the element-wise multiplication between this vector and a real dense vector.- Parameters:
b
- The real dense vector in the element-wise product.- Returns:
- The element-wise product of this vector and
b
. - Throws:
TensorShapeException
- If the two vectors are not the same size.
-
mult
Multiplies this vector by a complex scalar value.- Parameters:
factor
- Scalar value to multiply this vector by.- Returns:
- The result of multiplying this vector by the scalar
factor
.
-
toTensor
Converts this sparse vector to an equivalent tensor.- Returns:
- A tensor equivalent to this vector.
-
div
-
div
Computes the element-wise division of two vectors.- Parameters:
b
- The second vector in the element-wise quotient (denominator).- Returns:
- The element-wise quotient of this vector and
b
.
-
div
Divides each element of this sparse COO vector by a complex-valued scalar.- Parameters:
divisor
- Scalar in the vector-scalar quotient.- Returns:
- The vector-scalar quotient of this vector and
divisor
.
-
coalesce
Coalesces this sparse COO vector. An uncoalesced vector is a sparse vector with multiple data for a single index. This method will ensure that each index only has one non-zero value by summing duplicated data. If another form of aggregation other than summing is desired, usecoalesce(BinaryOperator)
.- Returns:
- A new coalesced sparse COO vector which is equivalent to this COO vector.
- See Also:
-
coalesce
Coalesces this sparse COO vector. An uncoalesced vector is a sparse vector with multiple data for a single index. This method will ensure that each index only has one non-zero value by aggregating duplicated data usingaggregator
.- Parameters:
aggregator
- Custom aggregation function to combine multiple.- Returns:
- A new coalesced sparse COO vector which is equivalent to this COO vector.
- See Also:
-
dropZeros
Drops any explicit zeros in this sparse COO vector.- Returns:
- A copy of this COO vector with any explicitly stored zeros removed.
-
toString
-