Package org.flag4j.operations.common
Class TensorEquals
java.lang.Object
org.flag4j.operations.common.TensorEquals
Utility class for determining if arbitrary pairs of tensors are equal. Could be a real dense tensor and a sparse complex matrix,
if they have the same shape and entries, then they are considered equal.
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final HashMap
<String, BiFunction<CTensor, SparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> private static final HashMap
<String, BiFunction<CooCTensor, SparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> private static final HashMap
<String, BiFunction<Tensor, SparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> private static final HashMap
<String, BiFunction<CooTensor, SparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static TensorBase
<?, ?, ?, ?, ?, ?, ?> ensureTensor
(TensorBase<?, ?, ?, ?, ?, ?, ?> src) Converts a tensor to an explicit tensor if it is a vector or matrix.private static boolean
generalEquals
(CTensor A, DenseTensorBase<?, ?, ?, ?, ?> B) Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).private static boolean
generalEquals
(CTensor A, SparseTensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if a complex dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).private static boolean
generalEquals
(Tensor A, DenseTensorBase<?, ?, ?, ?, ?> B) private static boolean
generalEquals
(Tensor A, SparseTensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).private static boolean
generalEquals
(CooCTensor A, SparseTensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).private static boolean
generalEquals
(CooTensor A, SparseTensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).private static boolean
generalEquals
(DenseTensorBase<?, ?, ?, ?, ?> A, SparseTensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if a dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).static boolean
generalEquals
(TensorBase<?, ?, ?, ?, ?, ?, ?> A, TensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if two arbitrary tensors are equal regardless implementation (e.g.
-
Field Details
-
realDenseLookUp
private static final HashMap<String,BiFunction<Tensor, realDenseLookUpSparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> -
complexDenseLookUp
private static final HashMap<String,BiFunction<CTensor, complexDenseLookUpSparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> -
realSparseLookUp
private static final HashMap<String,BiFunction<CooTensor, realSparseLookUpSparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>> -
complexSparseLookUp
private static final HashMap<String,BiFunction<CooCTensor, complexSparseLookUpSparseTensorBase<?, ?, ?, ?, ?, ?, ?>, Boolean>>
-
-
Constructor Details
-
TensorEquals
private TensorEquals()
-
-
Method Details
-
generalEquals
Checks if two arbitrary tensors are equal regardless implementation (e.g. any combination of real, complex, dense and sparse). Tensors do not need to be the same type and for the purposes of this method, matrices and vectors are considered tensors.- Parameters:
A
- First tensor in equality comparison.B
- Second tensor in equality comparison.- Returns:
- True if both tensors have the same shape and are element-wise equal.
-
ensureTensor
Converts a tensor to an explicit tensor if it is a vector or matrix.- Parameters:
src
- Tensor to convert to an explicit tensor.- Returns:
- Returns
src
if it is already a tensor. Otherwise, i.e.src
is a matrix or vector, returns an explicit tensor equivalent tosrc
.
-
generalEquals
-
generalEquals
Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).- Parameters:
A
- Real dense tensor.B
- Sparse tensor.- Returns:
- True if the two matrices are element-wise equivalent.
-
generalEquals
private static boolean generalEquals(DenseTensorBase<?, ?, ?, ?, ?> A, SparseTensorBase<?, ?, ?, ?, ?, ?, ?> B) Checks if a dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).- Parameters:
A
- Real dense tensor.B
- Sparse tensor.- Returns:
- True if the two matrices are element-wise equivalent.
-
generalEquals
Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).- Parameters:
A
- Real dense tensor.B
- Sparse tensor.- Returns:
- True if the two matrices are element-wise equivalent.
-
generalEquals
Checks if a complex dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).- Parameters:
A
- Real dense tensor.B
- Sparse tensor.- Returns:
- True if the two matrices are element-wise equivalent.
-
generalEquals
Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).- Parameters:
A
- Real dense tensor.B
- Sparse tensor.- Returns:
- True if the two matrices are element-wise equivalent.
-
generalEquals
Checks if a real dense tensor is equal to any sparse tensor (includingCooMatrix
,CsrMatrix
,CooCMatrix
,CsrCMatrix
,CooVector
, etc.).- Parameters:
A
- Real dense tensor.B
- Sparse tensor.- Returns:
- True if the two matrices are element-wise equivalent.
-