This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 405 | Differences between
and this patch

Collapse All | Expand All

(-)a/Eigen/src/Core/Functors.h (+40 lines)
Lines 964-974 struct functor_traits<std::binary_compos Link Here
964
#endif // EIGEN_STDEXT_SUPPORT
964
#endif // EIGEN_STDEXT_SUPPORT
965
965
966
// allow to add new functors and specializations of functor_traits from outside Eigen.
966
// allow to add new functors and specializations of functor_traits from outside Eigen.
967
// this macro is really needed because functor_traits must be specialized after it is declared but before it is used...
967
// this macro is really needed because functor_traits must be specialized after it is declared but before it is used...
968
#ifdef EIGEN_FUNCTORS_PLUGIN
968
#ifdef EIGEN_FUNCTORS_PLUGIN
969
#include EIGEN_FUNCTORS_PLUGIN
969
#include EIGEN_FUNCTORS_PLUGIN
970
#endif
970
#endif
971
971
972
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(OP,NAME) 				\
973
template<typename Scalar>							\
974
struct NAME {									\
975
  typedef typename packet_traits<Scalar>::type Packet;				\
976
  inline NAME(const NAME& other) : m_other(other.m_other) { }			\
977
  inline NAME(const Scalar& other) : m_other(other) { }				\
978
  inline Scalar operator() (const Scalar& a) const { return a OP m_other; }	\
979
  const Scalar m_other;								\
980
};										\
981
template<typename Scalar>							\
982
struct functor_traits<NAME<Scalar> >						\
983
{ enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = false }; };
984
985
EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(^ , scalar_bitxor_op)
986
EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(& , scalar_bitand_op)
987
EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(| , scalar_bitor_op)
988
989
#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT
990
  EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(>>, scalar_bitshr_op)
991
  EIGEN_MAKE_SCALAR_CWISE_UNARY_FUNCTOR(<<, scalar_bitshl_op)
992
#endif
993
994
#define EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(OP, NAME) 				\
995
template<typename Scalar>								\
996
struct NAME {										\
997
  EIGEN_EMPTY_STRUCT_CTOR(NAME)								\
998
  EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a, const Scalar& b) const { return a OP b; }	\
999
};											\
1000
template<typename Scalar>								\
1001
struct functor_traits<NAME<Scalar> > { enum { Cost = NumTraits<NAME<Scalar> >::AddCost, PacketAccess = false }; };
1002
1003
EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(|, scalar_bitor_binary_op)
1004
EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(&, scalar_bitand_binary_op)
1005
EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(^, scalar_bitxor_binary_op)
1006
1007
#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT
1008
  EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(>>, scalar_bitshr_binary_op)
1009
  EIGEN_MAKE_SCALAR_CWISE_BINARY_FUNCTOR(<<, scalar_bitshl_binary_op)
1010
#endif
1011
972
} // end namespace internal
1012
} // end namespace internal
973
1013
974
#endif // EIGEN_FUNCTORS_H
1014
#endif // EIGEN_FUNCTORS_H
(-)a/Eigen/src/plugins/ArrayCwiseBinaryOps.h (+16 lines)
Lines 172-179 operator&&(const EIGEN_CURRENT_STORAGE_B Link Here
172
template<typename OtherDerived>
172
template<typename OtherDerived>
173
inline const CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>
173
inline const CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>
174
operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
174
operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
175
{
175
{
176
  EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value),
176
  EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value),
177
                      THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
177
                      THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
178
  return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived());
178
  return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived());
179
}
179
}
180
181
#define EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(OP,FUNCTOR) 				\
182
template<typename OtherDerived>								\
183
  inline const CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived>	\
184
  operator OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const	\
185
  { return CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived>(derived(),other.derived()); }
186
187
EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(| ,  internal::scalar_bitor_binary_op)
188
EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(& ,  internal::scalar_bitand_binary_op)
189
EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(^ ,  internal::scalar_bitxor_binary_op)
190
191
#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT
192
  EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(>>,  internal::scalar_bitshr_binary_op)
193
  EIGEN_MAKE_SCALAR_CWISE_BINARY_BITOP(<<,  internal::scalar_bitshl_binary_op)
194
#endif
195
(-)a/Eigen/src/plugins/ArrayCwiseUnaryOps.h (+21 lines)
Lines 195-202 cube() const Link Here
195
195
196
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator==,  std::equal_to)
196
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator==,  std::equal_to)
197
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator!=,  std::not_equal_to)
197
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator!=,  std::not_equal_to)
198
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<,   std::less)
198
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<,   std::less)
199
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<=,  std::less_equal)
199
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<=,  std::less_equal)
200
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>,   std::greater)
200
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>,   std::greater)
201
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>=,  std::greater_equal)
201
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>=,  std::greater_equal)
202
202
203
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(OP,FUNCTOR) 	\
204
  inline const CwiseUnaryOp<FUNCTOR<Scalar>, const Derived>	\
205
    operator OP(const Scalar& scalar) const {			\
206
      return CwiseUnaryOp<FUNCTOR<Scalar>, const Derived>(derived(), FUNCTOR<Scalar>(scalar)); }
207
208
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(OP,FUNCTOR)	\
209
  EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(OP,FUNCTOR) 			\
210
  friend inline const CwiseUnaryOp<FUNCTOR<Scalar>, const Derived>	\
211
  operator OP(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& other)\
212
  { return other OP scalar; }
213
214
215
EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(^, internal::scalar_bitxor_op)
216
EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(&, internal::scalar_bitand_op)
217
EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP_COMMUTATIVE(|, internal::scalar_bitor_op)
218
219
#ifdef EIGEN_INCLUDE_ARRAY_BIT_SHIFT
220
  EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(>>,  internal::scalar_bitshr_op)
