[RFC,v2,04/12] ipa: libipa: vector: Rename the dot product operator*() to dot()
diff mbox series

Message ID 20241118000738.18977-5-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • Improve linear algebra helpers in libipa
Related show

Commit Message

Laurent Pinchart Nov. 18, 2024, 12:07 a.m. UTC
The Vector class defines a set of arithmetic operators between two
vectors or a vector and a scalar. All the operators perform element-wise
operations, except for the operator*() that computes the dot product.
This is inconsistent and confusing. Replace the operator with a dot()
function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/ipa/libipa/vector.cpp | 14 +++++++-------
 src/ipa/libipa/vector.h   | 16 ++++++++--------
 2 files changed, 15 insertions(+), 15 deletions(-)

Comments

Milan Zamazal Nov. 18, 2024, 12:35 p.m. UTC | #1
Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:

> The Vector class defines a set of arithmetic operators between two
> vectors or a vector and a scalar. All the operators perform element-wise
> operations, except for the operator*() that computes the dot product.
> This is inconsistent and confusing. 

I would expect it to be a dot product.  But indeed, while Emacs Calc
computes a dot product, Maxima computes a vector, so it's better to
avoid confusions.

Reviewed-by: Milan Zamazal <mzamazal@redhat.com>

> Replace the operator with a dot() function.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/ipa/libipa/vector.cpp | 14 +++++++-------
>  src/ipa/libipa/vector.h   | 16 ++++++++--------
>  2 files changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
> index df089f8aed9f..b2794c200b05 100644
> --- a/src/ipa/libipa/vector.cpp
> +++ b/src/ipa/libipa/vector.cpp
> @@ -85,13 +85,6 @@ namespace ipa {
>   * \return The sum of the two vectors
>   */
>  
> -/**
> - * \fn Vector::operator*(const Vector<T, Rows> &other) const
> - * \brief Compute the dot product
> - * \param[in] other The other vector
> - * \return The dot product of the two vectors
> - */
> -
>  /**
>   * \fn Vector::operator*(T factor) const
>   * \brief Multiply the vector by a scalar
> @@ -106,6 +99,13 @@ namespace ipa {
>   * \return The vector divided by \a factor
>   */
>  
> +/**
> + * \fn Vector::dot(const Vector<T, Rows> &other) const
> + * \brief Compute the dot product
> + * \param[in] other The other vector
> + * \return The dot product of the two vectors
> + */
> +
>  /**
>   * \fn T &Vector::x()
>   * \brief Convenience function to access the first element of the vector
> diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
> index 50e16250acfd..9dabdc28a540 100644
> --- a/src/ipa/libipa/vector.h
> +++ b/src/ipa/libipa/vector.h
> @@ -90,14 +90,6 @@ public:
>  		return ret;
>  	}
>  
> -	constexpr T operator*(const Vector<T, Rows> &other) const
> -	{
> -		T ret = 0;
> -		for (unsigned int i = 0; i < Rows; i++)
> -			ret += data_[i] * other[i];
> -		return ret;
> -	}
> -
>  	constexpr Vector<T, Rows> operator*(T factor) const
>  	{
>  		Vector<T, Rows> ret;
> @@ -114,6 +106,14 @@ public:
>  		return ret;
>  	}
>  
> +	constexpr T dot(const Vector<T, Rows> &other) const
> +	{
> +		T ret = 0;
> +		for (unsigned int i = 0; i < Rows; i++)
> +			ret += data_[i] * other[i];
> +		return ret;
> +	}
> +
>  #ifndef __DOXYGEN__
>  	template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>
>  #endif /* __DOXYGEN__ */

Patch
diff mbox series

diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp
index df089f8aed9f..b2794c200b05 100644
--- a/src/ipa/libipa/vector.cpp
+++ b/src/ipa/libipa/vector.cpp
@@ -85,13 +85,6 @@  namespace ipa {
  * \return The sum of the two vectors
  */
 
-/**
- * \fn Vector::operator*(const Vector<T, Rows> &other) const
- * \brief Compute the dot product
- * \param[in] other The other vector
- * \return The dot product of the two vectors
- */
-
 /**
  * \fn Vector::operator*(T factor) const
  * \brief Multiply the vector by a scalar
@@ -106,6 +99,13 @@  namespace ipa {
  * \return The vector divided by \a factor
  */
 
+/**
+ * \fn Vector::dot(const Vector<T, Rows> &other) const
+ * \brief Compute the dot product
+ * \param[in] other The other vector
+ * \return The dot product of the two vectors
+ */
+
 /**
  * \fn T &Vector::x()
  * \brief Convenience function to access the first element of the vector
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index 50e16250acfd..9dabdc28a540 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -90,14 +90,6 @@  public:
 		return ret;
 	}
 
-	constexpr T operator*(const Vector<T, Rows> &other) const
-	{
-		T ret = 0;
-		for (unsigned int i = 0; i < Rows; i++)
-			ret += data_[i] * other[i];
-		return ret;
-	}
-
 	constexpr Vector<T, Rows> operator*(T factor) const
 	{
 		Vector<T, Rows> ret;
@@ -114,6 +106,14 @@  public:
 		return ret;
 	}
 
+	constexpr T dot(const Vector<T, Rows> &other) const
+	{
+		T ret = 0;
+		for (unsigned int i = 0; i < Rows; i++)
+			ret += data_[i] * other[i];
+		return ret;
+	}
+
 #ifndef __DOXYGEN__
 	template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>
 #endif /* __DOXYGEN__ */