Package org.flag4j.core.sparse_base
Class ComplexSparseTensorBase<T,U,Y>
java.lang.Object
org.flag4j.core.TensorBase<T,U,T,U,Y,CNumber[],CNumber>
org.flag4j.core.sparse_base.SparseTensorBase<T,U,T,U,Y,CNumber[],CNumber>
org.flag4j.core.sparse_base.ComplexSparseTensorBase<T,U,Y>
- Type Parameters:
T
- Type of this tensor.U
- Dense Tensor type.Y
- Real tensor type.
- All Implemented Interfaces:
Serializable
,ComplexTensorMixin<T,
,Y> SparseTensorMixin
,TensorComparisonsMixin
,TensorManipulationsMixin<T>
,TensorOperationsMixin<T,
,U, T, U, Y, CNumber> TensorPropertiesMixin
- Direct Known Subclasses:
CooCMatrix
,CooCTensor
,CooCVector
,CsrCMatrix
public abstract class ComplexSparseTensorBase<T,U,Y>
extends SparseTensorBase<T,U,T,U,Y,CNumber[],CNumber>
implements ComplexTensorMixin<T,Y>
This abstract class is the base class of all complex sparse tensors.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.core.sparse_base.SparseTensorBase
indices, nnz
Fields inherited from class org.flag4j.core.TensorBase
DEFAULT_ROUND_TO_ZERO_THRESHOLD, entries, shape
-
Constructor Summary
ModifierConstructorDescriptionprotected
ComplexSparseTensorBase
(Shape shape, int nonZeroEntries, CNumber[] entries, int[][] indices) Creates a sparse tensor with specified shape.protected
ComplexSparseTensorBase
(Shape shape, int nonZeroEntries, CNumber[] entries, int[] initIndices, int[]... restIndices) Creates a sparse tensor with specified shape. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value/magnitude of a tensor.int[]
argMax()
Finds the indices of the maximum value in this tensor.int[]
argMin()
Finds the indices of the minimum value in this tensor.conj()
Computes the complex conjugate of a tensor.private int[][]
Creates a deep copy of the indices of this sparse tensor.div
(double divisor) Computes the scalar division of a tensor.Computes the scalar division of a tensor.boolean
Checks if this tensor contains at least one complex entry.boolean
isOnes()
Checks if this sparse tensors non-zero values are all ones.boolean
isReal()
Checks if this tensor has only real valued entries.boolean
isZeros()
Checks if this tensor only contains zeros.protected abstract Y
makeRealTensor
(Shape shape, double[] entries, int[][] indices) A factory for creating a real sparse tensor.protected abstract T
makeTensor
(Shape shape, CNumber[] entries, int[][] indices) A factory for creating a complex sparse tensor.double
max()
Finds the maximum value in this tensor.double
maxAbs()
Finds the maximum value, in absolute value, in this tensor.double
min()
Finds the minimum value in this tensor.double
minAbs()
Finds the minimum value, in absolute value, in this tensor.mult
(double a) Computes scalar multiplication of a tensor.Computes scalar multiplication of a tensor.int
Gets the number of non-zero entries stored in this sparse tensor.recip()
Computes the reciprocals, element-wise, of a tensor.reshape
(int... dims) Copies and reshapes tensor if possible.round()
Rounds each entry of this tensor to the nearest whole number.round
(int precision) Rounds each entry in this tensor to the nearest whole number.Rounds values in this tensor which are close to zero in absolute value to zero.roundToZero
(double threshold) Rounds values which are close to zero in absolute value to zero.void
Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.sqrt()
Computes the element-wise square root of a tensor.sum()
Sums together all entries in the tensor.toReal()
Converts a complex tensor to a real matrix.Converts a complex tensor to a real matrix safely.Methods inherited from class org.flag4j.core.sparse_base.SparseTensorBase
density, sparsity, toDense
Methods inherited from class org.flag4j.core.TensorBase
allClose, allClose, getEntries, getRank, getSelf, getShape, sameLength, sameShape, tensorEquals, totalEntries
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.flag4j.core.ComplexTensorMixin
H, hermTranspose, set
Methods inherited from interface org.flag4j.core.TensorComparisonsMixin
equals
Methods inherited from interface org.flag4j.core.TensorManipulationsMixin
flatten, flatten, reshape, set
-
Constructor Details
-
ComplexSparseTensorBase
protected ComplexSparseTensorBase(Shape shape, int nonZeroEntries, CNumber[] entries, int[][] indices) Creates a sparse tensor with specified shape. Note, this constructor stores indices for each element in the same array. That is, for a shape with rankm
andn
non-zero entries, the indices array will have shapen-by-m
. This is the opposite ofComplexSparseTensorBase(Shape, int, CNumber[], int[], int[][])
.- Parameters:
shape
- Shape of this tensor.nonZeroEntries
- Number of non-zero entries in the sparse tensor.entries
- Non-zero entries of this sparse tensor.indices
- Indices of the non-zero entries.- Throws:
IllegalArgumentException
- If the number of rows in the indices array is not equal to the number of elements in the entries array.IllegalArgumentException
- If the number of columns in the entries array is not equal to the rank of this tensor.
-
ComplexSparseTensorBase
protected ComplexSparseTensorBase(Shape shape, int nonZeroEntries, CNumber[] entries, int[] initIndices, int[]... restIndices) Creates a sparse tensor with specified shape. Note, this constructor stores indices for each element in different arrays. That is, for a shape with rankm
andn
non-zero entries, the indices array will have shapem-by-n
. This is the opposite ofComplexSparseTensorBase(Shape, int, CNumber[], int[][])
.- Parameters:
shape
- ShapenonZeroEntries
- The number of non-zero entries of the tensor.entries
- Non-zero entries of the sparse tensor.initIndices
- Non-zero indices of the first axis of the tensor.restIndices
- Non-zero indices of the rest of this tensor's axes.
-
-
Method Details
-
copyIndices
private int[][] copyIndices()Creates a deep copy of the indices of this sparse tensor.- Returns:
- A deep copy of the indices of this sparse tensor.
-
makeTensor
A factory for creating a complex sparse tensor.- Parameters:
shape
- Shape of the sparse tensor to make.entries
- Non-zero entries of the sparse tensor to make.indices
- Non-zero indices of the sparse tensor to make.- Returns:
- A tensor created from the specified parameters.
-
makeRealTensor
A factory for creating a real sparse tensor.- Parameters:
shape
- Shape of the sparse tensor to make.entries
- Non-zero entries of the sparse tensor to make.indices
- Non-zero indices of the sparse tensor to make.- Returns:
- A tensor created from the specified parameters.
-
sortIndices
public void sortIndices()Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.- Specified by:
sortIndices
in interfaceSparseTensorMixin
-
nonZeroEntries
public int nonZeroEntries()Gets the number of non-zero entries stored in this sparse tensor.- Overrides:
nonZeroEntries
in classSparseTensorBase<T,
U, T, U, Y, CNumber[], CNumber> - Returns:
- The number of non-zero entries stored in this tensor.
-
min
public double min()Description copied from interface:TensorPropertiesMixin
Finds the minimum value in this tensor. If this tensor is complex, then this method finds the smallest value in magnitude.- Specified by:
min
in interfaceTensorPropertiesMixin
- Returns:
- The minimum value (smallest in magnitude for a complex valued tensor) in this tensor.
-
max
public double max()Description copied from interface:TensorPropertiesMixin
Finds the maximum value in this tensor. If this tensor is complex, then this method finds the largest value in magnitude.- Specified by:
max
in interfaceTensorPropertiesMixin
- Returns:
- The maximum value (largest in magnitude for a complex valued tensor) in this tensor.
-
minAbs
public double minAbs()Description copied from interface:TensorPropertiesMixin
Finds the minimum value, in absolute value, in this tensor. If this tensor is complex, then this method is equivalent toTensorPropertiesMixin.min()
.- Specified by:
minAbs
in interfaceTensorPropertiesMixin
- Returns:
- The minimum value, in absolute value, in this tensor.
-
maxAbs
public double maxAbs()Description copied from interface:TensorPropertiesMixin
Finds the maximum value, in absolute value, in this tensor. If this tensor is complex, then this method is equivalent toTensorPropertiesMixin.max()
.- Specified by:
maxAbs
in interfaceTensorPropertiesMixin
- Returns:
- The maximum value, in absolute value, in this tensor.
-
isZeros
public boolean isZeros()Description copied from interface:TensorComparisonsMixin
Checks if this tensor only contains zeros.- Specified by:
isZeros
in interfaceTensorComparisonsMixin
- Returns:
- True if this tensor only contains zeros. Otherwise, returns false.
-
isOnes
public boolean isOnes()Checks if this sparse tensors non-zero values are all ones.- Specified by:
isOnes
in interfaceTensorComparisonsMixin
- Returns:
- True if this sparse tensors non-zero values are all ones. False otherwise.
-
sum
Description copied from interface:TensorOperationsMixin
Sums together all entries in the tensor. -
mult
Description copied from interface:TensorOperationsMixin
Computes scalar multiplication of a tensor. -
mult
Description copied from interface:TensorOperationsMixin
Computes scalar multiplication of a tensor. -
div
Description copied from interface:TensorOperationsMixin
Computes the scalar division of a tensor. -
div
Description copied from interface:TensorOperationsMixin
Computes the scalar division of a tensor. -
sqrt
Description copied from interface:TensorOperationsMixin
Computes the element-wise square root of a tensor. -
abs
Description copied from interface:TensorOperationsMixin
Computes the element-wise absolute value/magnitude of a tensor. If the tensor contains complex values, the magnitude will be computed. -
conj
Description copied from interface:ComplexTensorMixin
Computes the complex conjugate of a tensor.- Specified by:
conj
in interfaceComplexTensorMixin<T,
U> - Returns:
- The complex conjugate of this tensor.
-
recip
Description copied from interface:TensorOperationsMixin
Computes the reciprocals, element-wise, of a tensor. -
isComplex
public boolean isComplex()Description copied from interface:ComplexTensorMixin
Checks if this tensor contains at least one complex entry.- Specified by:
isComplex
in interfaceComplexTensorMixin<T,
U> - Returns:
- True if this tensor contains at least one complex entry. Otherwise, returns false.
-
isReal
public boolean isReal()Description copied from interface:ComplexTensorMixin
Checks if this tensor has only real valued entries.- Specified by:
isReal
in interfaceComplexTensorMixin<T,
U> - Returns:
- True if this tensor contains NO complex entries. Otherwise, returns false.
-
round
Description copied from interface:TensorManipulationsMixin
Rounds each entry of this tensor to the nearest whole number.- Specified by:
round
in interfaceTensorManipulationsMixin<T>
- Returns:
- A copy of this tensor with each entry rounded to the nearest whole number.
- See Also:
-
round
Description copied from interface:TensorManipulationsMixin
Rounds each entry in this tensor to the nearest whole number.- Specified by:
round
in interfaceTensorManipulationsMixin<T>
- Parameters:
precision
- The number of decimal places to round to. This value must be non-negative.- Returns:
- A copy of this matrix with rounded values.
- See Also:
-
argMax
public int[] argMax()Description copied from interface:TensorPropertiesMixin
Finds the indices of the maximum value in this tensor.- Specified by:
argMax
in interfaceTensorPropertiesMixin
- 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.
-
argMin
public int[] argMin()Description copied from interface:TensorPropertiesMixin
Finds the indices of the minimum value in this tensor.- Specified by:
argMin
in interfaceTensorPropertiesMixin
- 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.
-
toReal
Converts a complex tensor to a real matrix. The imaginary component of any complex value will be ignored.- Specified by:
toReal
in interfaceComplexTensorMixin<T,
U> - Returns:
- A tensor of the same size containing only the real components of this tensor.
- See Also:
-
toRealSafe
Converts a complex tensor to a real matrix safely. That is, first checks if the tensor only contains real values and then converts to a real tensor. However, if non-real value exist, then an error is thrown.- Specified by:
toRealSafe
in interfaceComplexTensorMixin<T,
U> - Returns:
- A tensor of the same size containing only the real components of this tensor.
- Throws:
RuntimeException
- If this tensor contains at least one non-real value.- See Also:
-
reshape
Copies and reshapes tensor if possible. The total number of entries in this tensor must match the total number of entries in the reshaped tensor.- Specified by:
reshape
in interfaceTensorManipulationsMixin<T>
- Parameters:
dims
- Shape of the new tensor.- Returns:
- A tensor which is equivalent to this tensor but with the specified shape.
- Throws:
IllegalArgumentException
- If this tensor cannot be reshaped to the specified dimensions.
-
roundToZero
Description copied from interface:TensorManipulationsMixin
Rounds values in this tensor which are close to zero in absolute value to zero. If the matrix is complex, both the real and imaginary components will be rounded independently. By default, the values must be within 1.0*E^-12 of zero. To specify a threshold value seeTensorManipulationsMixin.roundToZero(double)
.- Specified by:
roundToZero
in interfaceTensorManipulationsMixin<T>
- Returns:
- A copy of this matrix with rounded values.
- See Also:
-
roundToZero
Description copied from interface:TensorManipulationsMixin
Rounds values which are close to zero in absolute value to zero. If the matrix is complex, both the real and imaginary components will be rounded independently.- Specified by:
roundToZero
in interfaceTensorManipulationsMixin<T>
- Parameters:
threshold
- Threshold for rounding values to zero. That is, if a value in this matrix is less than the threshold in absolute value then it will be rounded to zero. This value must be non-negative.- Returns:
- A copy of this matrix with rounded values.
- See Also:
-