tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
comparison.h
Go to the documentation of this file.
1#pragma once
2#include "config.h"
3#include "fused/BaseExpr.h"
6#include "helper_traits.h"
8
9// ===============================
10// Comparison Operators
11// ===============================
12
13template <typename LHS, typename RHS>
14bool operator==(const BaseExpr<LHS> &lhs, const BaseExpr<RHS> &rhs) // TODO: conditionally noexcept
15{
16 using lhs_type = typename LHS::value_type;
17 using rhs_type = typename RHS::value_type;
18 static_assert(is_same_v<lhs_type, rhs_type>,
19 "operator== or operator!= : Cannot compare tensors with different scalar types");
20
21#ifdef COMPILETIME_CHECK_DIMENSIONS_COUNT_MISMATCH
22 // Compile-time check that both expressions have the same number of dimensions
23 static_assert(LHS::NumDims == RHS::NumDims, "operator== or operator!= : Cannot compare tensors with different number of dimensions");
24#endif
25#ifdef COMPILETIME_CHECK_DIMENSIONS_SIZE_MISMATCH
26 // Compile-time check that both expressions have the same dimensions
27 static_assert(dims_match<LHS::NumDims>(LHS::Dim, RHS::Dim),
28 "operator== or operator!= : there is at least one dimension mismatch");
29#endif
30
31 // runtime check that all dimensions are the same
32#if defined(RUNTIME_CHECK_DIMENSIONS_COUNT_MISMATCH) || defined(RUNTIME_CHECK_DIMENSIONS_SIZE_MISMATCH)
33 checkDimsMatch(lhs.derived(), rhs.derived(), "operator== or operator!=");
34#endif
35
37 lhs.derived(),
38 rhs.derived(),
39 lhs_type(PRECISION_TOLERANCE));
40}
41
42template <typename LHS, typename RHS>
43bool operator!=(const BaseExpr<LHS> &lhs, const BaseExpr<RHS> &rhs) // TODO: conditionally noexcept
44{
45 return !(lhs == rhs);
46}
Definition BaseExpr.h:15
const Derived & derived() const
Definition BaseExpr.h:17
bool operator==(const BaseExpr< LHS > &lhs, const BaseExpr< RHS > &rhs)
Definition comparison.h:14
bool operator!=(const BaseExpr< LHS > &lhs, const BaseExpr< RHS > &rhs)
Definition comparison.h:43
Global configuration for the tesseract tensor library.
#define PRECISION_TOLERANCE
Tolerance for floating-point comparisons (e.g. symmetry checks, Cholesky).
Definition config.h:117
Façade for higher-level kernel operations built on top of microkernels.
void checkDimsMatch(const Expr1 &lhs, const Expr2 &rhs, const char *opName) TESSERACT_CONDITIONAL_NOEXCEPT
Definition operators_common.h:5
static FORCE_INLINE bool reduce_all_approx_equal(const Expr1 &lhs, const Expr2 &rhs, T tolerance) noexcept
Check if all logical elements of two expressions are approximately equal.
Definition kernel_ops.h:76