summaryrefslogtreecommitdiff
path: root/src/ipa/libipa/vector.h
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-11-16 21:02:52 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-11-26 19:05:19 +0200
commitf0d73c8758cf5def353489dfcab0cb4a157be667 (patch)
tree5a452ad06f4fa013ac2d743057ba50048406c228 /src/ipa/libipa/vector.h
parent49e961ca3598922f62ec9381dc1d742b4c1c0b31 (diff)
ipa: libipa: vector: Add missing binary arithemtic operators
The Vector class defines multiple element-wise arithmetic operators between vectors or between a vector and a scalar. A few variants are missing. Add them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Diffstat (limited to 'src/ipa/libipa/vector.h')
-rw-r--r--src/ipa/libipa/vector.h32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index 5545da12..15a60951 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -68,24 +68,44 @@ public:
return ret;
}
+ constexpr Vector operator+(const Vector &other) const
+ {
+ return apply(*this, other, std::plus<>{});
+ }
+
+ constexpr Vector operator+(T scalar) const
+ {
+ return apply(*this, scalar, std::plus<>{});
+ }
+
constexpr Vector operator-(const Vector &other) const
{
return apply(*this, other, std::minus<>{});
}
- constexpr Vector operator+(const Vector &other) const
+ constexpr Vector operator-(T scalar) const
{
- return apply(*this, other, std::plus<>{});
+ return apply(*this, scalar, std::minus<>{});
+ }
+
+ constexpr Vector operator*(const Vector &other) const
+ {
+ return apply(*this, other, std::multiplies<>{});
+ }
+
+ constexpr Vector operator*(T scalar) const
+ {
+ return apply(*this, scalar, std::multiplies<>{});
}
- constexpr Vector operator*(T factor) const
+ constexpr Vector operator/(const Vector &other) const
{
- return apply(*this, factor, std::multiplies<>{});
+ return apply(*this, other, std::divides<>{});
}
- constexpr Vector operator/(T factor) const
+ constexpr Vector operator/(T scalar) const
{
- return apply(*this, factor, std::divides<>{});
+ return apply(*this, scalar, std::divides<>{});
}
constexpr T dot(const Vector<T, Rows> &other) const