atlas
ArrayStrides.h
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 <initializer_list>
15 #include <vector>
16 #include "atlas/library/config.h"
17 
18 //------------------------------------------------------------------------------------------------------
19 
20 namespace atlas {
21 namespace array {
22 
23 class ArrayStrides : public std::vector<idx_t> {
24 private:
25  using Base = std::vector<idx_t>;
26 
27 public:
28  ArrayStrides() {}
29  ArrayStrides( std::initializer_list<idx_t> list ) : Base( list ) {}
30  ArrayStrides( Base&& base ) : Base( std::forward<Base>( base ) ) {}
31 };
32 
33 namespace detail {
34 
35 template <typename Int>
36 inline ArrayStrides make_strides( Int size1 ) {
37  return ArrayStrides{static_cast<idx_t>( size1 )};
38 }
39 template <typename Int1, typename Int2>
40 inline ArrayStrides make_strides( Int1 size1, Int2 size2 ) {
41  return ArrayStrides{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 )};
42 }
43 template <typename Int1, typename Int2, typename Int3>
44 inline ArrayStrides make_strides( Int1 size1, Int2 size2, Int3 size3 ) {
45  return ArrayStrides{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 ), static_cast<idx_t>( size3 )};
46 }
47 template <typename Int1, typename Int2, typename Int3, typename Int4>
48 inline ArrayStrides make_strides( Int1 size1, Int2 size2, Int3 size3, Int4 size4 ) {
49  return ArrayStrides{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 ), static_cast<idx_t>( size3 ),
50  static_cast<idx_t>( size4 )};
51 }
52 template <typename Int1, typename Int2, typename Int3, typename Int4, typename Int5>
53 inline ArrayStrides make_strides( Int1 size1, Int2 size2, Int3 size3, Int4 size4, Int5 size5 ) {
54  return ArrayStrides{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 ), static_cast<idx_t>( size3 ),
55  static_cast<idx_t>( size4 ), static_cast<idx_t>( size5 )};
56 }
57 
58 } // namespace detail
59 
60 inline ArrayStrides make_strides( std::initializer_list<idx_t> sizes ) {
61  return ArrayStrides( sizes );
62 }
63 
64 template <typename... idx_t>
65 ArrayStrides make_strides( idx_t... indices ) {
66  return detail::make_strides( std::forward<idx_t>( indices )... );
67 }
68 
69 
70 //------------------------------------------------------------------------------------------------------
71 
72 } // namespace array
73 } // namespace atlas
Definition: ArrayStrides.h:23
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42