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
ConstructorsModifierConstructorDescriptionprotectedAbstractDoubleTensor(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.voidaddEq(double b) Adds a primitive scalar value to each entry of this tensor and stores the result in this tensor.voidAdds 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.intGets the size of the 1D data array backing 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.voiddivEq(double b) Divides each element of this tensor by a primitive scalar value and stores the result in this tensor.voidDivides 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 exchangingaxis1andaxis2.booleanisFinite()Checks if this tensor only contains finite values.booleanChecks if this tensor contains at least one infinite value.booleanisNaN()Checks if this tensor contains at least one NaN value.booleanisNeg()Checks if this tensor only contains negative values.booleanisOnes()Checks if this tensor only contains ones.booleanisPos()Checks if this tensor only contains positive values.booleanisZeros()Checks if this tensor only contains zeros.max()Finds the maximum value in this tensor.doublemaxAbs()Finds the maximum absolute value in this tensor.min()Finds the minimum value in this tensor.doubleminAbs()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.voidmultEq(double b) Multiplies a primitive scalar value to each entry of this tensor and stores the result in this tensor.voidMultiplies 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.voidsubEq(double b) Subtracts a scalar primitive value from each entry of this tensor and stores the result in this tensor.voidSubtracts 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, totalEntriesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
-
dataLength
public int dataLength()Gets the size of the 1D data array backing this tensor.- Specified by:
dataLengthin classAbstractTensor<T extends AbstractDoubleTensor<T>,double[], Double> - Returns:
- The size of the 1D data array backing this tensor.
-
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- Ifprecisionis 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_F64of 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
trueif this tensor only contains positive values;falseotherwise.
-
isNeg
public boolean isNeg()Checks if this tensor only contains negative values.- Returns:
- Returns
trueif this tensor only contains negative values;falseotherwise.
-
copy
Creates a deep copy of this tensor.- Specified by:
copyin 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:
subin 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:
subEqin 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:
absin 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:
conjin 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 exchangingaxis1andaxis2.- Specified by:
Hin 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 eitheraxis1oraxis2are 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:
Hin 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 lengthNwhich is a permutation of{0, 1, 2, ..., N-1}.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axesarray. - Throws:
IndexOutOfBoundsException- If any element ofaxesis out of bounds for the rank of this tensor.IllegalArgumentException- Ifaxesis not a permutation of{1, 2, 3, ... N-1}.- See Also:
-
min
Finds the minimum value in this tensor.- Specified by:
minin 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:
maxin 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:
minAbsin 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:
maxAbsin 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:
addin 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:
addEqin 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:
multin 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:
multEqin 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:
isZerosin interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
trueif this tensor only contains zeros;falseotherwise.
-
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:
isOnesin interfaceTensorOverSemiring<T extends AbstractDoubleTensor<T>,T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
trueif this tensor only contains ones;falseotherwise.
-
sum
Computes the sum of all values in this tensor.- Specified by:
sumin 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:
prodin 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:
addin 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:
addEqin 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:
multin 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:
multEqin 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:
subin 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:
subEqin 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:
divin 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:
divEqin 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:
divin 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:
divEqin 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:
sqrtin 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:
recipin 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:
isFinitein interfaceTensorOverField<T extends AbstractDoubleTensor<T>,T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
trueif this tensor only contains finite values;falseotherwise.- See Also:
-
isInfinite
public boolean isInfinite()Checks if this tensor contains at least one infinite value.- Specified by:
isInfinitein interfaceTensorOverField<T extends AbstractDoubleTensor<T>,T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
trueif this tensor contains at least one infinite value;falseotherwise.- See Also:
-
isNaN
public boolean isNaN()Checks if this tensor contains at least one NaN value.- Specified by:
isNaNin interfaceTensorOverField<T extends AbstractDoubleTensor<T>,T extends AbstractDoubleTensor<T>, double[], Double> - Returns:
trueif this tensor contains at least one NaN value;falseotherwise.- See Also:
-