Class AbstractDoubleTensor<T extends AbstractDoubleTensor<T>>
java.lang.Object
org.flag4j.arrays.backend.AbstractTensor<T,double[],Double>
org.flag4j.arrays.backend.primitive_arrays.AbstractDoubleTensor<T>
- All Implemented Interfaces:
Serializable
,TensorOverField<T,
,T, double[], Double> TensorOverRing<T,
,T, double[], Double> TensorOverSemiring<T,
T, double[], Double>
- Direct Known Subclasses:
AbstractDenseDoubleTensor
,CooMatrix
,CooTensor
,CooVector
,CsrMatrix
public abstract class AbstractDoubleTensor<T extends AbstractDoubleTensor<T>>
extends AbstractTensor<T,double[],Double>
implements TensorOverField<T,T,double[],Double>
This is the base class of all real primitive double tensors, matrices, or vectors. The methods implemented in this class are
agnostic to weather the tensor is dense or sparse.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractDoubleTensor
(Shape shape, double[] entries) Creates a tensor with the specified data and shape. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Computes the element-wise absolute value of this tensor.add
(double b) Adds a primitive scalar value to each entry of this tensor.Adds a scalar value to each entry of this tensor.void
addEq
(double b) Adds a primitive scalar value to each entry of this tensor and stores the result in this tensor.void
Adds a scalar value to each entry of this tensor and stores the result in this tensor.conj()
Computes the element-wise conjugation of this tensor.copy()
Creates a deep copy of this tensor.div
(double b) Divides each element of this tensor by a primitive scalar value.Divides each element of this tensor by a scalar value.void
divEq
(double b) Divides each element of this tensor by a primitive scalar value and stores the result in this tensor.void
Divides each element of this tensor by a scalar value and stores the result in this tensor.H
(int... axes) Computes the conjugate transpose of this tensor.H
(int axis1, int axis2) Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.boolean
isFinite()
Checks if this tensor only contains finite values.boolean
Checks if this tensor contains at least one infinite value.boolean
isNaN()
Checks if this tensor contains at least one NaN value.boolean
isNeg()
Checks if this tensor only contains negative values.boolean
isOnes()
Checks if this tensor only contains ones.boolean
isPos()
Checks if this tensor only contains positive values.boolean
isZeros()
Checks if this tensor only contains zeros.max()
Finds the maximum value in this tensor.double
maxAbs()
Finds the maximum absolute value in this tensor.min()
Finds the minimum value in this tensor.double
minAbs()
Finds the minimum value, in absolute value, in this tensor.mult
(double b) Multiplies a primitive scalar value to each entry of this tensor.Multiplies a scalar value to each entry of this tensor.void
multEq
(double b) Multiplies a primitive scalar value to each entry of this tensor and stores the result in this tensor.void
Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.prod()
Computes the product of all values in this tensor.recip()
Computes the element-wise reciprocals of this tensor.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.sqrt()
Computes the element-wise square root of this tensor.sub
(double b) Subtracts a primitive scalar value from each entry of this tensor.Subtracts a scalar value from each entry of this tensor.void
subEq
(double b) Subtracts a scalar primitive value from each entry of this tensor and stores the result in this tensor.void
Subtracts a scalar value from each entry of this tensor and stores the result in this tensor.sum()
Computes the sum of all values in this tensor.Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
flatten, flatten, get, getData, getRank, getShape, makeLikeTensor, reshape, reshape, sameShape, set, T, T, T, 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.arrays.backend.field_arrays.TensorOverField
div
-
Constructor Details
-
AbstractDoubleTensor
Creates a tensor with the specified data and shape.- Parameters:
shape
- Shape of this tensor.entries
- Entries of this tensor. If this tensor is dense, this specifies all data within the tensor. If this tensor is sparse, this specifies only the non-zero data of the tensor.
-
-
Method Details
-
round
Rounds each entry of this tensor to the nearest whole number.- Returns:
- A copy of this tensor with each entry rounded to the nearest whole number.
- See Also:
-
round
Rounds each entry in this tensor to the nearest whole number.- 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.
- Throws:
IllegalArgumentException
- Ifprecision
is negative.- See Also:
-
roundToZero
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 withinFlag4jConstants.EPS_F64
of zero. To specify a threshold value seeroundToZero(double)
.- Returns:
- A copy of this matrix with rounded values.
- See Also:
-
roundToZero
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.- 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.
- Throws:
IllegalArgumentException
- If threshold is negative.- See Also:
-
isPos
public boolean isPos()Checks if this tensor only contains positive values.- Returns:
- Returns
true
if this tensor only contains positive values;false
otherwise.
-
isNeg
public boolean isNeg()Checks if this tensor only contains negative values.- Returns:
- Returns
true
if this tensor only contains negative values;false
otherwise.
-
copy
Creates a deep copy of this tensor.- Specified by:
copy
in classAbstractTensor<T extends AbstractDoubleTensor<T>,
double[], Double> - Returns:
- A deep copy of this tensor.
-
sub
Subtracts a scalar value from each entry of this tensor.- Specified by:
sub
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in difference.- Returns:
- The difference of this tensor and the scalar
b
.
-
subEq
Subtracts a scalar value from each entry of this tensor and stores the result in this tensor.- Specified by:
subEq
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in difference.
-
abs
Computes the element-wise absolute value of this tensor.- Specified by:
abs
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The element-wise absolute value of this tensor.
-
conj
Computes the element-wise conjugation of this tensor.- Specified by:
conj
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The element-wise conjugation of this tensor.
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1
andaxis2
.- Specified by:
H
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
axis1
- First axis to exchange and conjugate.axis2
- Second axis to exchange and conjugate.- Returns:
- The conjugate transpose of this tensor according to the specified axes.
- Throws:
IndexOutOfBoundsException
- If eitheraxis1
oraxis2
are out of bounds for the rank of this tensor.- See Also:
-
H
Computes the conjugate transpose of this tensor. That is, conjugates and permutes the axes of this tensor so that it matches the permutation specified byaxes
.- Specified by:
H
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axes
array. - Throws:
IndexOutOfBoundsException
- If any element ofaxes
is out of bounds for the rank of this tensor.IllegalArgumentException
- Ifaxes
is not a permutation of{1, 2, 3, ... N-1}
.- See Also:
-
min
Finds the minimum value in this tensor.- Specified by:
min
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The minimum value in this tensor.
-
max
Finds the maximum value in this tensor.- Specified by:
max
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The maximum value in this tensor.
-
minAbs
public double minAbs()Finds the minimum value, in absolute value, in this tensor.- Specified by:
minAbs
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The minimum value, in absolute value, in this tensor.
-
maxAbs
public double maxAbs()Finds the maximum absolute value in this tensor.- Specified by:
maxAbs
in interfaceTensorOverRing<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The maximum absolute value in this tensor.
-
add
Adds a scalar value to each entry of this tensor. If the tensor is sparse, the scalar will only be added to the non-zero data of the tensor.- Specified by:
add
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar field value in sum.- Returns:
- The sum of this tensor with the scalar
b
.
-
addEq
Adds a scalar value to each entry of this tensor and stores the result in this tensor.- Specified by:
addEq
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar field value in sum.
-
mult
Multiplies a scalar value to each entry of this tensor.- Specified by:
mult
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in product.- Returns:
- The product of this tensor with
b
.
-
multEq
Multiplies a scalar value to each entry of this tensor and stores the result in this tensor.- Specified by:
multEq
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in product.
-
isZeros
public boolean isZeros()Checks if this tensor only contains zeros.- Specified by:
isZeros
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
true
if this tensor only contains zeros;false
otherwise.
-
isOnes
public boolean isOnes()Checks if this tensor only contains ones. If this tensor is sparse, only the non-zero data are considered.- Specified by:
isOnes
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
true
if this tensor only contains ones;false
otherwise.
-
sum
Computes the sum of all values in this tensor.- Specified by:
sum
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The sum of all values in this tensor.
-
prod
Computes the product of all values in this tensor.- Specified by:
prod
in interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The product of all values in this tensor.
-
add
Adds a primitive scalar value to each entry of this tensor. If the tensor is sparse, the scalar will only be added to the non-zero data of the tensor.- Specified by:
add
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in sum.- Returns:
- The sum of this tensor with the scalar
b
.
-
addEq
public void addEq(double b) Adds a primitive scalar value to each entry of this tensor and stores the result in this tensor.- Specified by:
addEq
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar field value in sum.
-
mult
Multiplies a primitive scalar value to each entry of this tensor.- Specified by:
mult
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in product.- Returns:
- The product of this tensor with
b
.
-
multEq
public void multEq(double b) Multiplies a primitive scalar value to each entry of this tensor and stores the result in this tensor.- Specified by:
multEq
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in product.
-
sub
Subtracts a primitive scalar value from each entry of this tensor.- Specified by:
sub
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in difference.- Returns:
- The difference of this tensor and the scalar
b
.
-
subEq
public void subEq(double b) Subtracts a scalar primitive value from each entry of this tensor and stores the result in this tensor.- Specified by:
subEq
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in difference.
-
div
Divides each element of this tensor by a scalar value.- Specified by:
div
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in quotient.- Returns:
- The element-wise quotient of this tensor and the scalar
b
. - See Also:
-
divEq
Divides each element of this tensor by a scalar value and stores the result in this tensor.- Specified by:
divEq
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in quotient.- See Also:
-
div
Divides each element of this tensor by a primitive scalar value.- Specified by:
div
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in quotient.- Returns:
- The element-wise quotient of this tensor and the scalar
b
. - See Also:
-
divEq
public void divEq(double b) Divides each element of this tensor by a primitive scalar value and stores the result in this tensor.- Specified by:
divEq
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Parameters:
b
- Scalar value in quotient.- See Also:
-
sqrt
Computes the element-wise square root of this tensor.- Specified by:
sqrt
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The element-wise square root of this tensor.
-
recip
Computes the element-wise reciprocals of this tensor.- Specified by:
recip
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
- The element-wise reciprocals of this tensor.
-
isFinite
public boolean isFinite()Checks if this tensor only contains finite values.- Specified by:
isFinite
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
true
if this tensor only contains finite values;false
otherwise.- See Also:
-
isInfinite
public boolean isInfinite()Checks if this tensor contains at least one infinite value.- Specified by:
isInfinite
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
true
if this tensor contains at least one infinite value;false
otherwise.- See Also:
-
isNaN
public boolean isNaN()Checks if this tensor contains at least one NaN value.- Specified by:
isNaN
in interfaceTensorOverField<T extends AbstractDoubleTensor<T>,
T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
true
if this tensor contains at least one NaN value;false
otherwise.- See Also:
-