10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H 33 template <
typename Index>
struct IndexPair {
34 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair() : first(0), second(0) { }
35 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair(Index f, Index s) : first(f), second(s) { }
43 template<std::
size_t n,
typename Dimension>
struct dget {
44 static const std::size_t value = get<n, Dimension>::value;
48 template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
49 struct fixed_size_tensor_index_linearization_helper
51 template <
typename Dimensions> EIGEN_DEVICE_FUNC
52 static inline Index run(array<Index, NumIndices>
const& indices,
53 const Dimensions& dimensions)
55 return array_get<RowMajor ? n - 1 : (NumIndices - n)>(indices) +
56 dget<RowMajor ? n - 1 : (NumIndices - n), Dimensions>::value *
57 fixed_size_tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
61 template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
62 struct fixed_size_tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor>
64 template <
typename Dimensions> EIGEN_DEVICE_FUNC
65 static inline Index run(array<Index, NumIndices>
const&,
const Dimensions&)
71 template<
typename Index, std::
size_t n>
72 struct fixed_size_tensor_index_extraction_helper
74 template <
typename Dimensions> EIGEN_DEVICE_FUNC
75 static inline Index run(
const Index index,
76 const Dimensions& dimensions)
78 const Index mult = (index == n-1) ? 1 : 0;
79 return array_get<n-1>(dimensions) * mult +
80 fixed_size_tensor_index_extraction_helper<Index, n - 1>::run(index, dimensions);
84 template<
typename Index>
85 struct fixed_size_tensor_index_extraction_helper<Index, 0>
87 template <
typename Dimensions> EIGEN_DEVICE_FUNC
88 static inline Index run(
const Index,
99 #ifndef EIGEN_EMULATE_CXX11_META_H 100 template <
typename std::ptrdiff_t... Indices>
101 struct Sizes : internal::numeric_list<std::ptrdiff_t, Indices...> {
102 typedef internal::numeric_list<std::ptrdiff_t, Indices...> Base;
103 static const std::ptrdiff_t total_size = internal::arg_prod(Indices...);
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank()
const {
109 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize() {
110 return internal::arg_prod(Indices...);
114 template <
typename DenseIndex>
115 explicit Sizes(
const array<DenseIndex, Base::count>& ) {
118 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 119 template <
typename... DenseIndex> Sizes(DenseIndex...) { }
120 explicit Sizes(std::initializer_list<std::ptrdiff_t> ) {
125 template <
typename T> Sizes& operator = (
const T& ) {
130 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[] (
const std::size_t index)
const {
131 return internal::fixed_size_tensor_index_extraction_helper<std::ptrdiff_t, Base::count>::run(index, *
this);
134 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
135 size_t IndexOfColMajor(
const array<DenseIndex, Base::count>& indices)
const {
136 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *static_cast<const Base*>(
this));
138 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
139 size_t IndexOfRowMajor(
const array<DenseIndex, Base::count>& indices)
const {
140 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *static_cast<const Base*>(
this));
145 template <
typename std::ptrdiff_t... Indices>
146 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(
const Sizes<Indices...>&) {
147 return Sizes<Indices...>::total_size;
153 template <std::
size_t n>
154 struct non_zero_size {
155 typedef internal::type2val<std::size_t, n> type;
158 struct non_zero_size<0> {
159 typedef internal::null_type type;
162 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 {
163 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;
164 static const size_t count = Base::count;
165 static const std::size_t total_size = internal::arg_prod<Base>::value;
167 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t rank()
const {
171 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t TotalSize() {
172 return internal::arg_prod<Base>::value;
176 template <
typename DenseIndex>
177 explicit Sizes(
const array<DenseIndex, Base::count>& ) {
180 template <
typename T> Sizes& operator = (
const T& ) {
185 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 186 template <
typename... DenseIndex> Sizes(DenseIndex... ) { }
187 explicit Sizes(std::initializer_list<std::size_t>) {
191 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex) {
193 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex,
const DenseIndex) {
195 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex) {
197 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex) {
199 EIGEN_DEVICE_FUNC
explicit Sizes(
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex,
const DenseIndex) {
203 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex operator[] (
const int index)
const {
206 return internal::get<0, Base>::value;
208 return internal::get<1, Base>::value;
210 return internal::get<2, Base>::value;
212 return internal::get<3, Base>::value;
214 return internal::get<4, Base>::value;
216 eigen_assert(
false &&
"index overflow");
217 return static_cast<DenseIndex
>(-1);
221 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
222 size_t IndexOfColMajor(
const array<DenseIndex, Base::count>& indices)
const {
223 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *reinterpret_cast<const Base*>(
this));
225 template <
typename DenseIndex> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
226 size_t IndexOfRowMajor(
const array<DenseIndex, Base::count>& indices)
const {
227 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *reinterpret_cast<const Base*>(
this));
232 template <std::
size_t V1, std::
size_t V2, std::
size_t V3, std::
size_t V4, std::
size_t V5>
233 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t array_prod(
const Sizes<V1, V2, V3, V4, V5>&) {
234 return Sizes<V1, V2, V3, V4, V5>::total_size;
242 template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
243 struct tensor_index_linearization_helper
245 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
246 Index run(array<Index, NumIndices>
const& indices, array<Index, NumIndices>
const& dimensions)
248 return array_get<RowMajor ? n : (NumIndices - n - 1)>(indices) +
249 array_get<RowMajor ? n : (NumIndices - n - 1)>(dimensions) *
250 tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
254 template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
255 struct tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor>
257 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
258 Index run(array<Index, NumIndices>
const& indices, array<Index, NumIndices>
const&)
260 return array_get<RowMajor ? 0 : NumIndices - 1>(indices);
268 template <
typename DenseIndex,
int NumDims>
269 struct DSizes : array<DenseIndex, NumDims> {
270 typedef array<DenseIndex, NumDims> Base;
271 static const int count = NumDims;
273 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
size_t rank()
const {
277 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize()
const {
278 return internal::array_prod(*static_cast<const Base*>(
this));
281 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DSizes() {
282 for (
int i = 0 ; i < NumDims; ++i) {
286 EIGEN_DEVICE_FUNC
explicit DSizes(
const array<DenseIndex, NumDims>& a) : Base(a) { }
288 #ifdef EIGEN_HAS_VARIADIC_TEMPLATES 289 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
290 EIGEN_STRONG_INLINE
explicit DSizes(DenseIndex firstDimension, IndexTypes... otherDimensions) {
291 EIGEN_STATIC_ASSERT(
sizeof...(otherDimensions) + 1 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE)
292 (*this) = array<DenseIndex, NumDims>{{firstDimension, otherDimensions...}};
295 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0) {
296 eigen_assert(NumDims == 1);
299 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0,
const DenseIndex i1) {
300 eigen_assert(NumDims == 2);
304 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2) {
305 eigen_assert(NumDims == 3);
310 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2,
const DenseIndex i3) {
311 eigen_assert(NumDims == 4);
317 EIGEN_DEVICE_FUNC
explicit DSizes(
const DenseIndex i0,
const DenseIndex i1,
const DenseIndex i2,
const DenseIndex i3,
const DenseIndex i4) {
318 eigen_assert(NumDims == 5);
327 EIGEN_DEVICE_FUNC DSizes& operator = (
const array<DenseIndex, NumDims>& other) {
328 *
static_cast<Base*
>(
this) = other;
333 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfColMajor(
const array<DenseIndex, NumDims>& indices)
const {
334 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, false>::run(indices, *static_cast<const Base*>(
this));
336 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex IndexOfRowMajor(
const array<DenseIndex, NumDims>& indices)
const {
337 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, true>::run(indices, *static_cast<const Base*>(
this));
346 template<
typename Index, std::
size_t NumIndices, std::
size_t n,
bool RowMajor>
347 struct tensor_vsize_index_linearization_helper
349 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
350 Index run(array<Index, NumIndices>
const& indices, std::vector<DenseIndex>
const& dimensions)
352 return array_get<RowMajor ? n : (NumIndices - n - 1)>(indices) +
353 array_get<RowMajor ? n : (NumIndices - n - 1)>(dimensions) *
354 tensor_vsize_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
358 template<
typename Index, std::
size_t NumIndices,
bool RowMajor>
359 struct tensor_vsize_index_linearization_helper<Index, NumIndices, 0, RowMajor>
361 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
362 Index run(array<Index, NumIndices>
const& indices, std::vector<DenseIndex>
const&)
364 return array_get<RowMajor ? 0 : NumIndices - 1>(indices);
372 template <
typename DenseIndex,
int NumDims>
struct array_size<const DSizes<DenseIndex, NumDims> > {
373 static const size_t value = NumDims;
375 template <
typename DenseIndex,
int NumDims>
struct array_size<DSizes<DenseIndex, NumDims> > {
376 static const size_t value = NumDims;
378 #ifndef EIGEN_EMULATE_CXX11_META_H 379 template <
typename std::ptrdiff_t... Indices>
struct array_size<const Sizes<Indices...> > {
380 static const std::ptrdiff_t value = Sizes<Indices...>::count;
382 template <
typename std::ptrdiff_t... Indices>
struct array_size<Sizes<Indices...> > {
383 static const std::ptrdiff_t value = Sizes<Indices...>::count;
385 template <std::ptrdiff_t n,
typename std::ptrdiff_t... Indices> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(
const Sizes<Indices...>&) {
386 return get<n, internal::numeric_list<std::size_t, Indices...> >::value;
388 template <std::ptrdiff_t n> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(
const Sizes<>&) {
389 eigen_assert(
false &&
"should never be called");
393 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> > {
394 static const size_t value = Sizes<V1,V2,V3,V4,V5>::count;
396 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> > {
397 static const size_t value = Sizes<V1,V2,V3,V4,V5>::count;
399 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>&) {
400 return get<n, typename Sizes<V1,V2,V3,V4,V5>::Base>::value;
406 template <
typename Dims1,
typename Dims2,
size_t n,
size_t m>
407 struct sizes_match_below_dim {
408 static inline bool run(Dims1&, Dims2&) {
412 template <
typename Dims1,
typename Dims2,
size_t n>
413 struct sizes_match_below_dim<Dims1, Dims2, n, n> {
414 static inline bool run(Dims1& dims1, Dims2& dims2) {
415 return (array_get<n-1>(dims1) == array_get<n-1>(dims2)) &
416 sizes_match_below_dim<Dims1, Dims2, n-1, n-1>::run(dims1, dims2);
419 template <
typename Dims1,
typename Dims2>
420 struct sizes_match_below_dim<Dims1, Dims2, 0, 0> {
421 static inline bool run(Dims1&, Dims2&) {
429 template <
typename Dims1,
typename Dims2>
430 bool dimensions_match(Dims1& dims1, Dims2& dims2) {
431 return internal::sizes_match_below_dim<Dims1, Dims2, internal::array_size<Dims1>::value, internal::array_size<Dims2>::value>::run(dims1, dims2);
436 #endif // EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13