Class FieldOps
java.lang.Object
org.flag4j.linalg.ops.common.field_ops.FieldOps
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V extends Field<V>>
voidadd
(double[] src, V scalar, V[] dest) Adds a scalar value to each entry of thesrc
tensor.static <V extends Field<V>>
voidadd
(V[] src, double scalar, V[] dest) Adds a primitive scalar value to each entry of thesrc
tensor.static <V extends Field<V>>
voidconj
(V[] src, V[] dest) Computes the element-wise complex conjugate of a tensor.static <V extends Field<V>>
voiddiv
(double[] src, V scalar, V[] dest) Divides each entry of thesrc
tensor by a scalar.static <V extends Field<V>>
voiddiv
(V[] src, double scalar, V[] dest) Divides each entry of thesrc
tensor by a primitive scalar.static <V extends Field<V>>
voiddiv
(V[] src, V scalar, V[] dest) Divides each entry of thesrc
tensor by a scalar.static <V extends Field<V>>
booleanisFinite
(V[] src) Checks if all elements of a tensor are finite.static <V extends Field<V>>
booleanisInfinite
(V[] src) Checks if any element of a tensor is infinite.static <V extends Field<V>>
booleanisNaN
(V[] src) Checks if any element of a tensor is NaN.static <V extends Field<V>>
voidmult
(double[] src, V scalar, V[] dest) Multiplies a scalar value to each entry of thesrc
tensor.static <V extends Field<V>>
voidmult
(V[] src, double scalar, V[] dest) Multiplies a primitive scalar value to each entry of thesrc
tensor.static <V extends Field<V>>
voidrecip
(V[] src, V[] dest) Computes the reciprocals, element-wise, of a tensor.static <V extends Field<V>>
voidscalMult
(double[] entries, V factor, V[] dest) Computes the scalar multiplication of a tensor.static <T extends Field<T>>
T[]scalMult
(T[] src, double factor, int start, int n, int stride, T[] dest) Scales entries by the specifiedfactor
withinsrc
starting at indexstart
and scaling a total ofn
elements spaced bystride
.static <V extends Field<V>>
voidscalMult
(V[] src, double factor, V[] dest) Computes the scalar multiplication of a tensor with a scalar value.static <V extends Field<V>>
voidsqrt
(V[] src, V[] dest) Computes the element-wise square root of a tensor.static <V extends Field<V>>
voidsub
(double[] src, V scalar, V[] dest) Subtracts a scalar value from each entry of thesrc
tensor.static <V extends Field<V>>
voidsub
(V[] src, double scalar, V[] dest) Subtracts a primitive scalar value from each entry of thesrc
tensor.
-
Method Details
-
add
Adds a primitive scalar value to each entry of thesrc
tensor.- Parameters:
src
- Entries of the tensor to add the scalar to.scalar
- Scalar to add to each entry of the tensor.dest
- Array to store the result of adding the scalar to each entry of the tensor. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
add
Adds a scalar value to each entry of thesrc
tensor.- Parameters:
src
- Entries of the tensor to add the scalar to.scalar
- Scalar to add to each entry of the tensor.dest
- Array to store the result of adding the scalar to each entry of the tensor. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
sub
Subtracts a primitive scalar value from each entry of thesrc
tensor.- Parameters:
src
- Entries of the tensor to subtract scalar from.scalar
- Scalar to subtract from entry of the tensor.dest
- Array to store the result of subtracting the scalar from each entry of the tensor. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
sub
Subtracts a scalar value from each entry of thesrc
tensor.- Parameters:
src
- Entries of the tensor to subtract scalar from.scalar
- Scalar to subtract from entry of the tensor.dest
- Array to store the result of subtracting the scalar from each entry of the tensor. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
mult
Multiplies a primitive scalar value to each entry of thesrc
tensor.- Parameters:
src
- Entries of the tensor to multiply the scalar to.scalar
- Scalar to multiply to each entry of the tensor.dest
- Array to store the result of multiplying the scalar to each entry of the tensor. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
mult
Multiplies a scalar value to each entry of thesrc
tensor.- Parameters:
src
- Entries of the tensor to multiply the scalar to.scalar
- Scalar to multiply to each entry of the tensor.dest
- Array to store the result of multiplying the scalar to each entry of the tensor. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
div
Divides each entry of thesrc
tensor by a scalar.- Parameters:
src
- Entries of the tensor.scalar
- Scalar to divide each entry of the tensor by.dest
- Array to store the result of divided each entry of the tensor by the scalar. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
div
Divides each entry of thesrc
tensor by a scalar.- Parameters:
src
- Entries of the tensor.scalar
- Scalar to divide each entry of the tensor by.dest
- Array to store the result of divided each entry of the tensor by the scalar. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
div
Divides each entry of thesrc
tensor by a primitive scalar.- Parameters:
src
- Entries of the tensor.scalar
- Scalar to divide each entry of the tensor by.dest
- Array to store the result of divided each entry of the tensor by the scalar. May be the same array assrc
.- Throws:
ArrayIndexOutOfBoundsException
- Ifdest.length < src.length
.
-
sqrt
Computes the element-wise square root of a tensor.- Parameters:
src
- Elements of the tensor.dest
- Array to store the result in. May be the same array assrc
.- Throws:
IllegalArgumentException
- Ifdest.length < src.length
.
-
scalMult
Computes the scalar multiplication of a tensor with a scalar value.- Parameters:
src
- Elements of the tensor.factor
- Factor to scale all elements ofsrc
by.dest
- Array to store the result in. May be the same array assrc
.- Throws:
IllegalArgumentException
- Ifdest.length < src.length
.
-
scalMult
Computes the scalar multiplication of a tensor.- Parameters:
entries
- Entries of the tensor.factor
- Scalar value to multiply.dest
- Array to store the result in. May be the same array assrc
.- Throws:
IllegalArgumentException
- Ifdest.length < src.length
.
-
scalMult
public static <T extends Field<T>> T[] scalMult(T[] src, double factor, int start, int n, int stride, T[] dest) Scales entries by the specified
factor
withinsrc
starting at indexstart
and scaling a total ofn
elements spaced bystride
.More formally, this method scales elements by the specified
factor
at indices:start
,start + stride
,start + 2*stride
, ...,start + (n-1)*stride
.This method may be used to scale a row or column of a
matrix
a
as follows:- Maximum absolute value within row
i
:scale(a.data, i*a.numCols, a.numCols, 1, dest);
- Maximum absolute value within column
j
:scale(a.data, j, a.numRows, a.numRows, dest);
- Parameters:
src
- The array containing values to scale.factor
- Factor by which to scale elements.start
- The starting index insrc
to begin scaling.n
- The number of elements to scale withinsrc1
.stride
- The gap (in indices) between consecutive elements to scale withinsrc
.dest
- The array to store the result in. May benull
or the same array assrc
to perform the operation in-place. Assumed to be at least as large assrc
but this is not explicitly enforced.- Returns:
- If
dest == null
a new array containing all elements ofsrc
with the appropriate values scaled. Otherwise, A reference to thedest
array.
- Maximum absolute value within row
-
conj
Computes the element-wise complex conjugate of a tensor.- Parameters:
src
- Entries of the tensor.dest
- Array to store the result in. May be the same array assrc
.- Throws:
IllegalArgumentException
- Ifdest.length < src.length
.
-
recip
Computes the reciprocals, element-wise, of a tensor.- Parameters:
src
- Elements of the tensor.dest
- Array to store the result in. May be the same array assrc
.- Throws:
IllegalArgumentException
- Ifdest.length < src.length
.
-
isFinite
Checks if all elements of a tensor are finite.- Parameters:
src
- Elements of the tensor.- Returns:
true
if every entry ofsrc
is finite;false
otherwise.
-
isInfinite
Checks if any element of a tensor is infinite.- Parameters:
src
- Elements of the tensor.- Returns:
true
if any entry ofsrc
is infinite;false
otherwise.
-
isNaN
Checks if any element of a tensor is NaN.- Parameters:
src
- Elements of the tensor.- Returns:
true
if any entry ofsrc
is NaN;false
otherwise.
-