tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
minmax.h
Go to the documentation of this file.
1#pragma once
2#include "config.h"
3#include "fused/BinaryExpr.h"
4#include "fused/ScalarExpr.h"
5#include "fused/Operations.h"
9
10// ===============================
11// Min/Max Operators
12// ===============================
13
14// tensor min tensor
15template <typename LHS, typename RHS>
16 requires(
22min(const BaseExpr<LHS> &lhs, const BaseExpr<RHS> &rhs) // TODO: conditionally noexcept
23{
24#if defined(RUNTIME_CHECK_DIMENSIONS_COUNT_MISMATCH) || defined(RUNTIME_CHECK_DIMENSIONS_SIZE_MISMATCH)
25 checkDimsMatch(lhs.derived(), rhs.derived(), "min");
26#endif
27 return BinaryExpr<LHS, RHS, Min>(lhs.derived(), rhs.derived());
28}
29
30// tensor max tensor
31template <typename LHS, typename RHS>
32 requires(
38max(const BaseExpr<LHS> &lhs, const BaseExpr<RHS> &rhs) // TODO: conditionally noexcept
39{
40#if defined(RUNTIME_CHECK_DIMENSIONS_COUNT_MISMATCH) || defined(RUNTIME_CHECK_DIMENSIONS_SIZE_MISMATCH)
41 checkDimsMatch(lhs.derived(), rhs.derived(), "max");
42#endif
43 return BinaryExpr<LHS, RHS, Max>(lhs.derived(), rhs.derived());
44}
45
46// min(tensor, scalar)
47template <typename LHS, typename T>
50 !is_base_of_v<detail::BaseExprTag, T>)
52min(const BaseExpr<LHS> &lhs, T scalar) noexcept
53{
54 return ScalarExprRHS<LHS, T, Min>(lhs.derived(), scalar);
55}
56
57// min(scalar, tensor) — commutative
58template <typename RHS, typename T>
61 !is_base_of_v<detail::BaseExprTag, T>)
63min(T scalar, const BaseExpr<RHS> &rhs) noexcept
64{
65 return ScalarExprRHS<RHS, T, Min>(rhs.derived(), scalar);
66}
67
68// max(tensor, scalar)
69template <typename LHS, typename T>
72 !is_base_of_v<detail::BaseExprTag, T>)
74max(const BaseExpr<LHS> &lhs, T scalar) noexcept
75{
76 return ScalarExprRHS<LHS, T, Max>(lhs.derived(), scalar);
77}
78
79// max(scalar, tensor) — commutative
80template <typename RHS, typename T>
83 !is_base_of_v<detail::BaseExprTag, T>)
85max(T scalar, const BaseExpr<RHS> &rhs) noexcept
86{
87 return ScalarExprRHS<RHS, T, Max>(rhs.derived(), scalar);
88}
Definition BaseExpr.h:15
const Derived & derived() const
Definition BaseExpr.h:17
Definition BinaryExpr.h:15
Definition ScalarExpr.h:14
Global configuration for the tesseract tensor library.
BinaryExpr< LHS, RHS, Max > max(const BaseExpr< LHS > &lhs, const BaseExpr< RHS > &rhs)
Definition minmax.h:38
BinaryExpr< LHS, RHS, Min > min(const BaseExpr< LHS > &lhs, const BaseExpr< RHS > &rhs)
Definition minmax.h:22
constexpr bool is_vector_space_v
Definition basic_algebraic_traits.h:123
void checkDimsMatch(const Expr1 &lhs, const Expr2 &rhs, const char *opName) TESSERACT_CONDITIONAL_NOEXCEPT
Definition operators_common.h:5