TensorMeta.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
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_CXX11_TENSOR_TENSOR_META_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_META_H
12 
13 namespace Eigen {
14 
15 template<bool cond> struct Cond {};
16 
17 template<typename T1, typename T2> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
18 const T1& choose(Cond<true>, const T1& first, const T2&) {
19  return first;
20 }
21 
22 template<typename T1, typename T2> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
23 const T2& choose(Cond<false>, const T1&, const T2& second) {
24  return second;
25 }
26 
27 template <size_t n> struct max_n_1 {
28  static const size_t size = n;
29 };
30 template <> struct max_n_1<0> {
31  static const size_t size = 1;
32 };
33 
34 
35 
36 
37 #if defined(EIGEN_HAS_CONSTEXPR)
38 #define EIGEN_CONSTEXPR constexpr
39 #else
40 #define EIGEN_CONSTEXPR
41 #endif
42 
43 // Tuple mimics std::pair but works on e.g. nvcc.
44 template <typename U, typename V> struct Tuple {
45  public:
46  U first;
47  V second;
48 
49  typedef U first_type;
50  typedef V second_type;
51 
52  EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
53  Tuple() : first(), second() {}
54 
55  EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
56  Tuple(const U& f, const V& s) : first(f), second(s) {}
57 
58  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
59  Tuple& operator= (const Tuple& rhs) {
60  if (&rhs == this) return *this;
61  first = rhs.first;
62  second = rhs.second;
63  return *this;
64  }
65 
66  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
67  void swap(Tuple& rhs) {
68  using numext::swap;
69  swap(first, rhs.first);
70  swap(second, rhs.second);
71  }
72 };
73 
74 template <typename U, typename V>
75 EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
76 bool operator==(const Tuple<U, V>& x, const Tuple<U, V>& y) {
77  return (x.first == y.first && x.second == y.second);
78 }
79 
80 template <typename U, typename V>
81 EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
82 bool operator!=(const Tuple<U, V>& x, const Tuple<U, V>& y) {
83  return !(x == y);
84 }
85 
86 #undef EIGEN_CONSTEXPR
87 
88 } // namespace Eigen
89 
90 #endif // EIGEN_CXX11_TENSOR_TENSOR_META_H
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13