aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-07-07 10:00:08 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-07-07 10:00:08 +0200
commite38fc9692dfac3596331c6f7b9e50a0fb7dbcfe9 (patch)
tree24cd97101328cd1e9d4e66b802b14b57d938ccb4 /Eigen/src
parentf8d3b4c0606683bb19ae2cf037e6fd637002954a (diff)
add a conj_product functor and optimize dot products
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/Core/Dot.h4
-rw-r--r--Eigen/src/Core/Functors.h22
-rw-r--r--Eigen/src/Core/util/ForwardDeclarations.h1
3 files changed, 25 insertions, 2 deletions
diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h
index 8eaa62185..9fc2fb60e 100644
--- a/Eigen/src/Core/Dot.h
+++ b/Eigen/src/Core/Dot.h
@@ -41,7 +41,7 @@ struct ei_dot_nocheck
{
static inline typename ei_traits<T>::Scalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
{
- return a.conjugate().cwiseProduct(b).sum();
+ return a.template binaryExpr<ei_scalar_conj_product_op<typename ei_traits<T>::Scalar> >(b).sum();
}
};
@@ -50,7 +50,7 @@ struct ei_dot_nocheck<T, U, true>
{
static inline typename ei_traits<T>::Scalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
{
- return a.adjoint().cwiseProduct(b).sum();
+ return a.transpose().template binaryExpr<ei_scalar_conj_product_op<typename ei_traits<T>::Scalar> >(b).sum();
}
};
diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h
index 103833447..ac5aa67c4 100644
--- a/Eigen/src/Core/Functors.h
+++ b/Eigen/src/Core/Functors.h
@@ -74,6 +74,28 @@ struct ei_functor_traits<ei_scalar_product_op<Scalar> > {
};
/** \internal
+ * \brief Template functor to compute the conjugate product of two scalars
+ *
+ * This is a short cut for ei_conj(x) * y which is needed for optimization purpose
+ */
+template<typename Scalar> struct ei_scalar_conj_product_op {
+ enum { Conj = NumTraits<Scalar>::IsComplex };
+ EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_conj_product_op)
+ EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const
+ { return ei_conj_helper<Scalar,Scalar,Conj,false>().pmul(a,b); }
+ template<typename PacketScalar>
+ EIGEN_STRONG_INLINE const PacketScalar packetOp(const PacketScalar& a, const PacketScalar& b) const
+ { return ei_conj_helper<PacketScalar,PacketScalar,Conj,false>().pmul(a,b); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_conj_product_op<Scalar> > {
+ enum {
+ Cost = NumTraits<Scalar>::MulCost,
+ PacketAccess = ei_packet_traits<Scalar>::HasMul
+ };
+};
+
+/** \internal
* \brief Template functor to compute the min of two scalars
*
* \sa class CwiseBinaryOp, MatrixBase::cwiseMin, class VectorwiseOp, MatrixBase::minCoeff()
diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h
index a757bef76..310ffa4b3 100644
--- a/Eigen/src/Core/util/ForwardDeclarations.h
+++ b/Eigen/src/Core/util/ForwardDeclarations.h
@@ -113,6 +113,7 @@ template<typename LhsScalar, typename RhsScalar, bool ConjLhs, bool ConjRhs> str
template<typename Scalar> struct ei_scalar_sum_op;
template<typename Scalar> struct ei_scalar_difference_op;
template<typename Scalar> struct ei_scalar_product_op;
+template<typename Scalar> struct ei_scalar_conj_product_op;
template<typename Scalar> struct ei_scalar_quotient_op;
template<typename Scalar> struct ei_scalar_opposite_op;
template<typename Scalar> struct ei_scalar_conjugate_op;