aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h
blob: 5c0f78489937526b8b38b19787c75cc742990764 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H
#define EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H

namespace Eigen {
namespace internal {


template<typename Scalar, int Options>
class compute_tensor_flags
{
  enum {
    is_dynamic_size_storage = 1,

    aligned_bit =
    (
        ((Options&DontAlign)==0) && (
#if EIGEN_ALIGN_STATICALLY
            (!is_dynamic_size_storage)
#else
            0
#endif
            ||
#if EIGEN_ALIGN
            is_dynamic_size_storage
#else
            0
#endif
      )
    ) ? AlignedBit : 0,
    packet_access_bit = packet_traits<Scalar>::Vectorizable && aligned_bit ? PacketAccessBit : 0
  };

  public:
    enum { ret = packet_access_bit | aligned_bit};
};


template<typename Scalar_, std::size_t NumIndices_, int Options_>
struct traits<Tensor<Scalar_, NumIndices_, Options_> >
{
  typedef Scalar_ Scalar;
  typedef Dense StorageKind;
  typedef DenseIndex Index;
  enum {
    Options = Options_,
    Flags = compute_tensor_flags<Scalar_, Options_>::ret | LvalueBit,
  };
};


template<typename Scalar_, typename Dimensions, int Options_>
struct traits<TensorFixedSize<Scalar_, Dimensions, Options_> >
{
  typedef Scalar_ Scalar;
  typedef Dense StorageKind;
  typedef DenseIndex Index;
  enum {
    Options = Options_,
    Flags = compute_tensor_flags<Scalar_, Options_>::ret | LvalueBit,
  };
};


template<typename PlainObjectType, int Options_>
struct traits<TensorMap<PlainObjectType, Options_> >
  : public traits<PlainObjectType>
{
  typedef traits<PlainObjectType> BaseTraits;
  typedef typename BaseTraits::Scalar Scalar;
  typedef typename BaseTraits::StorageKind StorageKind;
  typedef typename BaseTraits::Index Index;
  enum {
    Options = Options_,
    Flags = ((BaseTraits::Flags | LvalueBit) & ~AlignedBit) | (Options&Aligned ? AlignedBit : 0),
  };
};

template<typename PlainObjectType>
struct traits<TensorRef<PlainObjectType> >
  : public traits<PlainObjectType>
{
  typedef traits<PlainObjectType> BaseTraits;
  typedef typename BaseTraits::Scalar Scalar;
  typedef typename BaseTraits::StorageKind StorageKind;
  typedef typename BaseTraits::Index Index;
  enum {
    Options = BaseTraits::Options,
    Flags = ((BaseTraits::Flags | LvalueBit) & ~AlignedBit) | (Options&Aligned ? AlignedBit : 0),
  };
};


template<typename _Scalar, std::size_t NumIndices_, int Options>
struct eval<Tensor<_Scalar, NumIndices_, Options>, Eigen::Dense>
{
  typedef const Tensor<_Scalar, NumIndices_, Options>& type;
};

template<typename _Scalar, std::size_t NumIndices_, int Options>
struct eval<const Tensor<_Scalar, NumIndices_, Options>, Eigen::Dense>
{
  typedef const Tensor<_Scalar, NumIndices_, Options>& type;
};

template<typename Scalar_, typename Dimensions, int Options>
struct eval<TensorFixedSize<Scalar_, Dimensions, Options>, Eigen::Dense>
{
  typedef const TensorFixedSize<Scalar_, Dimensions, Options>& type;
};

template<typename Scalar_, typename Dimensions, int Options>
struct eval<const TensorFixedSize<Scalar_, Dimensions, Options>, Eigen::Dense>
{
  typedef const TensorFixedSize<Scalar_, Dimensions, Options>& type;
};

template<typename PlainObjectType, int Options>
struct eval<TensorMap<PlainObjectType, Options>, Eigen::Dense>
{
  typedef const TensorMap<PlainObjectType, Options>& type;
};

template<typename PlainObjectType, int Options>
struct eval<const TensorMap<PlainObjectType, Options>, Eigen::Dense>
{
  typedef const TensorMap<PlainObjectType, Options>& type;
};

template<typename PlainObjectType>
struct eval<TensorRef<PlainObjectType>, Eigen::Dense>
{
  typedef const TensorRef<PlainObjectType>& type;
};

template<typename PlainObjectType>
struct eval<const TensorRef<PlainObjectType>, Eigen::Dense>
{
  typedef const TensorRef<PlainObjectType>& type;
};


template <typename Scalar_, std::size_t NumIndices_, int Options_>
struct nested<Tensor<Scalar_, NumIndices_, Options_>, 1, typename eval<Tensor<Scalar_, NumIndices_, Options_> >::type>
{
  typedef const Tensor<Scalar_, NumIndices_, Options_>& type;
};

template <typename Scalar_, std::size_t NumIndices_, int Options_>
struct nested<const Tensor<Scalar_, NumIndices_, Options_>, 1, typename eval<const Tensor<Scalar_, NumIndices_, Options_> >::type>
{
  typedef const Tensor<Scalar_, NumIndices_, Options_>& type;
};

template <typename Scalar_, typename Dimensions, int Options>
struct nested<TensorFixedSize<Scalar_, Dimensions, Options>, 1, typename eval<TensorFixedSize<Scalar_, Dimensions, Options> >::type>
{
  typedef const TensorFixedSize<Scalar_, Dimensions, Options>& type;
};

template <typename Scalar_, typename Dimensions, int Options>
struct nested<const TensorFixedSize<Scalar_, Dimensions, Options>, 1, typename eval<const TensorFixedSize<Scalar_, Dimensions, Options> >::type>
{
  typedef const TensorFixedSize<Scalar_, Dimensions, Options>& type;
};


template <typename PlainObjectType, int Options>
struct nested<TensorMap<PlainObjectType, Options>, 1, typename eval<TensorMap<PlainObjectType, Options> >::type>
{
  typedef const TensorMap<PlainObjectType, Options>& type;
};

template <typename PlainObjectType, int Options>
struct nested<const TensorMap<PlainObjectType, Options>, 1, typename eval<TensorMap<PlainObjectType, Options> >::type>
{
  typedef const TensorMap<PlainObjectType, Options>& type;
};

template <typename PlainObjectType>
struct nested<TensorRef<PlainObjectType>, 1, typename eval<TensorRef<PlainObjectType> >::type>
{
  typedef const TensorRef<PlainObjectType>& type;
};

template <typename PlainObjectType>
struct nested<const TensorRef<PlainObjectType>, 1, typename eval<TensorRef<PlainObjectType> >::type>
{
  typedef const TensorRef<PlainObjectType>& type;
};

}  // end namespace internal
}  // end namespace Eigen

#endif // EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H