Class CVector
java.lang.Object
- All Implemented Interfaces:
Serializable,FieldTensorMixin<CVector,,CVector, Complex128> TensorOverField<CVector,,CVector, Complex128[], Complex128> RingTensorMixin<CVector,,CVector, Complex128> TensorOverRing<CVector,,CVector, Complex128[], Complex128> SemiringTensorMixin<CVector,,CVector, Complex128> TensorOverSemiring<CVector,,CVector, Complex128[], Complex128> VectorMixin<CVector,CMatrix, CMatrix, Complex128>
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringVector
sizeFields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElementFields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape -
Constructor Summary
ConstructorsConstructorDescriptionCVector(double... entries) Creates a complex vector with the specifieddata.CVector(int size) Creates a complex zero vector with the specifiedsize.CVector(int... entries) Creates a complex vector with the specifieddata.CVector(int size, double fillValue) Creates a complex vector with the specifiedsizeand filled withfillValue.CVector(int size, Complex128 fillValue) Creates a complex vector with the specifiedsizeand filled withfillValue.Creates a complex vector with the specifiedsizeand filled withfillValue.Creates a copy of the provided vector.Constructs a zero vector with the specified shape.CVector(Shape shape, Complex128[] data) Constructs a dense complex vector with the given shape and entries.CVector(Complex128... entries) Creates a complex vector with the specifieddata.Creates a complex vector with the specifieddata. -
Method Summary
Modifier and TypeMethodDescriptionComputes the element-wise sum between two tensors of the same shape.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.voidComputes the element-wise sum between two tensors of the same shape and stores the result in this tensor.Computes the vector cross product between two vectors.Computes the element-wise quotient between two tensors.Computes the element-wise multiplication of two tensors of the same shape.Computes the element-wise multiplication of two tensors of the same shape.Computes the element-wise multiplication of two tensors of the same shape.booleanChecks if an object is equal to this vector object.static CVectorgetEmpty(int size) Constructs an empty vector with the specified size.inthashCode()doubleCompute the inner product of this vector with itself.booleanChecks if any entry within this vector has non-zero imaginary component.booleanisReal()Checks if all data of this vector are real.mag()Computes the magnitude of this vector.doubleComputes the magnitude of this vector as a double value.makeEmptyDataArray(int length) Creates an empty array of the same type as the data array of this tensor.protected CooCVectormakeLikeCooTensor(Shape shape, Complex128[] entries, int[][] indices) Constructs a sparse COO tensor which is of a similar type as this dense tensor.makeLikeMatrix(Shape shape, Complex128[] entries) Constructs a matrix of similar type to this vector with the specifiedshapeanddata.makeLikeTensor(Shape shape, Complex128[] entries) Constructs a tensor of the same type as this tensor with the given theshapeanddata.makeLikeTensor(Complex128[] entries) Constructs a dense vector with the specifieddataof the same type as the vector.Normalizes this vector to a unit length vector.round(int precision) Rounds all data within this vector to the specified precision.roundToZero(double tolerance) Sets all elements of this vector to zero if they are withintolof zero.voidset(double val, int index) Sets the specified index of this vector to the provided real value.Computes the element-wise difference between two tensors of the same shape.sub(CooCVector b) Computes the element-wise difference between two tensors of the same shape.Computes the element-wise difference between two tensors of the same shape.voidComputes the element-wise difference between two vectors of the same shape.toCoo()Converts this tensor to an equivalent sparse COO tensor.toCoo(double estimatedSparsity) Converts this tensor to an equivalent sparse COO tensor.toReal()Converts this complex vector to a real vector.toString()Converts this vector to a human-readable string format.Methods inherited from class org.flag4j.arrays.backend.field_arrays.AbstractDenseFieldVector
abs, allClose, allClose, div, H, inner, isFinite, isInfinite, isNaN, norm, norm, outer, sqrtMethods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractDenseRingVector
H, sub, subEqMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringVector
dot, get, join, length, repeat, stack, toMatrixMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, dataLength, elemMult, flatten, flatten, get, getZeroElement, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTrMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, T, totalEntriesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.flag4j.arrays.backend.field_arrays.FieldTensorMixin
add, add, addEq, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, div, div, divEq, divEq, isOnes, isZeros, max, maxAbs, min, minAbs, mult, mult, multEq, multEq, prod, recip, sub, sub, subEq, subEq, sumMethods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
H, H, sub
-
Constructor Details
-
CVector
Creates a complex vector with the specifieddata.- Parameters:
entries- Entries of this vector.
-
CVector
Creates a complex vector with the specifieddata.- Parameters:
entries- Entries of this vector.
-
CVector
public CVector(double... entries) Creates a complex vector with the specifieddata.- Parameters:
entries- Entries of this vector.
-
CVector
public CVector(int... entries) Creates a complex vector with the specifieddata.- Parameters:
entries- Entries of this vector.
-
CVector
Creates a complex vector with the specifiedsizeand filled withfillValue.- Parameters:
size- The size of the vector.fillValue- The value to fill the vector with.
-
CVector
Creates a complex vector with the specifiedsizeand filled withfillValue.- Parameters:
size- The size of the vector.fillValue- The value to fill the vector with.
-
CVector
public CVector(int size, double fillValue) Creates a complex vector with the specifiedsizeand filled withfillValue.- Parameters:
size- The size of the vector.fillValue- The value to fill the vector with.
-
CVector
public CVector(int size) Creates a complex zero vector with the specifiedsize.- Parameters:
size- The size of the vector.
-
CVector
Creates a copy of the provided vector.- Parameters:
vector- Vector to create a copy of.
-
CVector
Constructs a dense complex vector with the given shape and entries.- Parameters:
shape- The shape of the vector. Must be rank-1 and satisfyshape.totalEntriesIntValueExact() == data.length.data- The entries of the vector.- Throws:
LinearAlgebraException- Ifshape.getRank() != 1IllegalArgumentException- Ifshape.totalEntriesIntValueExact() != data.length
-
CVector
Constructs a zero vector with the specified shape.- Parameters:
shape- Shape of the zero vector to construct. Must be rank 1.
-
-
Method Details
-
makeEmptyDataArray
Description copied from interface:SemiringTensorMixinCreates an empty array of the same type as the data array of this tensor.- Parameters:
length- The length of the array to construct.- Returns:
- An empty array of the same type as the data array of this tensor.
-
set
public void set(double val, int index) Sets the specified index of this vector to the provided real value.- Parameters:
val- Value to set in this vector.index- Index to set tovalin this vector.- Throws:
IndexOutOfBoundsException- Ifindexis not in bounds of this vector.
-
getEmpty
Constructs an empty vector with the specified size. The data of the resulting vector will be all benull.- Parameters:
size- The size of the vector to construct.- Returns:
- An empty vector (i.e. filled with
nullvalues) with the specified size.
-
makeLikeTensor
Constructs a dense vector with the specifieddataof the same type as the vector.- Specified by:
makeLikeTensorin classAbstractDenseSemiringVector<CVector,CMatrix, Complex128> - Parameters:
entries- Entries of the dense vector to construct.
-
makeLikeMatrix
Constructs a matrix of similar type to this vector with the specifiedshapeanddata.- Specified by:
makeLikeMatrixin classAbstractDenseSemiringVector<CVector,CMatrix, Complex128> - Parameters:
shape- Shape of the matrix to construct.entries- Entries of the matrix to construct.- Returns:
- A matrix of similar type to this vector with the specified
shapeanddata.
-
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:
TensorShapeException- 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:
TensorShapeException- If this tensor andbdo not have the same shape.
-
addEq
Computes the element-wise sum between two tensors of the same shape and stores the result in this tensor.- Parameters:
b- Second tensor in the element-wise sum.- Throws:
TensorShapeException- 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:
TensorShapeException- If this tensor andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- 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.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- 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.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- 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.
-
div
-
normalize
Normalizes this vector to a unit length vector.- Specified by:
normalizein interfaceVectorMixin<CVector,CMatrix, CMatrix, Complex128> - Overrides:
normalizein classAbstractDenseFieldVector<CVector,CMatrix, Complex128> - Returns:
- This vector normalized to a unit length.
-
mag
Computes the magnitude of this vector.- Specified by:
magin interfaceVectorMixin<CVector,CMatrix, CMatrix, Complex128> - Overrides:
magin classAbstractDenseFieldVector<CVector,CMatrix, Complex128> - Returns:
- The magnitude of this vector.
-
magAsDouble
public double magAsDouble()Computes the magnitude of this vector as a double value.- Returns:
- The magnitude of this vector as a double value.
-
makeLikeCooTensor
Constructs a sparse COO tensor which is of a similar type as this dense tensor.- Specified by:
makeLikeCooTensorin classAbstractDenseSemiringTensor<CVector,Complex128> - Parameters:
shape- Shape of the COO tensor.entries- Non-zero data of the COO tensor.indices-- Returns:
- A sparse COO tensor which is of a similar type as this dense tensor.
-
toCoo
Converts this tensor to an equivalent sparse COO tensor.- Overrides:
toCooin classAbstractDenseSemiringTensor<CVector,Complex128> - Returns:
- A sparse COO tensor that is equivalent to this dense tensor.
- See Also:
-
toCoo
Converts this tensor to an equivalent sparse COO tensor.- Overrides:
toCooin classAbstractDenseSemiringTensor<CVector,Complex128> - Parameters:
estimatedSparsity- Estimated sparsity of the tensor. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse COO tensor that is equivalent to this dense tensor.
- See Also:
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given theshapeanddata. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensorin interfaceTensorOverSemiring<CVector,CVector, Complex128[], Complex128> - Specified by:
makeLikeTensorin classAbstractTensor<CVector,Complex128[], Complex128> - Parameters:
shape- Shape of the tensor to construct.entries- Entries of the tensor to construct.- Returns:
- A tensor of the same type and with the same non-zero indices as this tensor with the given the
shapeanddata.
-
toReal
Converts this complex vector to a real vector. This conversion is done by taking the real component of each entry and ignoring the imaginary component.- Returns:
- A real vector containing the real components of the data of this vector.
-
isReal
public boolean isReal()Checks if all data of this vector are real.- Returns:
trueif all data of this tensor are real;falseotherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this vector has non-zero imaginary component.- Returns:
trueif any entry of this vector has a non-zero imaginary component.
-
round
Rounds all data within this vector to the specified precision.- Parameters:
precision- The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.- Returns:
- A new vector containing the data of this vector rounded to the specified precision.
-
roundToZero
Sets all elements of this vector to zero if they are withintolof zero. This is not done in place.- Parameters:
precision- The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.- Returns:
- A copy of this vector with all data within
tolof zero set to zero.
-
innerSelf
public double innerSelf()Compute the inner product of this vector with itself.- Returns:
-
cross
Computes the vector cross product between two vectors.
Note: Formally speaking, the vector cross product cannot be defined for complex vectors while maintaining the same properties as vectors from invalid input: 'ℝ'3 (e.g. orthogonality). However, it can still be defined algebraically in the same way as it is for real vectors though it may fail to satisfy properties of a true cross product. This is algebraic definition is what this method implements.
- Parameters:
b- Second vector in the cross product.- Returns:
- The result of the vector cross product between this vector and
b. - Throws:
IllegalArgumentException- If either this vector orbdo not have exactly 3 data.
-
subEq
Computes the element-wise difference between two vectors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Throws:
TensorShapeException- If!this.shape.equals(b.shape).
-
equals
Checks if an object is equal to this vector object. -
hashCode
-
toString
Converts this vector to a human-readable string format. To specify the maximum number of data to print, usePrintOptions.setMaxColumns(int).
-