Class CTensor
- All Implemented Interfaces:
Serializable
,FieldTensorMixin<CTensor,
,CTensor, Complex128> TensorOverField<CTensor,
,CTensor, Complex128[], Complex128> RingTensorMixin<CTensor,
,CTensor, Complex128> TensorOverRing<CTensor,
,CTensor, Complex128[], Complex128> SemiringTensorMixin<CTensor,
,CTensor, Complex128> TensorOverSemiring<CTensor,
CTensor, Complex128[], Complex128>
A dense complex tensor backed by an array of Complex128
's.
The AbstractTensor.data
of a tensor are mutable but the AbstractTensor.shape
is fixed.
- See Also:
-
Field Summary
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
ConstructorsConstructorDescriptionCreates a tensor from an nD array.Constructs a copy of the specified tensor.Creates a zero tensor with the specified shape.Creates a tensor with the specified shape and filled withfillValue
.Creates a tensor with the specified data and shape.Creates a tensor with the specified shape and filled withfillValue
.Creates a tensor with the specified data and shape.CTensor
(Shape shape, Complex128 fillValue) Creates a tensor with the specified shape and filled withfillValue
.CTensor
(Shape shape, Complex128[] entries) Creates a tensor with the specified data and shape.Creates a tensor with the specified shape and filled withfillValue
.Creates a tensor with the specified data and shape. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value of this tensor.Computes the element-wise sum between two tensors of the same shape.add
(CooCTensor 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 hte result in this tensor.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 tensor object.int
hashCode()
boolean
Checks if any entry within this tensor has non-zero imaginary component.boolean
isReal()
Checks if all data of this tensor are real.makeEmptyDataArray
(int length) Creates an empty array of the same type as the data array of this tensor.protected CooCTensor
makeLikeCooTensor
(Shape shape, Complex128[] entries, int[][] indices) Constructs a sparse COO tensor which is of a similar type as this dense tensor.makeLikeTensor
(Shape shape, Complex128[] entries) Constructs a tensor of the same type as this tensor with the given the shape and data.round
(int precision) Rounds all data within this tensor to the specified precision.roundToZero
(double tolerance) Sets all elements of this tensor to zero if they are withintol
of zero.Computes the element-wise difference between two tensors of the same shape.sub
(CooCTensor 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 of this tensor with a real dense tensor and stores the result in this tensor.toCoo()
Converts this tensor to an equivalent sparse COO tensor.toCoo
(double estimatedSparsity) Converts this tensor to an equivalent sparse COO tensor.toMatrix()
Converts this tensor to an equivalent matrix.toReal()
Converts this complex tensor to a real tensor.toString()
Formats this tensor as a human-readable string.toVector()
Converts this tensor to an equivalent vector.Methods inherited from class org.flag4j.arrays.backend.field_arrays.AbstractDenseFieldTensor
allClose, allClose, div, H, isFinite, isInfinite, isNaN, sqrt
Methods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractDenseRingTensor
argmaxAbs, argminAbs, H, maxAbs, minAbs, sub, subEq
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, norm, norm, prod, recip, sub, sub, subEq, subEq, sum
Methods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
H, H, sub
-
Constructor Details
-
CTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor.
-
CTensor
Creates a tensor from an nD array. The tensors shape will be inferred from.- Parameters:
nDArray
- Array to construct tensor from. Must be a rectangular array.- Throws:
IllegalArgumentException
- IfnDArray
is not an array or not rectangular.
-
CTensor
-
CTensor
Creates a zero tensor with the specified shape.- Parameters:
shape
- Shape of this tensor.
-
CTensor
Creates a tensor with the specified shape and filled withfillValue
.- Parameters:
shape
- Shape of this tensor.fillValue
- Value to fill this tensor with.
-
CTensor
-
CTensor
Creates a tensor with the specified shape and filled withfillValue
.- Parameters:
shape
- Shape of this tensor.fillValue
- Value to fill this tensor with.
-
CTensor
Creates a tensor with the specified shape and filled withfillValue
.- Parameters:
shape
- Shape of this tensor.fillValue
- Value to fill this tensor with. Must be a string representation of a complex number parsable byComplexNumberParser.parseNumberToComplex128(String)
.
-
CTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor. Each value indata
must be formated as a complex number such as:- "a"
- "a + bi", "a - bi", "a + i", or "a - i"
- "bi", "i", or "-i"
-
CTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor.
-
CTensor
Constructs a copy of the specified tensor.- Parameters:
tensor
- Tensor to create copy of.
-
-
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.
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given the shape and data.- Specified by:
makeLikeTensor
in interfaceTensorOverSemiring<CTensor,
CTensor, Complex128[], Complex128> - Specified by:
makeLikeTensor
in classAbstractTensor<CTensor,
Complex128[], Complex128> - 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.
-
makeLikeCooTensor
Constructs a sparse COO tensor which is of a similar type as this dense tensor.- Specified by:
makeLikeCooTensor
in classAbstractDenseSemiringTensor<CTensor,
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.
-
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 hte 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.
-
subEq
Computes the element-wise difference of this tensor with a real dense tensor and stores the result in this tensor.- Parameters:
b
- Second tensor in element-wise difference.
-
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
-
toCoo
Converts this tensor to an equivalent sparse COO tensor.- Overrides:
toCoo
in classAbstractDenseSemiringTensor<CTensor,
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<CTensor,
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:
-
toReal
Converts this complex tensor to a real tensor. This conversion is done by taking the real component of each entry and ignoring the imaginary component.- Returns:
- A real tensor containing the real components of the data of this tensor.
-
isReal
public boolean isReal()Checks if all data of this tensor are real.- Returns:
true
if all data of this tensor are real;false
otherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this tensor has non-zero imaginary component.- Returns:
true
if any entry of this tensor has a non-zero imaginary component.
-
round
Rounds all data within this tensor 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 tensor containing the data of this tensor rounded to the specified precision.
-
roundToZero
Sets all elements of this tensor 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 tensor with all data within
tol
of zero set to zero.
-
toMatrix
Converts this tensor to an equivalent matrix. If this tensor is not rank-2, it will be flattened to a row vector before conversion.- Returns:
- A matrix which is equivalent to this tensor.
-
toVector
Converts this tensor to an equivalent vector. If the tensor is not rank-1, it will be flattened first.- Returns:
- A vector which is equivalent to this tensor.
-
abs
Computes the element-wise absolute value of this tensor.- Returns:
- The element-wise absolute value of this tensor.
-
equals
Checks if an object is equal to this tensor object. -
hashCode
-
toString
-