Class RealOperations
java.lang.Object
org.flag4j.operations.common.real.RealOperations
This class provides low level methods for computing operations on real tensors. These methods can be applied to
either sparse or dense real tensors.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]
abs
(double[] src) Computes the element-wise absolute value of a tensor.static double[]
round
(double[] src) Rounds the values of a tensor to the nearest integer.static double[]
round
(double[] src, int precision) Rounds the values of a tensor with specified precision.static double[]
roundToZero
(double[] src, double threshold) Rounds values which are close to zero in absolute value to zero.static double[]
scalDiv
(double[] src, double divisor) Computes the scalar division of a tensor.static double[]
scalMult
(double[] src, double factor) Computes the scalar multiplication of a tensor.static double[]
scalMult
(double[] src, double[] dest, double factor) Computes the scalar multiplication of a tensor.static double[]
scalMult
(double[] src, double[] dest, double factor, int start, int stop) Computes the scalar multiplication of a tensor.static double[]
sqrt
(double[] src) Computes the element-wise square root of a tensor.
-
Constructor Details
-
RealOperations
private RealOperations()
-
-
Method Details
-
scalMult
public static double[] scalMult(double[] src, double factor) Computes the scalar multiplication of a tensor.- Parameters:
src
- Entries of the tensor.factor
- Scalar value to multiply.- Returns:
- The scalar multiplication of the tensor.
-
scalMult
public static double[] scalMult(double[] src, double[] dest, double factor) Computes the scalar multiplication of a tensor.- Parameters:
src
- Entries of the tensor.dest
- Array to store result in. May be null.factor
- Scalar value to multiply.- Returns:
- A reference to the
dest
array if it was not null. Otherwise, a new array will be formed. - Throws:
ArrayIndexOutOfBoundsException
- Ifdest
is not at least the size ofsrc
.
-
scalMult
public static double[] scalMult(double[] src, double[] dest, double factor, int start, int stop) Computes the scalar multiplication of a tensor.- Parameters:
src
- Entries of the tensor.dest
- Array to store result in. May be null.factor
- Scalar value to multiply.start
- Starting index of scalar multiplication.stop
- Stopping index of scalar multiplication.- Returns:
- A reference to the
dest
array if it was not null. Otherwise, a new array will be formed. - Throws:
ArrayIndexOutOfBoundsException
- Ifdest
is not the size ofsrc
.
-
scalDiv
public static double[] scalDiv(double[] src, double divisor) Computes the scalar division of a tensor.- Parameters:
src
- Entries of the tensor.divisor
- Scalar value to divide.- Returns:
- The scalar division of the tensor.
-
sqrt
public static double[] sqrt(double[] src) Computes the element-wise square root of a tensor.- Parameters:
src
- Elements of the tensor.- Returns:
- The element-wise square root of the tensor.
-
abs
public static double[] abs(double[] src) Computes the element-wise absolute value of a tensor.- Parameters:
src
- Elements of the tensor.- Returns:
- The element-wise absolute value of the tensor.
-
round
public static double[] round(double[] src) Rounds the values of a tensor to the nearest integer. Also seeround(double[], int)
.- Parameters:
src
- Entries of the tensor to round.- Returns:
- The result of rounding all entries of the source tensor to the nearest integer.
- Throws:
IllegalArgumentException
- Ifprecision
is negative.
-
round
public static double[] round(double[] src, int precision) Rounds the values of a tensor with specified precision. Note, if precision is zero,round(double[])
is preferred.- Parameters:
src
- Entries of the tensor to round.precision
- Precision to round to (i.e. the number of decimal places).- Returns:
- The result of rounding all entries of the source tensor with the specified precision.
- Throws:
IllegalArgumentException
- Ifprecision
is negative.
-
roundToZero
public static double[] roundToZero(double[] src, double threshold) Rounds values which are close to zero in absolute value to zero.- Parameters:
threshold
- Threshold for rounding values to zero. That is, if a value in this tensor 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
- Ifthreshold
is negative.
-