10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H 35 template<std::
size_t n,
typename Dimension>
struct dget {
36 static const std::size_t value = get<n, Dimension>::value;
40 template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
41 struct fixed_size_tensor_index_linearization_helper
43 template <
typename Dimensions> EIGEN_DEVICE_FUNC
44 static inline Index run(array<Index, NumIndices>
const& indices,
45 const Dimensions& dimensions)
47 return array_get<RowMajor ? n - 1 : (NumIndices - n)>(indices) +
48 dget<RowMajor ? n - 1 : (NumIndices - n), Dimensions>::value *
49 fixed_size_tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
53 template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
54 struct fixed_size_tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor>
56 template <
typename Dimensions> EIGEN_DEVICE_FUNC
57 static inline Index run(array<Index, NumIndices>
const&,
const Dimensions&)
63 template<
typename Index, std::
size_t n>
64 struct fixed_size_tensor_index_extraction_helper
66 template <
typename Dimensions> EIGEN_DEVICE_FUNC
67 static inline Index run(
const Index index,
68 const Dimensions& dimensions)
70 const Index mult = (index == n-1) ? 1 : 0;
71 return array_get<n-1>(dimensions) * mult +
72 fixed_size_tensor_index_extraction_helper<Index, n - 1>::run(index, dimensions);
76 template<
typename Index>
77 struct fixed_size_tensor_index_extraction_helper<Index, 0>
79 template <
typename Dimensions> EIGEN_DEVICE_FUNC
80 static inline Index run(
const Index,
91 #ifndef EIGEN_EMULATE_CXX11_META_H 92 template <
typename std::ptrdiff_t... Indices>
93 struct Sizes : internal::numeric_list<std::ptrdiff_t, Indices...> {
94 typedef internal::numeric_list<std::ptrdiff_t, Indices...> Base;
95 static const std::ptrdiff_t total_size = internal::arg_prod(Indices...);
97 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank()
const {
101 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize() {
102 return internal::arg_prod(Indices...);
105 EIGEN_DEVICE_FUNC Sizes() { }
106 template <
typename DenseIndex>
107 explicit EIGEN_DEVICE_FUNC Sizes(
const array<DenseIndex, Base::count>& ) {
110 #if EIGEN_HAS_VARIADIC_TEMPLATES 111 template <
typename... DenseIndex> EIGEN_DEVICE_FUNC Sizes(DenseIndex...) { }
112 explicit EIGEN_DEVICE_FUNC Sizes(std::initializer_list<std::ptrdiff_t> ) {
117 template <
typename T> Sizes& operator = (
const T& ) {
122 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[] (
const std::size_t index)
const {
123 return internal::fixed_size_tensor_index_extraction_helper<std::ptrdiff_t, Base::count>::run(index, *
this);
126 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
127 size_t IndexOfColMajor(
const array<DenseIndex, Base::count>& indices)
const {
128 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *static_cast<const Base*>(
this));
130 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
131 size_t IndexOfRowMajor(
const array<DenseIndex, Base::count>& indices)
const {
132 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *static_cast<const Base*>(
this));
137 template <
typename std::ptrdiff_t... Indices>
138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(
const Sizes<Indices...>&) {
139 return Sizes<Indices...>::total_size;
145 template <std::
size_t n>
146 struct non_zero_size {
147 typedef internal::type2val<std::size_t, n> type;
150 struct non_zero_size<0> {
151 typedef internal::null_type type;
154 template <std::
size_t V1=0, std::
size_t V2=0, std::
size_t V3=0, std::
size_t V4=0, std::
size_t V5=0>
struct Sizes {
155 typedef typename internal::make_type_list<typename non_zero_size<V1>::type,
typename non_zero_size<V2>::type,
typename non_zero_size<V3>::type,
typename non_zero_size<V4>::type,
typename non_zero_size<V5>::type >::type Base;
156 static const size_t count = Base::count;
157 static const std::size_t total_size = internal::arg_prod<Base>::value;
159 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t rank()
const {
163 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t TotalSize() {
164 return internal::arg_prod<Base>::value;
168 template <
typename DenseIndex>
169 explicit Sizes(
const array<DenseIndex, Base::count>& ) {
172 template <
typename T> Sizes& operator = (
const T& ) {
177 #if EIGEN_HAS_VARIADIC_TEMPLATES 178 template <
typename... DenseIndex> Sizes(DenseIndex... ) { }
179 explicit Sizes(std::initializer_list<std::size_t>) {
183 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex) {
185 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex) {
187 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex) {
189 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex) {
191 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex) {
195 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex operator[] (
const int index)
const {
198 return internal::get<0, Base>::value;
200 return internal::get<1, Base>::value;
202 return internal::get<2, Base>::value;
204 return internal::get<3, Base>::value;
206 return internal::get<4, Base>::value;
208 eigen_assert(
false &&
"index overflow");
209 return static_cast<DenseIndex
>(-1);
213 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
214 size_t IndexOfColMajor(
const array<DenseIndex, Base::count>& indices)
const {
215 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *reinterpret_cast<const Base*>(
this));
217 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
218 size_t IndexOfRowMajor(
const array<DenseIndex, Base::count>& indices)
const {
219 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *reinterpret_cast<const Base*>(
this));
224 template <std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5>
225 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_prod(
const Sizes<V1, V2, V3, V4, V5>&) {
226 return Sizes<V1, V2, V3, V4, V5>::total_size;
234 template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
235 struct tensor_index_linearization_helper
237 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
238 Index run(array<Index, NumIndices>
const& indices, array<Index, NumIndices>
const& dimensions)
240 return array_get<RowMajor ? n : (NumIndices - n - 1)>(indices) +
241 array_get<RowMajor ? n : (NumIndices - n - 1)>(dimensions) *
242 tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
246 template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
247 struct tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor>
249 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
250 Index run(array<Index, NumIndices>
const& indices, array<Index, NumIndices>
const&)
252 return array_get<RowMajor ? 0 : NumIndices - 1>(indices);
260 template <
typename DenseIndex,
int NumDims>
261 struct DSizes : array<DenseIndex, NumDims> {
262 typedef array<DenseIndex, NumDims> Base;
263 static const int count = NumDims;
265 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t rank()
const {
269 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize()
const {
270 return (NumDims == 0) ? 1 : internal::array_prod(*static_cast<const Base*>(
this));
273 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DSizes() {
274 for (
int i = 0 ; i < NumDims; ++i) {
278 EIGEN_DEVICE_FUNC
explicit DSizes(
const array<DenseIndex, NumDims>& a) : Base(a) { }
280 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0) {
281 eigen_assert(NumDims == 1);
285 #if EIGEN_HAS_VARIADIC_TEMPLATES 286 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
287 EIGEN_STRONG_INLINE
explicit DSizes(DenseIndex firstDimension, DenseIndex secondDimension, IndexTypes... otherDimensions) : Base({{firstDimension, secondDimension, otherDimensions...}}) {
288 EIGEN_STATIC_ASSERT(
sizeof...(otherDimensions) + 2 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE)
291 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1) {
292 eigen_assert(NumDims == 2);
296 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2) {
297 eigen_assert(NumDims == 3);
302 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2,
const DenseIndex i3) {
303 eigen_assert(NumDims == 4);
309 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2,
const DenseIndex i3,
const DenseIndex i4) {
310 eigen_assert(NumDims == 5);
319 EIGEN_DEVICE_FUNC DSizes& operator = (
const array<DenseIndex, NumDims>& other) {
320 *
static_cast<Base*
>(
this) = other;
325 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfColMajor(
const array<DenseIndex, NumDims>& indices)
const {
326 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, false>::run(indices, *static_cast<const Base*>(
this));
328 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfRowMajor(
const array<DenseIndex, NumDims>& indices)
const {
329 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, true>::run(indices, *static_cast<const Base*>(
this));
338 template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
339 struct tensor_vsize_index_linearization_helper
341 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
342 Index run(array<Index, NumIndices>
const& indices, std::vector<DenseIndex>
const& dimensions)
344 return array_get<RowMajor ? n : (NumIndices - n - 1)>(indices) +
345 array_get<RowMajor ? n : (NumIndices - n - 1)>(dimensions) *
346 tensor_vsize_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
350 template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
351 struct tensor_vsize_index_linearization_helper<Index, NumIndices, 0, RowMajor>
353 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
354 Index run(array<Index, NumIndices>
const& indices, std::vector<DenseIndex>
const&)
356 return array_get<RowMajor ? 0 : NumIndices - 1>(indices);
364 template <
typename DenseIndex,
int NumDims>
struct array_size<const DSizes<DenseIndex, NumDims> > {
365 static const size_t value = NumDims;
367 template <
typename DenseIndex,
int NumDims>
struct array_size<DSizes<DenseIndex, NumDims> > {
368 static const size_t value = NumDims;
370 #ifndef EIGEN_EMULATE_CXX11_META_H 371 template <
typename std::ptrdiff_t... Indices>
struct array_size<const Sizes<Indices...> > {
372 static const std::ptrdiff_t value = Sizes<Indices...>::count;
374 template <
typename std::ptrdiff_t... Indices>
struct array_size<Sizes<Indices...> > {
375 static const std::ptrdiff_t value = Sizes<Indices...>::count;
377 template <std::ptrdiff_t n,
typename std::ptrdiff_t... Indices> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(
const Sizes<Indices...>&) {
378 return get<n, internal::numeric_list<std::size_t, Indices...> >::value;
380 template <std::ptrdiff_t n> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(
const Sizes<>&) {
381 eigen_assert(
false &&
"should never be called");
385 template <std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5>
struct array_size<const Sizes<V1,V2,V3,V4,V5> > {
386 static const size_t value = Sizes<V1,V2,V3,V4,V5>::count;
388 template <std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5>
struct array_size<Sizes<V1,V2,V3,V4,V5> > {
389 static const size_t value = Sizes<V1,V2,V3,V4,V5>::count;
391 template <std::
size_t n, std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_get(
const Sizes<V1,V2,V3,V4,V5>&) {
392 return get<n, typename Sizes<V1,V2,V3,V4,V5>::Base>::value;
398 template <
typename Dims1,
typename Dims2,
size_t n,
size_t m>
399 struct sizes_match_below_dim {
400 static EIGEN_DEVICE_FUNC
inline bool run(Dims1&, Dims2&) {
404 template <
typename Dims1,
typename Dims2,
size_t n>
405 struct sizes_match_below_dim<Dims1, Dims2, n, n> {
406 static EIGEN_DEVICE_FUNC
inline bool run(Dims1& dims1, Dims2& dims2) {
407 return (array_get<n-1>(dims1) == array_get<n-1>(dims2)) &
408 sizes_match_below_dim<Dims1, Dims2, n-1, n-1>::run(dims1, dims2);
411 template <
typename Dims1,
typename Dims2>
412 struct sizes_match_below_dim<Dims1, Dims2, 0, 0> {
413 static EIGEN_DEVICE_FUNC
inline bool run(Dims1&, Dims2&) {
421 template <
typename Dims1,
typename Dims2>
422 EIGEN_DEVICE_FUNC
bool dimensions_match(Dims1& dims1, Dims2& dims2) {
423 return internal::sizes_match_below_dim<Dims1, Dims2, internal::array_size<Dims1>::value, internal::array_size<Dims2>::value>::run(dims1, dims2);
428 #endif // EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45