From 2a29a2a6a1784223a9caf1fae2a768fe550b5f64 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 16 Nov 2024 21:02:52 +0200 Subject: ipa: libipa: vector: Add element-wise min() and max() functions Add functions to calculate the element-wise minimum and maximum of two vectors or of a vector and a scalar. This will be used in algorithm implementations. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- src/ipa/libipa/vector.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/ipa/libipa/vector.h') diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 3b387bf6..937a28e9 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -148,6 +148,26 @@ public: return apply(scalar, [](T a, T b) { return a / b; }); } + constexpr Vector min(const Vector &other) const + { + return apply(*this, other, [](T a, T b) { return std::min(a, b); }); + } + + constexpr Vector min(T scalar) const + { + return apply(*this, scalar, [](T a, T b) { return std::min(a, b); }); + } + + constexpr Vector max(const Vector &other) const + { + return apply(*this, other, [](T a, T b) { return std::max(a, b); }); + } + + constexpr Vector max(T scalar) const + { + return apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); }); + } + constexpr T dot(const Vector &other) const { T ret = 0; -- cgit v1.2.1