atlas
ArrayShape.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 <array>
15 #include <vector>
16 #include "atlas/library/config.h"
17 
18 //------------------------------------------------------------------------------------------------------
19 
20 namespace atlas {
21 namespace array {
22 
24 public:
25  ArrayAlignment() : alignment_( 1 ) {}
26  ArrayAlignment( int alignment ) : alignment_( alignment ) {}
27  operator int() const { return alignment_; }
28 
29 private:
30  int alignment_;
31 };
32 
33 class ArrayShape : public std::vector<idx_t> {
34 private:
35  using Base = std::vector<idx_t>;
36 
37 public:
38  ArrayShape() {}
39  ArrayShape( Base&& base ) : Base( std::forward<Base>( base ) ) {}
40  ArrayShape( std::initializer_list<idx_t> list ) : Base( list ) {}
41  template <typename idx_t>
42  ArrayShape( idx_t data[], size_t size ) : Base( data, data + size ) {}
43  template <typename idx_t, std::size_t N>
44  ArrayShape( const std::array<idx_t, N>& list ) : Base( list.begin(), list.end() ) {}
45  template <typename idx_t>
46  ArrayShape( const std::vector<idx_t>& list ) : Base( list.begin(), list.end() ) {}
47 };
48 
49 namespace detail {
50 
51 template <typename Int>
52 inline ArrayShape make_shape( Int size1 ) {
53  return ArrayShape{static_cast<idx_t>( size1 )};
54 }
55 template <typename Int1, typename Int2>
56 inline ArrayShape make_shape( Int1 size1, Int2 size2 ) {
57  return ArrayShape{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 )};
58 }
59 template <typename Int1, typename Int2, typename Int3>
60 inline ArrayShape make_shape( Int1 size1, Int2 size2, Int3 size3 ) {
61  return ArrayShape{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 ), static_cast<idx_t>( size3 )};
62 }
63 template <typename Int1, typename Int2, typename Int3, typename Int4>
64 inline ArrayShape make_shape( Int1 size1, Int2 size2, Int3 size3, Int4 size4 ) {
65  return ArrayShape{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 ), static_cast<idx_t>( size3 ),
66  static_cast<idx_t>( size4 )};
67 }
68 template <typename Int1, typename Int2, typename Int3, typename Int4, typename Int5>
69 inline ArrayShape make_shape( Int1 size1, Int2 size2, Int3 size3, Int4 size4, Int5 size5 ) {
70  return ArrayShape{static_cast<idx_t>( size1 ), static_cast<idx_t>( size2 ), static_cast<idx_t>( size3 ),
71  static_cast<idx_t>( size4 ), static_cast<idx_t>( size5 )};
72 }
73 
74 } // namespace detail
75 
76 
77 inline ArrayShape make_shape( std::initializer_list<idx_t> sizes ) {
78  return ArrayShape( sizes );
79 }
80 
81 template <typename... idx_t>
82 ArrayShape make_shape( idx_t... indices ) {
83  return detail::make_shape( std::forward<idx_t>( indices )... );
84 }
85 
86 
87 //------------------------------------------------------------------------------------------------------
88 
89 } // namespace array
90 } // namespace atlas
Definition: ArrayShape.h:33
Definition: ArrayShape.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