10#ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H
11#define EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H
19template<std::
size_t n,
typename Dimension>
struct dget {
20 static const std::size_t value = get<n, Dimension>::value;
24template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
25struct fixed_size_tensor_index_linearization_helper
27 template <
typename Dimensions> EIGEN_DEVICE_FUNC
28 static inline Index run(array<Index, NumIndices>
const& indices,
29 const Dimensions& dimensions)
31 return array_get<
RowMajor ? n - 1 : (NumIndices - n)>(indices) +
32 dget<
RowMajor ? n - 1 : (NumIndices - n), Dimensions>::value *
33 fixed_size_tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
37template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
38struct fixed_size_tensor_index_linearization_helper<
Index, NumIndices, 0,
RowMajor>
40 template <
typename Dimensions> EIGEN_DEVICE_FUNC
41 static inline Index run(array<Index, NumIndices>
const&,
const Dimensions&)
47template<
typename Index, std::
size_t n>
48struct fixed_size_tensor_index_extraction_helper
50 template <
typename Dimensions> EIGEN_DEVICE_FUNC
52 const Dimensions& dimensions)
54 const Index mult = (index == n-1) ? 1 : 0;
55 return array_get<n-1>(dimensions) * mult +
56 fixed_size_tensor_index_extraction_helper<Index, n - 1>::run(index, dimensions);
60template<
typename Index>
61struct fixed_size_tensor_index_extraction_helper<
Index, 0>
63 template <
typename Dimensions> EIGEN_DEVICE_FUNC
74#ifndef EIGEN_EMULATE_CXX11_META_H
87template <
typename std::ptrdiff_t... Indices>
88struct Sizes : internal::numeric_list<std::ptrdiff_t, Indices...> {
89 typedef internal::numeric_list<std::ptrdiff_t, Indices...> Base;
90 static const std::ptrdiff_t total_size = internal::arg_prod(Indices...);
92 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank()
const {
96 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize() {
97 return internal::arg_prod(Indices...);
100 EIGEN_DEVICE_FUNC Sizes() { }
101 template <
typename DenseIndex>
102 explicit EIGEN_DEVICE_FUNC Sizes(
const array<DenseIndex, Base::count>& ) {
105#if EIGEN_HAS_VARIADIC_TEMPLATES
106 template <
typename... DenseIndex> EIGEN_DEVICE_FUNC Sizes(DenseIndex...) { }
107 explicit EIGEN_DEVICE_FUNC Sizes(std::initializer_list<std::ptrdiff_t> ) {
112 template <
typename T> Sizes& operator = (
const T& ) {
117 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[] (
const std::size_t index)
const {
118 return internal::fixed_size_tensor_index_extraction_helper<std::ptrdiff_t, Base::count>::run(index, *
this);
121 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
122 size_t IndexOfColMajor(
const array<DenseIndex, Base::count>& indices)
const {
123 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *
static_cast<const Base*
>(
this));
125 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
126 size_t IndexOfRowMajor(
const array<DenseIndex, Base::count>& indices)
const {
127 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *
static_cast<const Base*
>(
this));
132template <
typename std::ptrdiff_t... Indices>
133EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(
const Sizes<Indices...>&) {
134 return Sizes<Indices...>::total_size;
140template <std::
size_t n>
141struct non_zero_size {
142 typedef internal::type2val<std::size_t, n> type;
145struct non_zero_size<0> {
146 typedef internal::null_type type;
149template <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 {
150 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;
151 static const size_t count = Base::count;
152 static const std::size_t total_size = internal::arg_prod<Base>::value;
154 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t rank()
const {
158 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t TotalSize() {
159 return internal::arg_prod<Base>::value;
163 template <
typename DenseIndex>
164 explicit Sizes(
const array<DenseIndex, Base::count>& ) {
167 template <
typename T> Sizes& operator = (
const T& ) {
172#if EIGEN_HAS_VARIADIC_TEMPLATES
173 template <
typename... DenseIndex> Sizes(DenseIndex... ) { }
174 explicit Sizes(std::initializer_list<std::size_t>) {
178 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex) {
180 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex) {
182 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex) {
184 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex) {
186 EIGEN_DEVICE_FUNC Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex) {
190 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index operator[] (
const Index index)
const {
193 return internal::get<0, Base>::value;
195 return internal::get<1, Base>::value;
197 return internal::get<2, Base>::value;
199 return internal::get<3, Base>::value;
201 return internal::get<4, Base>::value;
203 eigen_assert(
false &&
"index overflow");
204 return static_cast<Index>(-1);
208 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
209 size_t IndexOfColMajor(
const array<DenseIndex, Base::count>& indices)
const {
210 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *
reinterpret_cast<const Base*
>(
this));
212 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
213 size_t IndexOfRowMajor(
const array<DenseIndex, Base::count>& indices)
const {
214 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *
reinterpret_cast<const Base*
>(
this));
219template <std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5>
220EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_prod(
const Sizes<V1, V2, V3, V4, V5>&) {
221 return Sizes<V1, V2, V3, V4, V5>::total_size;
229template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
230struct tensor_index_linearization_helper
232 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
233 Index run(array<Index, NumIndices>
const& indices, array<Index, NumIndices>
const& dimensions)
235 return array_get<
RowMajor ? n : (NumIndices - n - 1)>(indices) +
236 array_get<
RowMajor ? n : (NumIndices - n - 1)>(dimensions) *
237 tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
241template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
242struct tensor_index_linearization_helper<
Index, NumIndices, 0,
RowMajor>
244 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
245 Index run(array<Index, NumIndices>
const& indices, array<Index, NumIndices>
const&)
247 return array_get<
RowMajor ? 0 : NumIndices - 1>(indices);
263template <
typename DenseIndex,
int NumDims>
264struct DSizes : array<DenseIndex, NumDims> {
265 typedef array<DenseIndex, NumDims> Base;
266 static const int count = NumDims;
268 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t rank()
const {
272 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize()
const {
273 return (NumDims == 0) ? 1 : internal::array_prod(*
static_cast<const Base*
>(
this));
276 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DSizes() {
277 for (
int i = 0 ; i < NumDims; ++i) {
281 EIGEN_DEVICE_FUNC
explicit DSizes(
const array<DenseIndex, NumDims>& a) : Base(a) { }
283 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0) {
284 eigen_assert(NumDims == 1);
288#if EIGEN_HAS_VARIADIC_TEMPLATES
289 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
290 EIGEN_STRONG_INLINE
explicit DSizes(DenseIndex firstDimension, DenseIndex secondDimension, IndexTypes... otherDimensions) : Base({{firstDimension, secondDimension, otherDimensions...}}) {
291 EIGEN_STATIC_ASSERT(
sizeof...(otherDimensions) + 2 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE)
294 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1) {
295 eigen_assert(NumDims == 2);
299 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2) {
300 eigen_assert(NumDims == 3);
305 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2,
const DenseIndex i3) {
306 eigen_assert(NumDims == 4);
312 EIGEN_DEVICE_FUNC DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2,
const DenseIndex i3,
const DenseIndex i4) {
313 eigen_assert(NumDims == 5);
322 EIGEN_DEVICE_FUNC DSizes& operator = (
const array<DenseIndex, NumDims>& other) {
323 *
static_cast<Base*
>(
this) = other;
328 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfColMajor(
const array<DenseIndex, NumDims>& indices)
const {
329 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, false>::run(indices, *
static_cast<const Base*
>(
this));
331 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfRowMajor(
const array<DenseIndex, NumDims>& indices)
const {
332 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, true>::run(indices, *
static_cast<const Base*
>(
this));
341template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
342struct tensor_vsize_index_linearization_helper
344 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
345 Index run(array<Index, NumIndices>
const& indices, std::vector<DenseIndex>
const& dimensions)
347 return array_get<
RowMajor ? n : (NumIndices - n - 1)>(indices) +
348 array_get<
RowMajor ? n : (NumIndices - n - 1)>(dimensions) *
349 tensor_vsize_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
353template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
354struct tensor_vsize_index_linearization_helper<
Index, NumIndices, 0,
RowMajor>
356 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
357 Index run(array<Index, NumIndices>
const& indices, std::vector<DenseIndex>
const&)
359 return array_get<
RowMajor ? 0 : NumIndices - 1>(indices);
367template <
typename DenseIndex,
int NumDims>
struct array_size<const DSizes<DenseIndex, NumDims> > {
368 static const size_t value = NumDims;
370template <
typename DenseIndex,
int NumDims>
struct array_size<DSizes<DenseIndex, NumDims> > {
371 static const size_t value = NumDims;
373#ifndef EIGEN_EMULATE_CXX11_META_H
374template <
typename std::ptrdiff_t... Indices>
struct array_size<const Sizes<Indices...> > {
375static const std::ptrdiff_t value = Sizes<Indices...>::count;
377template <
typename std::ptrdiff_t... Indices>
struct array_size<Sizes<Indices...> > {
378static const std::ptrdiff_t value = Sizes<Indices...>::count;
380template <std::ptrdiff_t n,
typename std::ptrdiff_t... Indices> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(
const Sizes<Indices...>&) {
381 return get<n, internal::numeric_list<std::size_t, Indices...> >::value;
383template <std::ptrdiff_t n> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(
const Sizes<>&) {
384 eigen_assert(
false &&
"should never be called");
388template <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> > {
389 static const size_t value = Sizes<V1,V2,V3,V4,V5>::count;
391template <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> > {
392 static const size_t value = Sizes<V1,V2,V3,V4,V5>::count;
394template <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>&) {
395 return get<n, typename Sizes<V1,V2,V3,V4,V5>::Base>::value;
401template <
typename Dims1,
typename Dims2,
size_t n,
size_t m>
402struct sizes_match_below_dim {
403 static EIGEN_DEVICE_FUNC
inline bool run(Dims1&, Dims2&) {
407template <
typename Dims1,
typename Dims2,
size_t n>
408struct sizes_match_below_dim<Dims1, Dims2, n, n> {
409 static EIGEN_DEVICE_FUNC
inline bool run(Dims1& dims1, Dims2& dims2) {
410 return (array_get<n-1>(dims1) == array_get<n-1>(dims2)) &
411 sizes_match_below_dim<Dims1, Dims2, n-1, n-1>::run(dims1, dims2);
414template <
typename Dims1,
typename Dims2>
415struct sizes_match_below_dim<Dims1, Dims2, 0, 0> {
416 static EIGEN_DEVICE_FUNC
inline bool run(Dims1&, Dims2&) {
424template <
typename Dims1,
typename Dims2>
425EIGEN_DEVICE_FUNC
bool dimensions_match(Dims1& dims1, Dims2& dims2) {
426 return internal::sizes_match_below_dim<Dims1, Dims2, internal::array_size<Dims1>::value, internal::array_size<Dims2>::value>::run(dims1, dims2);
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index