10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_DIMENSIONS_H
37 template<std::ptrdiff_t n,
typename Dimension>
struct dget {
38 static const std::ptrdiff_t value = get<n, Dimension>::value;
42 template<
typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n,
bool RowMajor>
43 struct fixed_size_tensor_index_linearization_helper
47 const Dimensions& dimensions)
50 dget<
RowMajor ?
n - 1 : (NumIndices -
n), Dimensions>::value *
51 fixed_size_tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
55 template<
typename Index, std::ptrdiff_t NumIndices,
bool RowMajor>
56 struct fixed_size_tensor_index_linearization_helper<
Index, NumIndices, 0,
RowMajor>
65 template<
typename Index, std::ptrdiff_t n>
66 struct fixed_size_tensor_index_extraction_helper
69 static EIGEN_STRONG_INLINE
Index run(
const Index index,
70 const Dimensions& dimensions)
72 const Index mult = (index ==
n-1) ? 1 : 0;
74 fixed_size_tensor_index_extraction_helper<Index, n - 1>::run(index, dimensions);
78 template<
typename Index>
79 struct fixed_size_tensor_index_extraction_helper<
Index, 0>
82 static EIGEN_STRONG_INLINE
Index run(
const Index,
93 #ifndef EIGEN_EMULATE_CXX11_META_H
94 template <
typename std::ptrdiff_t... Indices>
96 typedef internal::numeric_list<std::ptrdiff_t, Indices...>
Base;
99 static const ptrdiff_t
count = Base::count;
110 template <
typename DenseIndex>
125 return internal::fixed_size_tensor_index_extraction_helper<std::ptrdiff_t, Base::count>::run(index,
t);
130 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices,
t);
134 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices,
t);
139 template <
typename std::ptrdiff_t... Indices>
141 return Sizes<Indices...>::total_size;
147 template <std::ptrdiff_t n>
148 struct non_zero_size {
149 typedef internal::type2val<std::ptrdiff_t, n> type;
152 struct non_zero_size<0> {
153 typedef internal::null_type type;
156 template <std::ptrdiff_t V1=0, std::ptrdiff_t V2=0, std::ptrdiff_t V3=0, std::ptrdiff_t V4=0, std::ptrdiff_t V5=0>
struct Sizes {
157 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;
158 static const std::ptrdiff_t
count = Base::count;
159 static const std::ptrdiff_t
total_size = internal::arg_prod<Base>::value;
166 return internal::arg_prod<Base>::value;
170 template <
typename DenseIndex>
181 explicit Sizes(std::initializer_list<std::ptrdiff_t>) {
188 return internal::get<0, Base>::value;
190 return internal::get<1, Base>::value;
192 return internal::get<2, Base>::value;
194 return internal::get<3, Base>::value;
196 return internal::get<4, Base>::value;
199 return static_cast<Index>(-1);
205 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(indices, *
reinterpret_cast<const Base*
>(
this));
209 return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(indices, *
reinterpret_cast<const Base*
>(
this));
214 template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5>
224 template<
typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n,
bool RowMajor>
225 struct tensor_index_linearization_helper
232 tensor_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
236 template<
typename Index, std::ptrdiff_t NumIndices,
bool RowMajor>
237 struct tensor_index_linearization_helper<
Index, NumIndices, 0,
RowMajor>
250 template <
typename DenseIndex,
int NumDims>
264 for (
int i = 0 ;
i < NumDims; ++
i) {
276 for (
int i = 0 ;
i < NumDims; ++
i) {
283 template<
typename OtherIndex>
290 typename internal::promote_index_type<
294 >::value,
void*> = 0) {
295 for (
int i = 0;
i < NumDims; ++
i) {
300 template <
typename FirstType,
typename... OtherTypes>
303 for (
int i = 0;
i < dimensions.count; ++
i) {
304 (*this)[
i] = dimensions[
i];
308 #ifndef EIGEN_EMULATE_CXX11_META_H
309 template <
typename std::ptrdiff_t... Indices>
311 for (
int i = 0 ;
i < NumDims; ++
i) {
316 template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5>
318 for (
int i = 0 ;
i < NumDims; ++
i) {
325 EIGEN_STRONG_INLINE
explicit DSizes(
DenseIndex firstDimension,
DenseIndex secondDimension, IndexTypes... otherDimensions) :
Base({{firstDimension, secondDimension, otherDimensions...}}) {
326 EIGEN_STATIC_ASSERT(
sizeof...(otherDimensions) + 2 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE)
330 *
static_cast<Base*
>(
this) = other;
336 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, false>::run(indices, *
static_cast<const Base*
>(
this));
339 return internal::tensor_index_linearization_helper<DenseIndex, NumDims, NumDims - 1, true>::run(indices, *
static_cast<const Base*
>(
this));
343 template <
typename IndexType,
int NumDims>
347 for (
int i = 0;
i < NumDims; ++
i) {
348 if (
i > 0) os <<
", ";
357 template<
typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n,
bool RowMajor>
358 struct tensor_vsize_index_linearization_helper
365 tensor_vsize_index_linearization_helper<Index, NumIndices, n - 1, RowMajor>::run(indices, dimensions);
369 template<
typename Index, std::ptrdiff_t NumIndices,
bool RowMajor>
370 struct tensor_vsize_index_linearization_helper<
Index, NumIndices, 0,
RowMajor>
383 template <
typename DenseIndex,
int NumDims>
struct array_size<const DSizes<
DenseIndex, NumDims> > {
384 static const ptrdiff_t value = NumDims;
386 template <
typename DenseIndex,
int NumDims>
struct array_size<DSizes<
DenseIndex, NumDims> > {
387 static const ptrdiff_t value = NumDims;
389 #ifndef EIGEN_EMULATE_CXX11_META_H
390 template <
typename std::ptrdiff_t... Indices>
struct array_size<const Sizes<Indices...> > {
391 static const std::ptrdiff_t value = Sizes<Indices...>::count;
393 template <
typename std::ptrdiff_t... Indices>
struct array_size<Sizes<Indices...> > {
394 static const std::ptrdiff_t value = Sizes<Indices...>::count;
397 return get<
n, internal::numeric_list<std::ptrdiff_t, Indices...> >::value;
404 template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5>
struct array_size<const
Sizes<V1,V2,V3,V4,V5> > {
407 template <std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5>
struct array_size<Sizes<V1,V2,V3,V4,V5> > {
410 template <std::ptrdiff_t n, std::ptrdiff_t V1, std::ptrdiff_t V2, std::ptrdiff_t V3, std::ptrdiff_t V4, std::ptrdiff_t V5>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t
array_get(
const Sizes<V1,V2,V3,V4,V5>&) {
411 return get<n, typename Sizes<V1,V2,V3,V4,V5>::Base>::value;
417 template <
typename Dims1,
typename Dims2, ptrdiff_t n, ptrdiff_t m>
418 struct sizes_match_below_dim {
423 template <
typename Dims1,
typename Dims2, ptrdiff_t n>
424 struct sizes_match_below_dim<Dims1, Dims2,
n,
n> {
425 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool run(Dims1& dims1, Dims2& dims2) {
427 sizes_match_below_dim<Dims1, Dims2, n-1, n-1>::run(dims1, dims2);
430 template <
typename Dims1,
typename Dims2>
431 struct sizes_match_below_dim<Dims1, Dims2, 0, 0> {
440 template <
typename Dims1,
typename Dims2>
442 return internal::sizes_match_below_dim<Dims1, Dims2, internal::array_size<Dims1>::value, internal::array_size<Dims2>::value>::run(dims1, dims2);
#define EIGEN_ALWAYS_INLINE
#define EIGEN_DEVICE_FUNC
#define EIGEN_STATIC_ASSERT(X, MSG)
constexpr T array_get(const numeric_list< T, a, as... > &)
constexpr decltype(reduce< product_op, Ts... >::run((*((Ts *) 0))... arg_prod))(Ts... ts)
constexpr auto array_prod(const array< T, N > &arr) -> decltype(array_reduce< product_op, T, N >(arr, static_cast< T >(1)))
bool equal_strict(const double &x, const double &y)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
std::ostream & operator<<(std::ostream &s, const DiagonalBase< Derived > &m)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2)
DenseIndex TotalSize() const
DenseIndex IndexOfRowMajor(const array< DenseIndex, NumDims > &indices) const
DSizes(const array< OtherIndex, NumDims > &other, std::enable_if_t< internal::is_same< DenseIndex, typename internal::promote_index_type< DenseIndex, OtherIndex >::type >::value, void * >=0)
DSizes(const Eigen::IndexList< FirstType, OtherTypes... > &dimensions)
DSizes(const array< DenseIndex, NumDims > &a)
DSizes(const DimensionList< DenseIndex, NumDims > &a)
DSizes & operator=(const array< DenseIndex, NumDims > &other)
DSizes(DenseIndex firstDimension, DenseIndex secondDimension, IndexTypes... otherDimensions)
DSizes(const DenseIndex i0)
array< DenseIndex, NumDims > Base
DenseIndex IndexOfColMajor(const array< DenseIndex, NumDims > &indices) const
DSizes(const Sizes< Indices... > &a)
static const std::ptrdiff_t total_size
static std::ptrdiff_t TotalSize()
std::ptrdiff_t operator[](const std::ptrdiff_t index) const
ptrdiff_t IndexOfRowMajor(const array< DenseIndex, Base::count > &indices) const
static const ptrdiff_t count
internal::numeric_list< std::ptrdiff_t, Indices... > Base
ptrdiff_t IndexOfColMajor(const array< DenseIndex, Base::count > &indices) const
std::ptrdiff_t rank() const
Sizes(std::initializer_list< std::ptrdiff_t >)
Sizes & operator=(const T &)
Sizes(const array< DenseIndex, Base::count > &)