| 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 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <stddef.h> |
| 14 |
#include <utility> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
#include "atlas/library/config.h" |
| 18 |
|
| 19 |
//------------------------------------------------------------------------------------------------------ |
| 20 |
|
| 21 |
|
| 22 |
namespace atlas { |
| 23 |
namespace array { |
| 24 |
|
| 25 |
//using ArrayIdx = std::vector<idx_t>; |
| 26 |
typedef std::vector<idx_t> ArrayIdx; |
| 27 |
|
| 28 |
namespace detail { |
| 29 |
|
| 30 |
inline ArrayIdx make_idx(idx_t size1) { |
| 31 |
return std::vector<idx_t>(1, size1); |
| 32 |
} |
| 33 |
inline ArrayIdx make_idx(idx_t size1, idx_t size2) { |
| 34 |
std::vector<idx_t> v(2); |
| 35 |
v[0] = size1; |
| 36 |
v[1] = size2; |
| 37 |
return v; |
| 38 |
} |
| 39 |
inline ArrayIdx make_idx(idx_t size1, idx_t size2, idx_t size3) { |
| 40 |
std::vector<idx_t> v(3); |
| 41 |
v[0] = size1; |
| 42 |
v[1] = size2; |
| 43 |
v[2] = size3; |
| 44 |
return v; |
| 45 |
} |
| 46 |
inline ArrayIdx make_idx(idx_t size1, idx_t size2, idx_t size3, idx_t size4) { |
| 47 |
std::vector<idx_t> v(4); |
| 48 |
v[0] = size1; |
| 49 |
v[1] = size2; |
| 50 |
v[2] = size3; |
| 51 |
v[3] = size4; |
| 52 |
return v; |
| 53 |
} |
| 54 |
|
| 55 |
} // namespace detail |
| 56 |
|
| 57 |
template <typename... idx_t> |
| 58 |
ArrayIdx make_idx(idx_t... indices) { |
| 59 |
return detail::make_idx(std::forward<idx_t>(indices)...); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
//------------------------------------------------------------------------------------------------------ |
| 64 |
|
| 65 |
} // namespace array |
| 66 |
} // namespace atlas |