[eigen] [PATCH] ParialRedux count() |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] [PATCH] ParialRedux count()
- From: Ricard Marxer Piñón <email@xxxxxxxxxxxxxxxx>
- Date: Sat, 24 Jan 2009 13:27:22 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=Rw2SaAFqfX+rZc4H9bY1m1pwwbcbEApt0/gEM7iPlKU=; b=jAyoH88al9OQWicvQ6vXbBl5oo+Z+MSSJSnq1X5u+EdVYa1S/Z2S4g6KgSaYhNmqcs Csd/8YjT1aADO7qemthDdIEhqZe0CA9bucQJXBV9RJDytombuZ73af5quD9ZvjkX0aj8 bhS8mJ7i9WlX4aUYwkFLabTINcJim0HqvCUz0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=nZI4xgZjk7l2x5kjZUJJ/JsVrO4fXL2skmYMMeDN7uoQ9smbYfIz0M6+HhUxjB8+9q 1kc5+5OUJ8NGfUKNCPG/uQd39ejobYA8yvcurs6b+JUXwGCTbaoVEEYQnTT39MTrD7ih vnZjpriOxETsRYx0F32cFKIH9/34j0yayISKs=
Hi,
I have added count() to PartialRedux. Attached is the patch which also includes a snippet for the doc.
When
telling the cost of the operator I have simplified a bit and implied
that the casts to bool and int (which are in the count() method in
BooleanRedux.h) are always necessary, I think this needs reviews.
PS: if you think of other easy tasks i could tackle, I would be
happy to do it, that way I will get more familiarized with Eigen
internals.
--
ricard
http://www.ricardmarxer.com
http://www.caligraft.com
Index: doc/snippets/PartialRedux_count.cpp
===================================================================
--- doc/snippets/PartialRedux_count.cpp (revision 0)
+++ doc/snippets/PartialRedux_count.cpp (revision 0)
@@ -0,0 +1,3 @@
+Matrix3d m = Matrix3d::Random();
+cout << "Here is the matrix m:" << endl << m << endl;
+cout << "Here is the count of elements larger or equal than 0.5 of each row:" << endl << (m.cwise() >= 0.5).rowwise().count() << endl;
Index: Eigen/src/Array/PartialRedux.h
===================================================================
--- Eigen/src/Array/PartialRedux.h (revision 915940)
+++ Eigen/src/Array/PartialRedux.h (working copy)
@@ -107,6 +107,17 @@
{ return mat.MEMBER(); } \
}
+#define EIGEN_MEMBER_FUNCTOR_RETURNTYPE(MEMBER,COST,RETURNTYPE) \
+ template <typename ResultType> \
+ struct ei_member_##MEMBER EIGEN_EMPTY_STRUCT { \
+ typedef RETURNTYPE result_type; \
+ template<typename Scalar, int Size> struct Cost \
+ { enum { value = COST }; }; \
+ template<typename Derived> \
+ inline result_type operator()(const MatrixBase<Derived>& mat) const \
+ { return mat.MEMBER(); } \
+ }
+
EIGEN_MEMBER_FUNCTOR(squaredNorm, Size * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost);
EIGEN_MEMBER_FUNCTOR(norm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost);
EIGEN_MEMBER_FUNCTOR(sum, (Size-1)*NumTraits<Scalar>::AddCost);
@@ -114,6 +125,7 @@
EIGEN_MEMBER_FUNCTOR(maxCoeff, (Size-1)*NumTraits<Scalar>::AddCost);
EIGEN_MEMBER_FUNCTOR(all, (Size-1)*NumTraits<Scalar>::AddCost);
EIGEN_MEMBER_FUNCTOR(any, (Size-1)*NumTraits<Scalar>::AddCost);
+EIGEN_MEMBER_FUNCTOR_RETURNTYPE(count, (Size-1)*NumTraits<int>::AddCost*NumTraits<bool>::AddCost*NumTraits<int>::AddCost, int);
/** \internal */
template <typename BinaryOp, typename Scalar>
@@ -233,6 +245,16 @@
const typename ReturnType<ei_member_sum>::Type sum() const
{ return _expression(); }
+ /** \returns a row (or column) vector expression of the count
+ * of each column (or row) of the referenced expression.
+ *
+ * Example: \include PartialRedux_count.cpp
+ * Output: \verbinclude PartialRedux_count.out
+ *
+ * \sa MatrixBase::count() */
+ const typename ReturnType<ei_member_count>::Type count() const
+ { return _expression(); }
+
/** \returns a row (or column) vector expression representing
* whether \b all coefficients of each respective column (or row) are \c true.
*