| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
#pragma once |
| 11 |
|
| 12 |
#include "atlas/array/ArrayView.h" |
| 13 |
|
| 14 |
namespace atlas { |
| 15 |
namespace array { |
| 16 |
|
| 17 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 18 |
template <int cnt, int DimSkip, typename DATA_TYPE, int RANK> |
| 19 |
constexpr typename std::enable_if<(cnt == RANK), idx_t>::type get_var_size_impl( |
| 20 |
array::ArrayView<DATA_TYPE, RANK>& field) { |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
template <int cnt, int DimSkip, typename DATA_TYPE, int RANK> |
| 25 |
constexpr typename std::enable_if<(cnt != RANK), idx_t>::type get_var_size_impl( |
| 26 |
array::ArrayView<DATA_TYPE, RANK>& field) { |
| 27 |
return (cnt == DimSkip) ? get_var_size_impl<cnt + 1, DimSkip>(field) |
| 28 |
: get_var_size_impl<cnt + 1, DimSkip>(field) * field.template shape<cnt>(); |
| 29 |
} |
| 30 |
|
| 31 |
template <int DimSkip, typename DATA_TYPE, int RANK> |
| 32 |
constexpr idx_t get_var_size(array::ArrayView<DATA_TYPE, RANK>& field) { |
| 33 |
return get_var_size_impl<0, DimSkip>(field); |
| 34 |
} |
| 35 |
|
| 36 |
template <typename DimPolicy> |
| 37 |
struct get_dim { |
| 38 |
static constexpr int value = -1; |
| 39 |
}; |
| 40 |
|
| 41 |
template <int cDim> |
| 42 |
struct get_dim<Dim<cDim>> { |
| 43 |
static constexpr int value = cDim; |
| 44 |
}; |
| 45 |
|
| 46 |
template <typename DimPolicy, typename DATA_TYPE, int RANK> |
| 47 |
constexpr unsigned int get_parallel_dim(array::ArrayView<DATA_TYPE, RANK>& field) { |
| 48 |
static_assert(is_dim_policy<DimPolicy>::value, "DimPolicy required"); |
| 49 |
return std::is_same<DimPolicy, FirstDim>::value |
| 50 |
? 0 |
| 51 |
: (std::is_same<DimPolicy, LastDim>::value ? RANK - 1 : (get_dim<DimPolicy>::value)); |
| 52 |
} |
| 53 |
#endif |
| 54 |
|
| 55 |
} // namespace array |
| 56 |
} // namespace atlas |