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.dataof the vector. All other data in the vector are assumed to be zero. Zero values can also explicitly be stored inAbstractTensor.data. - The
indicesof 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 intThe number of non-zero values in this sparse COO vector.final intThe 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[] data, int[] indices) Creates sparse COO vector with the specifiedsize, non-zero data, and non-zero indices.CooVector(int size, int[] data, 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(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.add(Complex128 b) Adds a scalar field value to each non-zero entry of this tensor.voidAdds 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.Computes the element-wise division of two vectors.Computes the element-wise division of two vectors.Computes the element-wise quotient between two tensors.div(Complex128 divisor) Divides each element of this sparse COO vector by a complex-valued scalar.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.booleanChecks 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 CooVectorCreates 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 exchangingaxis1andaxis2.inthashCode()Computes the inner product between two vectors.booleanChecks if a vector is parallel to this vector.booleanChecks if a vector is perpendicular to this vector.Joints specified vector with this vector.intlength()Gets the length of a vector.mag()Computes the magnitude of this vector.makeLikeTensor(int size, double[] data, int[] indices) Constructs a vector of the same type as this tensor with the given the shape and data.makeLikeTensor(Shape shape, double[] data) 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.doublenorm()Computes the Euclidean norm of this vector.doublenorm(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 vectorntimes along a certain axis to create a matrix.Copies and reshapes this tensor.Sets the element of this tensor at the specified indices.voidSorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.doublesparsity()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.Computes the element-wise difference between two tensors of the same shape.sub(Complex128 b) Subtracts a scalar value from each non-zero entry of this tensor.voidSubtracts 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 exchangingaxis1andaxis2.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.static CooVectorunsafeMake(int size, double[] data, int[] indices) Factory to construct a COO vector which bypasses any validation checks on the data and indices.static CooVectorunsafeMake(Shape shape, double[] data, int[] indices) Factory to construct a COO vector which bypasses any validation checks on the data and indices.Methods inherited from class org.flag4j.arrays.backend.primitive_arrays.AbstractDoubleTensor
abs, addEq, conj, copy, dataLength, 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, sumMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, totalEntriesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring
getData, getRank, getShape, tensorDot, tensorDot, tensorDot, tensorTrMethods 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:
data- 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[] data, int[] indices) Creates sparse COO vector with the specifiedsize, non-zero data, and non-zero indices.- Parameters:
size- The size of this vector.data- 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[] data, int[] indices) Creates sparse COO vector with the specifiedsize, non-zero data, and non-zero indices.- Parameters:
size- The size of this vector.data- 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
-
unsafeMake
Factory to construct a COO vector which bypasses any validation checks on the data and indices.
Warning: This method should be used with extreme caution. It primarily exists for internal use. Only use this factory if you are 100% certain the parameters are valid as some methods may throw exceptions or exhibit undefined behavior.
- Parameters:
size- The full size of the COO vector.data- The non-zero entries of the COO vector.indices- The non-zero indices of the COO vector.- Returns:
- A COO vector constructed from the provided parameters.
-
unsafeMake
Factory to construct a COO vector which bypasses any validation checks on the data and indices.
Warning: This method should be used with extreme caution. It primarily exists for internal use. Only use this factory if you are 100% certain the parameters are valid as some methods may throw exceptions or exhibit undefined behavior.
- Parameters:
data- The non-zero entries of the COO vector.indices- The non-zero indices of the COO vector.Shape- Full shape of the COO vector. Assumed to be rank 1 (this is not enforced).- Returns:
- A COO vector constructed from the provided parameters.
-
fromDense
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given the shape and data.- Specified by:
makeLikeTensorin interfaceTensorOverSemiring<CooVector,CooVector, double[], Double> - Specified by:
makeLikeTensorin classAbstractTensor<CooVector,double[], Double> - Parameters:
shape- Shape of the tensor to construct.data- 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:
data- 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:
tensorDotin 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 forsrc2tensor.- Returns:
- The tensor dot product over the specified axes.
- Throws:
IllegalArgumentException- If the two tensors shapes do not match along the specified axes pairwise inaAxesandbAxes.IllegalArgumentException- IfaAxesandbAxesdo 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 exchangingaxis1andaxis2.- Specified by:
Tin 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 eitheraxis1oraxis2are 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:
Tin classAbstractTensor<CooVector,double[], Double> - Parameters:
axes- Permutation of tensor axis. If the tensor has rankN, then this must be an array of lengthNwhich is a permutation of{0, 1, 2, ..., N-1}.- Returns:
- The transpose of this tensor with its axes permuted by the
axesarray. - Throws:
IndexOutOfBoundsException- If any element ofaxesis out of bounds for the rank of this tensor.IllegalArgumentException- Ifaxesis 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:
innerin 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 vectorbdo 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:
dotin 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 vectorbdo 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-pvalue 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:
trueif the vectorbis parallel to this vector and the same size;falseotherwise.- See Also:
-
isPerp
Checks if a vector is perpendicular to this vector.- Parameters:
b- Vector to compare to this vector.- Returns:
trueif the vectorbis perpendicular to this vector and the same size;falseotherwise.- 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:
getin 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:
setin 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- Ifindicesis not within the bounds of this tensor.
-
flatten
Flattens tensor to single dimension while preserving order of data.- Specified by:
flattenin classAbstractTensor<CooVector,double[], Double> - Returns:
- The flattened tensor.
- See Also:
-
flatten
Flattens a tensor along the specified axis.- Specified by:
flattenin 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:
reshapein classAbstractTensor<CooVector,double[], Double> - Parameters:
newShape- New shape for the tensor.- Returns:
- A copy of this tensor with the new shape.
- Throws:
TensorShapeException- IfnewShapeis not broadcastable tothis.shape.
-
sub
Subtracts a scalar value from each non-zero entry of this tensor.- Specified by:
subin interfaceTensorOverRing<CooVector,CooVector, double[], Double> - Overrides:
subin 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:
subEqin interfaceTensorOverRing<CooVector,CooVector, double[], Double> - Overrides:
subEqin classAbstractDoubleTensor<CooVector>- Parameters:
b- Scalar value in difference.
-
add
Adds a scalar field value to each entry of this tensor.- Specified by:
addin interfaceTensorOverSemiring<CooVector,CooVector, double[], Double> - Overrides:
addin 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
bto 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:
addEqin interfaceTensorOverSemiring<CooVector,CooVector, double[], Double> - Overrides:
addEqin classAbstractDoubleTensor<CooVector>- Parameters:
b- Scalar field value in sum.
-
add
Computes the element-wise sum between two tensors of the same shape.- Specified by:
addin 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 andbdo 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 andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Specified by:
subin 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 andbdo not have the same shape.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- Specified by:
elemMultin 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 andbdo 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
axis1andaxis2. The shape of the resulting tensor is equal to this tensor with theaxis1andaxis2removed.- Specified by:
tensorTrin 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
axis1andaxis2. This will be a tensor of rankthis.getRank() - 2with the same shape as this tensor but withaxis1andaxis2removed. - Throws:
IndexOutOfBoundsException- If the two axes are not both larger than zero and less than this tensors rank.IllegalArgumentException- Ifaxis1 == axis2orthis.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:
prodin interfaceTensorOverSemiring<CooVector,CooVector, double[], Double> - Overrides:
prodin 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:
Tin classAbstractTensor<CooVector,double[], Double> - Returns:
- The transpose of this tensor.
- See Also:
-
H
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1andaxis2.- Specified by:
Hin interfaceTensorOverRing<CooVector,CooVector, double[], Double> - Overrides:
Hin 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 eitheraxis1oraxis2are 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:
Hin interfaceTensorOverRing<CooVector,CooVector, double[], Double> - Overrides:
Hin classAbstractDoubleTensor<CooVector>- Parameters:
axes- Permutation of tensor axis. If the tensor has rankN, then this must be an array of lengthNwhich is a permutation of{0, 1, 2, ..., N-1}.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axesarray. - Throws:
IndexOutOfBoundsException- If any element ofaxesis out of bounds for the rank of this tensor.IllegalArgumentException- Ifaxesis 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:
argminin 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:
argmaxin 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:
argminAbsin 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:
argmaxAbsin 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:
recipin interfaceTensorOverField<CooVector,CooVector, double[], Double> - Overrides:
recipin 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:
addin interfaceTensorOverField<CooVector,CooVector, double[], Double> - Overrides:
addin 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:
subin interfaceTensorOverField<CooVector,CooVector, double[], Double> - Overrides:
subin 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
UnsupportedOperationExceptionwill be thrown. Element-wise division is undefined for sparse vectors as it would almost certainly result in a division by zero.- Specified by:
divin 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 vectorntimes along a certain axis to create a matrix.- Specified by:
repeatin 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 verticallyntimes. - If
axis=1then the vector will be treated as a column vector and stacked horizontallyntimes.
- 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:
stackin 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
nalong axis 0 stacks the vectors as if they were row vectors resulting in a2×nmatrix.Stacking two vectors of length
nalong axis 1 stacks the vectors as if they were column vectors resulting in an×2matrix.- Specified by:
stackin 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:
outerin 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:
toMatrixin 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
-