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
size
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElement
Fields 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 specifiedsize
and filled withfillValue
.CVector
(int size, Complex128 fillValue) Creates a complex vector with the specifiedsize
and filled withfillValue
.Creates a complex vector with the specifiedsize
and filled withfillValue
.CVector
(Complex128... entries) Creates a complex vector with the specifieddata
.Creates a complex vector with the specifieddata
.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. -
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.void
Computes 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.boolean
Checks if an object is equal to this vector object.static CVector
getEmpty
(int size) Constructs an empty vector with the specified size.int
hashCode()
double
Compute the inner product of this vector with itself.boolean
Checks if any entry within this vector has non-zero imaginary component.boolean
isReal()
Checks if all data of this vector are real.mag()
Computes the magnitude of this vector.double
Computes 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 CooCVector
makeLikeCooTensor
(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 specifiedshape
anddata
.makeLikeTensor
(Complex128[] entries) Constructs a dense vector with the specifieddata
of the same type as the vector.makeLikeTensor
(Shape shape, Complex128[] entries) Constructs a tensor of the same type as this tensor with the given theshape
anddata
.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 withintol
of zero.void
set
(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.void
Computes 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, sqrt
Methods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractDenseRingVector
H, sub, subEq
Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringVector
dot, get, join, length, repeat, stack, toMatrix
Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, elemMult, flatten, flatten, get, getZeroElement, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTr
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, T, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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, sum
Methods 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 specifiedsize
and filled withfillValue
.- Parameters:
size
- The size of the vector.fillValue
- The value to fill the vector with.
-
CVector
Creates a complex vector with the specifiedsize
and 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 specifiedsize
and 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() != 1
IllegalArgumentException
- 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:SemiringTensorMixin
Creates 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 toval
in this vector.- Throws:
IndexOutOfBoundsException
- Ifindex
is 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
null
values) with the specified size.
-
makeLikeTensor
Constructs a dense vector with the specifieddata
of the same type as the vector.- Specified by:
makeLikeTensor
in 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 specifiedshape
anddata
.- Specified by:
makeLikeMatrix
in 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
shape
anddata
.
-
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 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:
TensorShapeException
- If this tensor andb
do 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 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:
TensorShapeException
- If this tensor andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do not have the same shape.
-
div
-
normalize
Normalizes this vector to a unit length vector.- Specified by:
normalize
in interfaceVectorMixin<CVector,
CMatrix, CMatrix, Complex128> - Overrides:
normalize
in classAbstractDenseFieldVector<CVector,
CMatrix, Complex128> - Returns:
- This vector normalized to a unit length.
-
mag
Computes the magnitude of this vector.- Specified by:
mag
in interfaceVectorMixin<CVector,
CMatrix, CMatrix, Complex128> - Overrides:
mag
in 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:
makeLikeCooTensor
in 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:
toCoo
in 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:
toCoo
in 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 theshape
anddata
. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensor
in interfaceTensorOverSemiring<CVector,
CVector, Complex128[], Complex128> - Specified by:
makeLikeTensor
in 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
shape
anddata
.
-
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:
true
if all data of this tensor are real;false
otherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this vector has non-zero imaginary component.- Returns:
true
if 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 withintol
of 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
tol
of 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 orb
do 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)
.
-