221
  EIGEN_MAKE_SCALAR_CWISE_UNARY_BITOP(<<,  internal::scalar_bitshl_op)
222
#endif
223
(-)a/test/CMakeLists.txt (+1 lines)
Lines 95-110 ei_add_test(adjoint) Link Here
95
ei_add_test(diagonal)
95
ei_add_test(diagonal)
96
ei_add_test(miscmatrices)
96
ei_add_test(miscmatrices)
97
ei_add_test(commainitializer)
97
ei_add_test(commainitializer)
98
ei_add_test(smallvectors)
98
ei_add_test(smallvectors)
99
ei_add_test(map)
99
ei_add_test(map)
100
ei_add_test(mapstride)
100
ei_add_test(mapstride)
101
ei_add_test(mapstaticmethods)
101
ei_add_test(mapstaticmethods)
102
ei_add_test(array)
102
ei_add_test(array)
103
ei_add_test(array_bit_ops)
103
ei_add_test(array_for_matrix)
104
ei_add_test(array_for_matrix)
104
ei_add_test(array_replicate)
105
ei_add_test(array_replicate)
105
ei_add_test(array_reverse)
106
ei_add_test(array_reverse)
106
ei_add_test(triangular)
107
ei_add_test(triangular)
107
ei_add_test(selfadjoint)
108
ei_add_test(selfadjoint)
108
ei_add_test(product_selfadjoint)
109
ei_add_test(product_selfadjoint)
109
ei_add_test(product_symm)
110
ei_add_test(product_symm)
110
ei_add_test(product_syrk)
111
ei_add_test(product_syrk)
(-)a/test/array_bit_ops.cpp (+87 lines)
Line 0 Link Here
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2011 John Roll <john@rkroll.com>
5
//
6
// Eigen is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 3 of the License, or (at your option) any later version.
10
//
11
// Alternatively, you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License as
13
// published by the Free Software Foundation; either version 2 of
14
// the License, or (at your option) any later version.
15
//
16
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
// GNU General Public License for more details.
20
//
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
24
25
#define EIGEN2_SUPPORT
26
#define EIGEN_NO_STATIC_ASSERT
27
#define EIGEN_INCLUDE_ARRAY_BIT_SHIFT
28
#include "main.h"
29
#include <functional>
30
31
#include <iostream>
32
using namespace std;
33
34
#ifdef min
35
#undef min
36
#endif
37
38
#ifdef max
39
#undef max
40
#endif
41
42
template<typename ArrayType> void array_bit_ops(ArrayType a)
43
{
44
  typename ArrayType::Scalar pow = 1;
45
  typename ArrayType::Scalar one = 1;
46
47
  a.setConstant(1);
48
49
  for ( unsigned int i = 0; i < sizeof(typename ArrayType::Scalar)*8; i++ ) {
50
51
      /* The Lhs is generated with bit shifting native types and multiplication.
52
	 The Rhs is generated with the array bit operations.
53
       */
54
      VERIFY(((a*((one<<i) & 1)) == ((a*(one<<i)) &            1 )).all());
55
      VERIFY(((a*((one<<i) & 1)) == (           1 & (a*(one<<i)) )).all());
56
      VERIFY(((a*((one<<i) & 1)) == ((a*(one<<i)) &        (a*1) )).all());
57
58
      VERIFY(((a*((one<<i) | 1)) == ((a*(one<<i)) |            1 )).all());
59
      VERIFY(((a*((one<<i) | 1)) == (           1 | (a*(one<<i)) )).all());
60
      VERIFY(((a*((one<<i) | 1)) == ((a*(one<<i)) |        (a*1) )).all());
61
62
      VERIFY(((a*((one<<i) ^ 1)) == ((a*(one<<i)) ^    1         )).all());
63
      VERIFY(((a*((one<<i) ^ 1)) == (           1 ^ (a*(one<<i)) )).all());
64
      VERIFY(((a*((one<<i) ^ 1)) == ((a*(one<<i)) ^        (a*1) )).all());
65
66
      VERIFY((a*pow ==  a <<    i ).all());
67
      VERIFY((a*pow ==  a << (a*i)).all());
68
69
      if ( i != sizeof(typename ArrayType::Scalar)*8-1 ) {	// Don't shift out of sign bit
70
	  VERIFY((((a*pow) >>    i ) == a).all());
71
	  VERIFY((((a*pow) >> (a*i)) == a).all());
72
      }
73
74
      pow *= 2;
75
  }
76
}
77
78
void test_array_bit_ops()
79
{
80
  for(int i = 0; i < g_repeat ; i++) {
81
    CALL_SUBTEST_1( array_bit_ops(Array<int, EIGEN_TEST_MAX_SIZE, EIGEN_TEST_MAX_SIZE>()) );
82
    CALL_SUBTEST_2( array_bit_ops(Array<short, EIGEN_TEST_MAX_SIZE, EIGEN_TEST_MAX_SIZE>()) );
83
    CALL_SUBTEST_3( array_bit_ops(Array<unsigned short, EIGEN_TEST_MAX_SIZE, EIGEN_TEST_MAX_SIZE>()) );
84
    CALL_SUBTEST_4( array_bit_ops(Array<long, EIGEN_TEST_MAX_SIZE, EIGEN_TEST_MAX_SIZE>()) );
85
    CALL_SUBTEST_5( array_bit_ops(Array<long long, EIGEN_TEST_MAX_SIZE, EIGEN_TEST_MAX_SIZE>()) );
86
  }
87
}

Return to bug 405