Package org.flag4j.core.dense_base
Class RealDenseTensorBase<T extends RealDenseTensorBase<T,W>,W extends ComplexDenseTensorBase<W,T>>
java.lang.Object
org.flag4j.core.TensorBase<T,T,W,W,T,double[],Double>
org.flag4j.core.dense_base.DenseTensorBase<T,W,T,double[],Double>
org.flag4j.core.dense_base.RealDenseTensorBase<T,W>
- Type Parameters:
T
- Type of this tensor.W
- Complex Tensor type.
- All Implemented Interfaces:
Serializable
,DenseMixin<Double>
,RealTensorMixin<T,
,W> TensorComparisonsMixin
,TensorManipulationsMixin<T>
,TensorOperationsMixin<T,
,T, W, W, T, Double> TensorPropertiesMixin
public abstract class RealDenseTensorBase<T extends RealDenseTensorBase<T,W>,W extends ComplexDenseTensorBase<W,T>>
extends DenseTensorBase<T,W,T,double[],Double>
implements RealTensorMixin<T,W>
The base class for all real dense tensors. This includes real dense matrices and vectors.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.core.TensorBase
DEFAULT_ROUND_TO_ZERO_THRESHOLD, entries, shape
-
Constructor Summary
ModifierConstructorDescriptionprotected
RealDenseTensorBase
(Shape shape, double[] entries) Creates a real dense tensor with specified entries and shape. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value/magnitude of a tensor.add
(double b) Adds specified value to all entries of this tensor.Adds specified value to all entries of this tensor.Computes the element-wise addition between two tensors of the same rank.void
Subtracts a specified value from all entries of this tensor and stores the result in this tensor.void
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.boolean
Checks if all entries of this tensor are close to the entries of the argumenttensor
.int[]
argMax()
Finds the indices of the maximum value in this tensor.int[]
argMin()
Finds the indices of the minimum value in this tensor.copy()
Creates a deep copy of this tensor.div
(double b) Computes the scalar division of a tensor.Computes the scalar division of a tensor.Computes the element-wise division between two tensors.Computes the element-wise multiplication between two tensors.get
(int... indices) Gets the element in this tensor at the specified indices.int
hashCode()
Creates a hashcode for this matrix.boolean
isNeg()
Checks if this tensor contains only non-positive values.boolean
isOnes()
Checks if this tensor only contains ones.boolean
isPos()
Checks if this tensor contains only non-negative values.boolean
isZeros()
Checks if this tensor only contains zeros.protected abstract W
makeComplexTensor
(Shape shape, double[] entries) Factory to create a complex tensor with the specified shape and size.protected abstract W
makeComplexTensor
(Shape shape, CNumber[] entries) Factory to create a complex tensor with the specified shape and size.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 b) Computes scalar multiplication of a tensor.Computes scalar multiplication of a tensor.recip()
Computes the reciprocals, element-wise, of a tensor.reshape
(int... shape) Copies and reshapes tensor if possible.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.set
(double value, int... indices) Sets an index of this tensor to a specified value.sqrt()
Computes the element-wise square root of a tensor.sub
(double b) Adds specified value to all entries of this tensor.Adds specified value to all entries of this tensor.Computes the element-wise subtraction between two tensors of the same rank.void
Subtracts a specified value from all entries of this tensor and stores the result in this tensor.void
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.sum()
Sums together all entries in the tensor.Converts this tensor to an equivalent complex tensor.Methods inherited from class org.flag4j.core.dense_base.DenseTensorBase
makeTensor, toCoo
Methods inherited from class org.flag4j.core.TensorBase
allClose, getEntries, getRank, getSelf, getShape, sameLength, sameShape, tensorEquals, totalEntries
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.flag4j.core.TensorComparisonsMixin
equals
Methods inherited from interface org.flag4j.core.TensorManipulationsMixin
flatten, flatten
Methods inherited from interface org.flag4j.core.TensorOperationsMixin
T, transpose
-
Constructor Details
-
RealDenseTensorBase
Creates a real dense tensor with specified entries and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor. The number of entries must match the product of allshape
dimensions.- Throws:
IllegalArgumentException
- If the number of entries does not equal the product of dimensions in theshape
.
-
-
Method Details
-
makeComplexTensor
-
makeComplexTensor
-
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.
-
argMin
public int[] argMin()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.
-
argMax
public int[] argMax()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.
-
isPos
public boolean isPos()Description copied from interface:RealTensorMixin
Checks if this tensor contains only non-negative values.- Specified by:
isPos
in interfaceRealTensorMixin<T extends RealDenseTensorBase<T,
W>, W extends ComplexDenseTensorBase<W, T>> - Returns:
- True if this tensor only contains non-negative values. Otherwise, returns false.
-
isNeg
public boolean isNeg()Description copied from interface:RealTensorMixin
Checks if this tensor contains only non-positive values.- Specified by:
isNeg
in interfaceRealTensorMixin<T extends RealDenseTensorBase<T,
W>, W extends ComplexDenseTensorBase<W, T>> - Returns:
- trie if this tensor only contains non-positive values. Otherwise, returns false.
-
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()Description copied from interface:TensorComparisonsMixin
Checks if this tensor only contains ones.- Specified by:
isOnes
in interfaceTensorComparisonsMixin
- Returns:
- True if this tensor only contains ones. Otherwise, returns false.
-
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.- Specified by:
abs
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Returns:
- The result of applying an element-wise absolute value/magnitude to this tensor.
-
sqrt
Description copied from interface:TensorOperationsMixin
Computes the element-wise square root of a tensor.- Specified by:
sqrt
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Returns:
- The result of applying an element-wise square root to this tensor. Note, this method will compute the principle square root i.e. the square root with positive real part.
-
add
Description copied from interface:TensorOperationsMixin
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
-
sub
Description copied from interface:TensorOperationsMixin
Computes the element-wise subtraction between two tensors of the same rank.- Specified by:
sub
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
B
- Second tensor in element-wise subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
-
add
Description copied from interface:TensorOperationsMixin
Adds specified value to all entries of this tensor.- Specified by:
add
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
b
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
sub
Description copied from interface:TensorOperationsMixin
Adds specified value to all entries of this tensor.- Specified by:
sub
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
b
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
mult
Description copied from interface:TensorOperationsMixin
Computes scalar multiplication of a tensor.- Specified by:
mult
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
b
- Scalar value to multiply with tensor.- Returns:
- The result of multiplying this tensor by the specified scalar.
-
div
Description copied from interface:TensorOperationsMixin
Computes the scalar division of a tensor.- Specified by:
div
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
b
- The scalar value to divide tensor by.- Returns:
- The result of dividing this tensor by the specified scalar.
-
elemMult
Description copied from interface:TensorOperationsMixin
Computes the element-wise multiplication between two tensors.- Specified by:
elemMult
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
B
- Tensor to element-wise multiply to this tensor.- Returns:
- The result of the element-wise tensor multiplication.
-
elemDiv
Description copied from interface:TensorOperationsMixin
Computes the element-wise division between two tensors.- Specified by:
elemDiv
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
B
- Tensor to element-wise divide with this tensor.- Returns:
- The result of the element-wise tensor multiplication.
-
addEq
Description copied from class:DenseTensorBase
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.- Specified by:
addEq
in classDenseTensorBase<T extends RealDenseTensorBase<T,
W>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, double[], Double> - Parameters:
B
- Second tensor in the subtraction.
-
addEq
Description copied from interface:DenseMixin
Subtracts a specified value from all entries of this tensor and stores the result in this tensor.- Specified by:
addEq
in interfaceDenseMixin<T extends RealDenseTensorBase<T,
W>> - Parameters:
b
- Value to subtract from all entries of this tensor.
-
subEq
Description copied from class:DenseTensorBase
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.- Specified by:
subEq
in classDenseTensorBase<T extends RealDenseTensorBase<T,
W>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, double[], Double> - Parameters:
B
- Second tensor in the subtraction.
-
subEq
Description copied from interface:DenseMixin
Subtracts a specified value from all entries of this tensor and stores the result in this tensor.- Specified by:
subEq
in interfaceDenseMixin<T extends RealDenseTensorBase<T,
W>> - Parameters:
b
- Value to subtract from all entries of this tensor.
-
sum
Sums together all entries in the tensor.- Specified by:
sum
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Returns:
- The sum of all entries in this tensor.
-
set
Sets an index of this tensor to a specified value.- Specified by:
set
in interfaceTensorManipulationsMixin<T extends RealDenseTensorBase<T,
W>> - Parameters:
value
- Value to set.indices
- The indices of this tensor for which to set the value.- Returns:
- A reference to this tensor.
- Throws:
IllegalArgumentException
- If the number of indices provided does not match the rank of this tensor.IllegalArgumentException
- If any of the indices are outside the tensor for that respective axis.
-
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 extends RealDenseTensorBase<T,
W>> - Parameters:
shape
- 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.
-
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 extends RealDenseTensorBase<T,
W>> - Parameters:
shape
- 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.
-
recip
Computes the reciprocals, element-wise, of a tensor.- Specified by:
recip
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Returns:
- A tensor containing the reciprocal elements of this tensor.
- Throws:
ArithmeticException
- If this tensor contains any zeros.
-
get
Gets the element in this tensor at the specified indices.- Specified by:
get
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
indices
- Indices of element.- Returns:
- The element at the specified indices.
- Throws:
IllegalArgumentException
- If the number of indices does not match the rank of this tensor.
-
copy
Creates a deep copy of this tensor.- Specified by:
copy
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Returns:
- A deep copy of this tensor.
-
toComplex
Converts this tensor to an equivalent complex tensor. That is, the entries of the resultant matrix will be exactly the same value but will have typeCNumber
rather thanDouble
.- Specified by:
toComplex
in interfaceRealTensorMixin<T extends RealDenseTensorBase<T,
W>, W extends ComplexDenseTensorBase<W, T>> - Returns:
- A complex matrix which is equivalent to this matrix.
-
add
Adds specified value to all entries of this tensor.- Specified by:
add
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
sub
Adds specified value to all entries of this tensor.- Specified by:
sub
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
a
- Value to add to all entries of this tensor.- Returns:
- The result of adding the specified value to each entry of this tensor.
-
mult
Computes scalar multiplication of a tensor.- Specified by:
mult
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
factor
- Scalar value to multiply with tensor.- Returns:
- The result of multiplying this tensor by the specified scalar.
-
div
Computes the scalar division of a tensor.- Specified by:
div
in interfaceTensorOperationsMixin<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, Double> - Parameters:
divisor
- The scalar value to divide tensor by.- Returns:
- The result of dividing this tensor by the specified scalar.
- Throws:
ArithmeticException
- If divisor is zero.
-
hashCode
public int hashCode()Creates a hashcode for this matrix. Note, method addsArrays.hashCode(double[])
applied on the underlying data array and the underlying shape array. -
round
Description copied from interface:TensorManipulationsMixin
Rounds each entry of this tensor to the nearest whole number.- Specified by:
round
in interfaceTensorManipulationsMixin<T extends RealDenseTensorBase<T,
W>> - 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 extends RealDenseTensorBase<T,
W>> - 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:
-
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 extends RealDenseTensorBase<T,
W>> - 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 extends RealDenseTensorBase<T,
W>> - 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:
-
allClose
Description copied from class:TensorBase
Checks if all entries of this tensor are close to the entries of the argumenttensor
.- Specified by:
allClose
in classTensorBase<T extends RealDenseTensorBase<T,
W>, T extends RealDenseTensorBase<T, W>, W extends ComplexDenseTensorBase<W, T>, W extends ComplexDenseTensorBase<W, T>, T extends RealDenseTensorBase<T, W>, double[], Double> - Parameters:
tensor
- Tensor to compare this tensor to.relTol
- Relative tolerance.absTol
- Absolute tolerance.- Returns:
- True if the argument
tensor
is the same shape as this tensor and all entries are 'close', i.e. elementsa
andb
at the same positions in the two tensors respectively satisfy|a-b| <= (atol + rtol*|b|)
. Otherwise, returns false. - See Also:
-