[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] log10 support?
- From: Trevor Irons <trevorirons@xxxxxxxxx>
- Date: Mon, 7 Jun 2010 14:44:47 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=Fvj0ofeuk7xmdknaGXQu86VykyrjKdryWjpnsjfdzHQ=; b=fCfYnqyAflx9lNUlhEjIIgs8PvdIRRMJ2XJ/VfLNi/AcFeIkcCp/oa5qTcCVpsCFrg XjaDH0feLms6CJBxjEsVm+X56pBGbkytnjT/CayIyX45TXvGyDpqOH0ba5B/eOE5LdKg jW027m7adLzAtg+mHEtxw49oc5dWHmAxFDmOw=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Sroakaxj+40WAz/avlxaKynmDM4bCQ7w90Hq5sGHEeIsBrt52iXKPsJ4CEDbbpPRTn V/bs3emjCBwxyzx7s1/UaO3hpGT8vWUveS89oF6JAHQOZnA+0ZmXoJDFeWI1XKz0t7Lq ivi+ykZlNBu1XyzRWe4BtyQnQEydqZhmhOw4w=
This patch adds log10 support to arrays.
I'm still learning Eigen, I build it by grepping all the instances of Log, and log that I could find in the source code. It is possible that I missed something, but test cases compile and give correct answers. I don't know how to add to the unit tests.
Any problems with pushing this?
Thanks,
Trevor
# HG changeset patch
# User Trevor Irons <trevorirons@xxxxxxxxx>
# Date 1275943105 21600
# Node ID a7faca383da3219c9726595956cee3340898f856
# Parent 230c71b12785f3725ae83853660fcac83ddbed54
Added log10 support to arrays.
diff -r 230c71b12785 -r a7faca383da3 Eigen/Eigen2Support
--- a/Eigen/Eigen2Support Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/Eigen2Support Mon Jun 07 14:38:25 2010 -0600
@@ -72,6 +72,7 @@
using Eigen::ei_sqrt; \
using Eigen::ei_exp; \
using Eigen::ei_log; \
+using Eigen::ei_log10; \
using Eigen::ei_sin; \
using Eigen::ei_cos;
diff -r 230c71b12785 -r a7faca383da3 Eigen/src/Array/GlobalFunctions.h
--- a/Eigen/src/Array/GlobalFunctions.h Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/src/Array/GlobalFunctions.h Mon Jun 07 14:38:25 2010 -0600
@@ -58,6 +58,7 @@
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(cos,ei_scalar_cos_op)
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(exp,ei_scalar_exp_op)
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(log,ei_scalar_log_op)
+ EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(log10,ei_scalar_log10_op)
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(abs,ei_scalar_abs_op)
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(sqrt,ei_scalar_sqrt_op)
}
@@ -70,6 +71,7 @@
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_cos,ei_scalar_cos_op)
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_exp,ei_scalar_exp_op)
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_log,ei_scalar_log_op)
+ EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_log10,ei_scalar_log10_op)
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_abs,ei_scalar_abs_op)
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_abs2,ei_scalar_abs2_op)
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(ei_sqrt,ei_scalar_sqrt_op)
diff -r 230c71b12785 -r a7faca383da3 Eigen/src/Core/Functors.h
--- a/Eigen/src/Core/Functors.h Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/src/Core/Functors.h Mon Jun 07 14:38:25 2010 -0600
@@ -373,6 +373,22 @@
{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = ei_packet_traits<Scalar>::HasLog }; };
/** \internal
+ *
+ * \brief Template functor to compute the base 10 logarithm of a scalar
+ *
+ * \sa class CwiseUnaryOp, Cwise::log10()
+ */
+template<typename Scalar> struct ei_scalar_log10_op {
+ EIGEN_EMPTY_STRUCT_CTOR(ei_scalar_log10_op)
+ inline const Scalar operator() (const Scalar& a) const { return ei_log10(a); }
+ typedef typename ei_packet_traits<Scalar>::type Packet;
+ inline Packet packetOp(const Packet& a) const { return ei_plog10(a); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_log10_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = ei_packet_traits<Scalar>::HasLog10 }; };
+
+/** \internal
* \brief Template functor to multiply a scalar by a fixed other one
*
* \sa class CwiseUnaryOp, MatrixBase::operator*, MatrixBase::operator/
diff -r 230c71b12785 -r a7faca383da3 Eigen/src/Core/GenericPacketMath.h
--- a/Eigen/src/Core/GenericPacketMath.h Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/src/Core/GenericPacketMath.h Mon Jun 07 14:38:25 2010 -0600
@@ -65,6 +65,7 @@
HasSqrt = 0,
HasExp = 0,
HasLog = 0,
+ HasLog10 = 0,
HasPow = 0,
HasSin = 0,
@@ -221,6 +222,10 @@
/** \internal \returns the log of \a a (coeff-wise) */
template<typename Packet> inline static Packet ei_plog(Packet a) { return ei_log(a); }
+/** \internal \returns the log10 of \a a (coeff-wise) */
+template<typename Packet> inline static Packet ei_plog10(Packet a) { return
+ ei_log10(a); }
+
/** \internal \returns the square-root of \a a (coeff-wise) */
template<typename Packet> inline static Packet ei_psqrt(Packet a) { return ei_sqrt(a); }
diff -r 230c71b12785 -r a7faca383da3 Eigen/src/Core/MathFunctions.h
--- a/Eigen/src/Core/MathFunctions.h Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/src/Core/MathFunctions.h Mon Jun 07 14:38:25 2010 -0600
@@ -600,6 +600,44 @@
}
/****************************************************************************
+* Implementation of ei_log10 *
+****************************************************************************/
+
+template<typename Scalar, bool IsInteger>
+struct ei_log10_default_impl
+{
+ static inline Scalar run(const Scalar& x)
+ {
+ return std::log10(x);
+ }
+};
+
+template<typename Scalar>
+struct ei_log10_default_impl<Scalar, true>
+{
+ static inline Scalar run(const Scalar&)
+ {
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
+ return Scalar(0);
+ }
+};
+
+template<typename Scalar>
+struct ei_log10_impl : ei_log10_default_impl<Scalar, NumTraits<Scalar>::IsInteger> {};
+
+template<typename Scalar>
+struct ei_log10_retval
+{
+ typedef Scalar type;
+};
+
+template<typename Scalar>
+inline EIGEN_MATHFUNC_RETVAL(log10, Scalar) ei_log10(const Scalar& x)
+{
+ return EIGEN_MATHFUNC_IMPL(log10, Scalar)::run(x);
+}
+
+/****************************************************************************
* Implementation of ei_atan2 *
****************************************************************************/
diff -r 230c71b12785 -r a7faca383da3 Eigen/src/Core/util/ForwardDeclarations.h
--- a/Eigen/src/Core/util/ForwardDeclarations.h Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/src/Core/util/ForwardDeclarations.h Mon Jun 07 14:38:25 2010 -0600
@@ -116,6 +116,7 @@
template<typename Scalar> struct ei_scalar_sqrt_op;
template<typename Scalar> struct ei_scalar_exp_op;
template<typename Scalar> struct ei_scalar_log_op;
+template<typename Scalar> struct ei_scalar_log10_op;
template<typename Scalar> struct ei_scalar_cos_op;
template<typename Scalar> struct ei_scalar_sin_op;
template<typename Scalar> struct ei_scalar_pow_op;
diff -r 230c71b12785 -r a7faca383da3 Eigen/src/plugins/ArrayCwiseUnaryOps.h
--- a/Eigen/src/plugins/ArrayCwiseUnaryOps.h Mon Jun 07 14:47:20 2010 +0200
+++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h Mon Jun 07 14:38:25 2010 -0600
@@ -31,7 +31,7 @@
* Example: \include Cwise_exp.cpp
* Output: \verbinclude Cwise_exp.out
*
- * \sa pow(), log(), sin(), cos()
+ * \sa pow(), log(), log10(), sin(), cos()
*/
inline const CwiseUnaryOp<ei_scalar_exp_op<Scalar>, Derived>
exp() const
@@ -52,6 +52,16 @@
return derived();
}
+/** \returns an expression of the coefficient-wise base 10 logarithm of *this.
+ *
+ * \sa exp()
+ */
+inline const CwiseUnaryOp<ei_scalar_log10_op<Scalar>, Derived>
+log10() const
+{
+ return derived();
+}
+
/** \returns an expression of the coefficient-wise square root of *this.
*
* Example: \include Cwise_sqrt.cpp
diff -r 230c71b12785 -r a7faca383da3 doc/snippets/Cwise_log10.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/snippets/Cwise_log10.cpp Mon Jun 07 14:38:25 2010 -0600
@@ -0,0 +1,2 @@
+Array3d v(1,2,3);
+cout << v.log10() << endl;