TR-mbed 1.0
Loading...
Searching...
No Matches
BinaryFunctors.h
Go to the documentation of this file.
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_BINARY_FUNCTORS_H
11#define EIGEN_BINARY_FUNCTORS_H
12
13namespace Eigen {
14
15namespace internal {
16
17//---------- associative binary functors ----------
18
19template<typename Arg1, typename Arg2>
21{
22 typedef Arg1 first_argument_type;
24};
25
31template<typename LhsScalar,typename RhsScalar>
32struct scalar_sum_op : binary_op_base<LhsScalar,RhsScalar>
33{
35#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
37#else
40 }
41#endif
42 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a + b; }
43 template<typename Packet>
46 template<typename Packet>
49};
50template<typename LhsScalar,typename RhsScalar>
58
59
60template<>
61EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool scalar_sum_op<bool,bool>::operator() (const bool& a, const bool& b) const { return a || b; }
62
63
69template<typename LhsScalar,typename RhsScalar>
70struct scalar_product_op : binary_op_base<LhsScalar,RhsScalar>
71{
73#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
75#else
78 }
79#endif
80 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; }
81 template<typename Packet>
84 template<typename Packet>
87};
88template<typename LhsScalar,typename RhsScalar>
96
97template<>
98EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool scalar_product_op<bool,bool>::operator() (const bool& a, const bool& b) const { return a && b; }
99
100
106template<typename LhsScalar,typename RhsScalar>
124template<typename LhsScalar,typename RhsScalar>
131
137template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
156
157template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
164
170template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
189
190template<typename LhsScalar,typename RhsScalar, int NaNPropagation>
197
202template<typename LhsScalar, typename RhsScalar, ComparisonName cmp> struct scalar_cmp_op;
203
204template<typename LhsScalar, typename RhsScalar, ComparisonName cmp>
205struct functor_traits<scalar_cmp_op<LhsScalar,RhsScalar, cmp> > {
206 enum {
208 PacketAccess = false
209 };
210};
211
212template<ComparisonName Cmp, typename LhsScalar, typename RhsScalar>
213struct result_of<scalar_cmp_op<LhsScalar, RhsScalar, Cmp>(LhsScalar,RhsScalar)> {
214 typedef bool type;
215};
216
217
218template<typename LhsScalar, typename RhsScalar>
219struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_EQ> : binary_op_base<LhsScalar,RhsScalar>
220{
221 typedef bool result_type;
223 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a==b;}
224};
225template<typename LhsScalar, typename RhsScalar>
226struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_LT> : binary_op_base<LhsScalar,RhsScalar>
227{
228 typedef bool result_type;
230 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a<b;}
231};
232template<typename LhsScalar, typename RhsScalar>
233struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_LE> : binary_op_base<LhsScalar,RhsScalar>
234{
235 typedef bool result_type;
237 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a<=b;}
238};
239template<typename LhsScalar, typename RhsScalar>
240struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_GT> : binary_op_base<LhsScalar,RhsScalar>
241{
242 typedef bool result_type;
244 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a>b;}
245};
246template<typename LhsScalar, typename RhsScalar>
247struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_GE> : binary_op_base<LhsScalar,RhsScalar>
248{
249 typedef bool result_type;
251 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a>=b;}
252};
253template<typename LhsScalar, typename RhsScalar>
254struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_UNORD> : binary_op_base<LhsScalar,RhsScalar>
255{
256 typedef bool result_type;
258 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return !(a<=b || b<=a);}
259};
260template<typename LhsScalar, typename RhsScalar>
261struct scalar_cmp_op<LhsScalar,RhsScalar, cmp_NEQ> : binary_op_base<LhsScalar,RhsScalar>
262{
263 typedef bool result_type;
265 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator()(const LhsScalar& a, const RhsScalar& b) const {return a!=b;}
266};
267
273template<typename Scalar>
275{
277
279 {
280 // This functor is used by hypotNorm only for which it is faster to first apply abs
281 // on all coefficients prior to reduction through hypot.
282 // This way we avoid calling abs on positive and real entries, and this also permits
283 // to seamlessly handle complexes. Otherwise we would have to handle both real and complexes
284 // through the same functor...
286 }
287};
288template<typename Scalar>
298
303template<typename Scalar, typename Exponent>
304struct scalar_pow_op : binary_op_base<Scalar,Exponent>
305{
307#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
309#else
310 scalar_pow_op() {
311 typedef Scalar LhsScalar;
312 typedef Exponent RhsScalar;
314 }
315#endif
316
318 inline result_type operator() (const Scalar& a, const Exponent& b) const { return numext::pow(a, b); }
319
320 template<typename Packet>
322 {
323 return generic_pow(a,b);
324 }
325};
326
327template<typename Scalar, typename Exponent>
340
341//---------- non associative binary functors ----------
342
348template<typename LhsScalar,typename RhsScalar>
349struct scalar_difference_op : binary_op_base<LhsScalar,RhsScalar>
350{
352#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
354#else
357 }
358#endif
359 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a - b; }
360 template<typename Packet>
362 { return internal::psub(a,b); }
363};
364template<typename LhsScalar,typename RhsScalar>
371
377template<typename LhsScalar,typename RhsScalar>
378struct scalar_quotient_op : binary_op_base<LhsScalar,RhsScalar>
379{
381#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
383#else
386 }
387#endif
388 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a / b; }
389 template<typename Packet>
391 { return internal::pdiv(a,b); }
392};
393template<typename LhsScalar,typename RhsScalar>
401
402
403
411 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a && b; }
412 template<typename Packet>
414 { return internal::pand(a,b); }
415};
417 enum {
419 PacketAccess = true
420 };
421};
422
430 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a || b; }
431 template<typename Packet>
433 { return internal::por(a,b); }
434};
436 enum {
438 PacketAccess = true
439 };
440};
441
449 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a ^ b; }
450 template<typename Packet>
452 { return internal::pxor(a,b); }
453};
455 enum {
457 PacketAccess = true
458 };
459};
460
466template<typename LhsScalar,typename RhsScalar>
468{
470#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
472#else
475 }
476#endif
477 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const
478 { return numext::absdiff(a,b); }
479 template<typename Packet>
482};
483template<typename LhsScalar,typename RhsScalar>
490
491
492
493//---------- binary functors bound to a constant, thus appearing as a unary functor ----------
494
495// The following two classes permits to turn any binary functor into a unary one with one argument bound to a constant value.
496// They are analogues to std::binder1st/binder2nd but with the following differences:
497// - they are compatible with packetOp
498// - they are portable across C++ versions (the std::binder* are deprecated in C++11)
499template<typename BinaryOp> struct bind1st_op : BinaryOp {
500
501 typedef typename BinaryOp::first_argument_type first_argument_type;
502 typedef typename BinaryOp::second_argument_type second_argument_type;
503 typedef typename BinaryOp::result_type result_type;
504
506
507 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const second_argument_type& b) const { return BinaryOp::operator()(m_value,b); }
508
509 template<typename Packet>
511 { return BinaryOp::packetOp(internal::pset1<Packet>(m_value), b); }
512
514};
515template<typename BinaryOp> struct functor_traits<bind1st_op<BinaryOp> > : functor_traits<BinaryOp> {};
516
517
518template<typename BinaryOp> struct bind2nd_op : BinaryOp {
519
520 typedef typename BinaryOp::first_argument_type first_argument_type;
521 typedef typename BinaryOp::second_argument_type second_argument_type;
522 typedef typename BinaryOp::result_type result_type;
523
525
526 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const first_argument_type& a) const { return BinaryOp::operator()(a,m_value); }
527
528 template<typename Packet>
530 { return BinaryOp::packetOp(a,internal::pset1<Packet>(m_value)); }
531
533};
534template<typename BinaryOp> struct functor_traits<bind2nd_op<BinaryOp> > : functor_traits<BinaryOp> {};
535
536
537} // end namespace internal
538
539} // end namespace Eigen
540
541#endif // EIGEN_BINARY_FUNCTORS_H
ArrayXXi a
Definition Array_initializer_list_23_cxx11.cpp:1
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition XprHelper.h:22
Scalar * b
Definition benchVecAdd.cpp:17
SCALAR Scalar
Definition bench_gemm.cpp:46
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition gnuplot_common_settings.hh:12
return int(ret)+1
#define EIGEN_SCALAR_BINARY_OP_PLUGIN
Definition linearstructure.cpp:12
EIGEN_DEVICE_FUNC Packet padd(const Packet &a, const Packet &b)
Definition GenericPacketMath.h:215
@ cmp_NEQ
Definition Constants.h:555
@ cmp_EQ
Definition Constants.h:551
@ cmp_GT
Definition Constants.h:556
@ cmp_LT
Definition Constants.h:552
@ cmp_GE
Definition Constants.h:557
@ cmp_LE
Definition Constants.h:553
@ cmp_UNORD
Definition Constants.h:554
EIGEN_DEVICE_FUNC unpacket_traits< Packet >::type predux(const Packet &a)
Definition GenericPacketMath.h:875
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet generic_pow(const Packet &x, const Packet &y)
Definition GenericPacketMathFunctions.h:1449
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RealScalar positive_real_hypot(const RealScalar &x, const RealScalar &y)
Definition MathFunctionsImpl.h:80
const Scalar & y
Definition MathFunctions.h:821
EIGEN_DEVICE_FUNC Packet pdiv(const Packet &a, const Packet &b)
Definition GenericPacketMath.h:244
EIGEN_STRONG_INLINE Packet8h por(const Packet8h &a, const Packet8h &b)
Definition PacketMath.h:1042
EIGEN_DEVICE_FUNC unpacket_traits< Packet >::type predux_mul(const Packet &a)
Definition GenericPacketMath.h:882
EIGEN_DEVICE_FUNC Packet pmul(const Packet &a, const Packet &b)
Definition GenericPacketMath.h:237
EIGEN_DEVICE_FUNC Packet pabsdiff(const Packet &a, const Packet &b)
Definition GenericPacketMath.h:595
EIGEN_STRONG_INLINE Packet8h pand(const Packet8h &a, const Packet8h &b)
Definition PacketMath.h:1050
EIGEN_STRONG_INLINE Packet8h pxor(const Packet8h &a, const Packet8h &b)
Definition PacketMath.h:1047
EIGEN_DEVICE_FUNC Packet psub(const Packet &a, const Packet &b)
Definition GenericPacketMath.h:222
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T absdiff(const T &x, const T &y)
Definition MathFunctions.h:1296
EIGEN_DEVICE_FUNC internal::pow_impl< ScalarX, ScalarY >::result_type pow(const ScalarX &x, const ScalarY &y)
Definition MathFunctions.h:1361
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Definition BandTriangularSolver.h:13
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:806
Definition BinaryFunctors.h:21
Arg1 first_argument_type
Definition BinaryFunctors.h:22
Arg2 second_argument_type
Definition BinaryFunctors.h:23
Definition BinaryFunctors.h:499
BinaryOp::second_argument_type second_argument_type
Definition BinaryFunctors.h:502
EIGEN_DEVICE_FUNC bind1st_op(const first_argument_type &val)
Definition BinaryFunctors.h:505
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &b) const
Definition BinaryFunctors.h:510
first_argument_type m_value
Definition BinaryFunctors.h:513
BinaryOp::first_argument_type first_argument_type
Definition BinaryFunctors.h:501
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator()(const second_argument_type &b) const
Definition BinaryFunctors.h:507
BinaryOp::result_type result_type
Definition BinaryFunctors.h:503
Definition BinaryFunctors.h:518
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition BinaryFunctors.h:529
BinaryOp::first_argument_type first_argument_type
Definition BinaryFunctors.h:520
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator()(const first_argument_type &a) const
Definition BinaryFunctors.h:526
BinaryOp::second_argument_type second_argument_type
Definition BinaryFunctors.h:521
second_argument_type m_value
Definition BinaryFunctors.h:532
EIGEN_DEVICE_FUNC bind2nd_op(const second_argument_type &val)
Definition BinaryFunctors.h:524
BinaryOp::result_type result_type
Definition BinaryFunctors.h:522
scalar_quotient_op< LhsScalar, RhsScalar >::result_type result_type
Definition BinaryFunctors.h:395
Definition XprHelper.h:176
@ PacketAccess
Definition XprHelper.h:180
@ Cost
Definition XprHelper.h:179
Definition Meta.h:148
Definition GenericPacketMath.h:107
Definition Meta.h:513
Definition BinaryFunctors.h:468
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_absolute_difference_op >::ReturnType result_type
Definition BinaryFunctors.h:469
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator()(const LhsScalar &a, const RhsScalar &b) const
Definition BinaryFunctors.h:477
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:480
Definition BinaryFunctors.h:409
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:413
Definition BinaryFunctors.h:428
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:432
Definition BinaryFunctors.h:447
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:451
Definition BinaryFunctors.h:202
Definition BinaryFunctors.h:108
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_conj_product_op >::ReturnType result_type
Definition BinaryFunctors.h:114
@ Conj
Definition BinaryFunctors.h:111
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:121
Definition BinaryFunctors.h:350
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:361
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator()(const LhsScalar &a, const RhsScalar &b) const
Definition BinaryFunctors.h:359
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_difference_op >::ReturnType result_type
Definition BinaryFunctors.h:351
Definition XprHelper.h:710
Definition ForwardDeclarations.h:210
Definition BinaryFunctors.h:172
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_max_op >::ReturnType result_type
Definition BinaryFunctors.h:173
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet &a) const
Definition BinaryFunctors.h:184
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:179
Definition BinaryFunctors.h:139
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_min_op >::ReturnType result_type
Definition BinaryFunctors.h:140
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet &a) const
Definition BinaryFunctors.h:151
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:146
Definition BinaryFunctors.h:305
ScalarBinaryOpTraits< Scalar, Exponent, scalar_pow_op >::ReturnType result_type
Definition BinaryFunctors.h:306
EIGEN_DEVICE_FUNC result_type operator()(const Scalar &a, const Exponent &b) const
Definition BinaryFunctors.h:318
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:321
Definition BinaryFunctors.h:71
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_product_op >::ReturnType result_type
Definition BinaryFunctors.h:72
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator()(const LhsScalar &a, const RhsScalar &b) const
Definition BinaryFunctors.h:80
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet &a) const
Definition BinaryFunctors.h:85
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:82
Definition BinaryFunctors.h:379
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:390
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator()(const LhsScalar &a, const RhsScalar &b) const
Definition BinaryFunctors.h:388
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_quotient_op >::ReturnType result_type
Definition BinaryFunctors.h:380
Definition BinaryFunctors.h:33
ScalarBinaryOpTraits< LhsScalar, RhsScalar, scalar_sum_op >::ReturnType result_type
Definition BinaryFunctors.h:34
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type predux(const Packet &a) const
Definition BinaryFunctors.h:47
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &b) const
Definition BinaryFunctors.h:44
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator()(const LhsScalar &a, const RhsScalar &b) const
Definition BinaryFunctors.h:42
Definition ForwardDeclarations.h:17
Definition PacketMath.h:47