Bugzilla – Attachment 247 Details for
Bug 405
Patch to add cwise bit operators to Array
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
[patch]
hg exported patch.
array_bit_ops.hg-export (text/plain), 6.25 KB, created by
John Roll
on 2012-01-13 14:17:15 UTC
(
hide
)
Description:
hg exported patch.
Filename:
MIME Type:
Creator:
John Roll
Created:
2012-01-13 14:17:15 UTC
Size:
6.25 KB
patch
obsolete
># HG changeset patch ># User John Roll <john@rkroll.com> ># Date 1326408102 18000 ># Node ID dbc7c2ef654a61aaf867e91c667e16a7ef16aeb3 ># Parent a71fd8e2744ca8e0750e261af19a245b847426e3 >Array bit operators. > >diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h >--- a/Eigen/src/Core/Functors.h >+++ b/Eigen/src/Core/Functors.h >@@ -964,11 +964,51 @@ struct functor_traits<std::binary_compos > #endif // EIGEN_STDEXT_SUPPORT > > // allow to add new functors and specializations of functor_traits from outside Eigen. > // this macro is really needed because functor_traits must be specialized after it is declared but before it is used... > #ifdef EIGEN_FUNCTORS_PLUGIN > #include EIGEN_FUNCTORS_PLUGIN > #endif > >+#define EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(OP,NAME) \ >+template<typename Scalar> \ >+struct NAME { \ >+ typedef typename packet_traits<Scalar>::type Packet; \ >+ inline NAME(const NAME& other) : m_other(other.m_other) { } \ >+ inline NAME(const Scalar& other) : m_other(other) { } \ >+ inline Scalar operator() (const Scalar& a) const { return a OP m_other; } \ >+ const Scalar m_other; \ >+}; \ >+template<typename Scalar> \ >+struct functor_traits<NAME<Scalar> > \ >+{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = false }; }; >+ >+EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(^ , scalar_bitxor_op) >+EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(& , scalar_bitand_op) >+EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(| , scalar_bitor_op) >+ >+#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT >+ EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(>>, scalar_bitshr_op) >+ EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(<<, scalar_bitshl_op) >+#endif >+ >+#define EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(OP, NAME) \ >+template<typename Scalar> \ >+struct NAME { \ >+ EIGEN_EMPTY_STRUCT_CTOR(NAME) \ >+ EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a, const Scalar& b) const { return a OP b; } \ >+}; \ >+template<typename Scalar> \ >+struct functor_traits<NAME<Scalar> > { enum { Cost = NumTraits<NAME<Scalar> >::AddCost, PacketAccess = false }; }; >+ >+EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(|, scalar_bitor_binary_op) >+EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(&, scalar_bitand_binary_op) >+EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(^, scalar_bitxor_binary_op) >+ >+#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT >+ EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(>>, scalar_bitshr_binary_op) >+ EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(<<, scalar_bitshl_binary_op) >+#endif >+ > } // end namespace internal > > #endif // EIGEN_FUNCTORS_H >diff --git a/Eigen/src/plugins/ArrayCwiseBinaryOps.h b/Eigen/src/plugins/ArrayCwiseBinaryOps.h >--- a/Eigen/src/plugins/ArrayCwiseBinaryOps.h >+++ b/Eigen/src/plugins/ArrayCwiseBinaryOps.h >@@ -172,8 +172,24 @@ operator&&(const EIGEN_CURRENT_STORAGE_B > template<typename OtherDerived> > inline const CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived> > operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const > { > EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), > THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); > return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived()); > } >+ >+#define EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(OP,FUNCTOR) \ >+template<typename OtherDerived> \ >+ inline const CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived> \ >+ operator OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ >+ { return CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived>(derived(),other.derived()); } >+ >+EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(| , internal::scalar_bitor_binary_op) >+EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(& , internal::scalar_bitand_binary_op) >+EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(^ , internal::scalar_bitxor_binary_op) >+ >+#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT >+ EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(>>, internal::scalar_bitshr_binary_op) >+ EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(<<, internal::scalar_bitshl_binary_op) >+#endif >+ >diff --git a/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/Eigen/src/plugins/ArrayCwiseUnaryOps.h >--- a/Eigen/src/plugins/ArrayCwiseUnaryOps.h >+++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h >@@ -195,8 +195,29 @@ cube() const > > EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator==, std::equal_to) > EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator!=, std::not_equal_to) > EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<, std::less) > EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<=, std::less_equal) > EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>, std::greater) > EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>=, std::greater_equal) > >+#define EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(OP,FUNCTOR) \ >+ inline const CwiseUnaryOp<FUNCTOR<Scalar>, const Derived> \ >+ operator OP(const Scalar& scalar) const { \ >+ return CwiseUnaryOp<FUNCTOR<Scalar>, const Derived>(derived(), FUNCTOR<Scalar>(scalar)); } >+ >+#define EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(OP,FUNCTOR) \ >+ EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(OP,FUNCTOR) \ >+ friend inline const CwiseUnaryOp<FUNCTOR<Scalar>, const Derived> \ >+ operator OP(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& other)\ >+ { return other OP scalar; } >+ >+ >+EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(^, internal::scalar_bitxor_op) >+EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(&, internal::scalar_bitand_op) >+EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(|, internal::scalar_bitor_op) >+ >+#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT >+ EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(>>, internal::scalar_bitshr_op) >+ EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(<<, internal::scalar_bitshl_op) >+#endif >+ >diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt >--- a/test/CMakeLists.txt >+++ b/test/CMakeLists.txt >@@ -95,16 +95,17 @@ ei_add_test(adjoint) > ei_add_test(diagonal) > ei_add_test(miscmatrices) > ei_add_test(commainitializer) > ei_add_test(smallvectors) > ei_add_test(map) > ei_add_test(mapstride) > ei_add_test(mapstaticmethods) > ei_add_test(array) >+ei_add_test(array_bit_ops) > ei_add_test(array_for_matrix) > ei_add_test(array_replicate) > ei_add_test(array_reverse) > ei_add_test(triangular) > ei_add_test(selfadjoint) > ei_add_test(product_selfadjoint) > ei_add_test(product_symm) > ei_add_test(product_syrk)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 405
: 247 |
248