Package org.flag4j.core
Interface TensorManipulationsMixin<T>
- Type Parameters:
T
- Tensor type.
- All Known Implementing Classes:
CMatrix
,ComplexDenseTensorBase
,ComplexSparseTensorBase
,CooCMatrix
,CooCTensor
,CooCVector
,CooMatrix
,CooTensor
,CooVector
,CsrCMatrix
,CsrMatrix
,CTensor
,CVector
,DenseTensorBase
,Matrix
,RealDenseTensorBase
,RealSparseTensorBase
,SparseTensorBase
,Tensor
,TensorBase
,Vector
interface TensorManipulationsMixin<T>
This interface specifies manipulations which all tensors (i.e. matrices and vectors) should implement.
-
Method Summary
Modifier and TypeMethodDescriptionflatten()
Flattens tensor to single dimension.flatten
(int axis) Flattens a tensor along the specified axis.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.
-
Method Details
-
set
Sets an index of this tensor to a specified value.- Parameters:
value
- Value to set.indices
- The indices of this tensor for which to set the value.- Returns:
- A reference to this tensor.
-
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.- 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.- 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.
-
flatten
T flatten()Flattens tensor to single dimension. To flatten tensor along a single axis.- Returns:
- The flattened tensor.
-
flatten
Flattens a tensor along the specified axis.- Parameters:
axis
- Axis along which to flatten tensor.- Throws:
IllegalArgumentException
- If the axis is not positive or larger than the rank of this tensor.
-
round
T 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
T 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 within 1.0*E^-12 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:
-