[RFC PATCH v2 06/12] ipa: libipa: vector: Add missing binary arithemtic operators
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Nov 18 01:07:32 CET 2024
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 at ideasonboard.com>
---
src/ipa/libipa/vector.cpp | 54 +++++++++++++++++++++++++++++----------
src/ipa/libipa/vector.h | 38 ++++++++++++++++++++-------
2 files changed, 70 insertions(+), 22 deletions(-)
diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
index b2794c200b05..d0e38f402220 100644
--- a/src/ipa/libipa/vector.cpp
+++ b/src/ipa/libipa/vector.cpp
@@ -71,32 +71,60 @@ namespace ipa {
* \return The negated vector
*/
+/**
+ * \fn Vector::operator+(Vector const &other) const
+ * \brief Calculate the sum of this vector and \a other element-wise
+ * \param[in] other The other vector
+ * \return The element-wise sum of this vector and \a other
+ */
+
+/**
+ * \fn Vector::operator+(T scalar) const
+ * \brief Calculate the sum of this vector and \a scalar element-wise
+ * \param[in] scalar The scalar
+ * \return The element-wise sum of this vector and \a other
+ */
+
/**
* \fn Vector::operator-(Vector const &other) const
- * \brief Subtract one vector from another
+ * \brief Calculate the difference of this vector and \a other element-wise
* \param[in] other The other vector
- * \return The difference of \a other from this vector
+ * \return The element-wise subtraction of \a other from this vector
*/
/**
- * \fn Vector::operator+()
- * \brief Add two vectors together
+ * \fn Vector::operator-(T scalar) const
+ * \brief Calculate the difference of this vector and \a scalar element-wise
+ * \param[in] scalar The scalar
+ * \return The element-wise subtraction of \a scalar from this vector
+ */
+
+/**
+ * \fn Vector::operator*(const Vector &other) const
+ * \brief Calculate the product of this vector and \a other element-wise
* \param[in] other The other vector
- * \return The sum of the two vectors
+ * \return The element-wise product of this vector and \a other
*/
/**
- * \fn Vector::operator*(T factor) const
- * \brief Multiply the vector by a scalar
- * \param[in] factor The factor
- * \return The vector multiplied by \a factor
+ * \fn Vector::operator*(T scalar) const
+ * \brief Calculate the product of this vector and \a scalar element-wise
+ * \param[in] scalar The scalar
+ * \return The element-wise product of this vector and \a scalar
*/
/**
- * \fn Vector::operator/()
- * \brief Divide the vector by a scalar
- * \param[in] factor The factor
- * \return The vector divided by \a factor
+ * \fn Vector::operator/(const Vector &other) const
+ * \brief Calculate the quotient of this vector and \a other element-wise
+ * \param[in] other The other vector
+ * \return The element-wise division of this vector by \a other
+ */
+
+/**
+ * \fn Vector::operator/(T scalar) const
+ * \brief Calculate the quotient of this vector and \a scalar element-wise
+ * \param[in] scalar The scalar
+ * \return The element-wise division of this vector by \a scalar
*/
/**
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index 8c4edfbaf85f..dda49b1f468b 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -74,24 +74,44 @@ public:
return ret;
}
- constexpr Vector operator-(const Vector &other) const
- {
- return apply(*this, other, [](T a, T b) { return a - b; });
- }
-
constexpr Vector operator+(const Vector &other) const
{
return apply(*this, other, [](T a, T b) { return a + b; });
}
- constexpr Vector operator*(T factor) const
+ constexpr Vector operator+(T scalar) const
{
- return apply(*this, factor, [](T a, T b) { return a * b; });
+ return apply(*this, scalar, [](T a, T b) { return a + b; });
}
- constexpr Vector operator/(T factor) const
+ constexpr Vector operator-(const Vector &other) const
{
- return apply(*this, factor, [](T a, T b) { return a / b; });
+ return apply(*this, other, [](T a, T b) { return a - b; });
+ }
+
+ constexpr Vector operator-(T scalar) const
+ {
+ return apply(*this, scalar, [](T a, T b) { return a - b; });
+ }
+
+ constexpr Vector operator*(const Vector &other) const
+ {
+ return apply(*this, other, [](T a, T b) { return a * b; });
+ }
+
+ constexpr Vector operator*(T scalar) const
+ {
+ return apply(*this, scalar, [](T a, T b) { return a * b; });
+ }
+
+ constexpr Vector operator/(const Vector &other) const
+ {
+ return apply(*this, other, [](T a, T b) { return a / b; });
+ }
+
+ constexpr Vector operator/(T scalar) const
+ {
+ return apply(*this, scalar, [](T a, T b) { return a / b; });
}
constexpr T dot(const Vector<T, Rows> &other) const
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list