| 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 <vector> |
| 15 |
#include <string_view> |
| 16 |
#include <string> |
| 17 |
|
| 18 |
#include "atlas/array/ArrayIdx.h" |
| 19 |
#include "atlas/array/ArrayLayout.h" |
| 20 |
#include "atlas/array/ArrayShape.h" |
| 21 |
#include "atlas/array/ArrayStrides.h" |
| 22 |
#include "atlas/array/DataType.h" |
| 23 |
#include "atlas/library/config.h" |
| 24 |
|
| 25 |
//------------------------------------------------------------------------------------------------------ |
| 26 |
|
| 27 |
namespace atlas { |
| 28 |
namespace array { |
| 29 |
|
| 30 |
class ArraySpec { |
| 31 |
private: |
| 32 |
size_t size_; |
| 33 |
idx_t rank_; |
| 34 |
size_t allocated_size_; |
| 35 |
DataType datatype_; |
| 36 |
ArrayShape shape_; |
| 37 |
ArrayStrides strides_; |
| 38 |
ArrayStrides device_strides_; |
| 39 |
ArrayLayout layout_; |
| 40 |
ArrayAlignment alignment_; |
| 41 |
std::vector<int> shapef_; |
| 42 |
std::vector<int> stridesf_; |
| 43 |
std::vector<int> device_stridesf_; |
| 44 |
bool contiguous_; |
| 45 |
bool default_layout_; |
| 46 |
|
| 47 |
public: |
| 48 |
ArraySpec(); |
| 49 |
ArraySpec(const ArrayShape&); |
| 50 |
ArraySpec(const ArrayShape&, const ArrayStrides&); |
| 51 |
ArraySpec(const ArrayShape&, const ArrayStrides&, const ArrayLayout&); |
| 52 |
ArraySpec(const ArrayShape&, const ArrayAlignment&); |
| 53 |
ArraySpec(const ArrayShape&, const ArrayStrides&, const ArrayAlignment&); |
| 54 |
ArraySpec(const ArrayShape&, const ArrayStrides&, const ArrayLayout&, const ArrayAlignment&); |
| 55 |
ArraySpec(DataType, const ArrayShape&); |
| 56 |
ArraySpec(DataType, const ArrayShape&, const ArrayStrides&); |
| 57 |
ArraySpec(DataType, const ArrayShape&, const ArrayStrides&, const ArrayLayout&); |
| 58 |
ArraySpec(DataType, const ArrayShape&, const ArrayAlignment&); |
| 59 |
ArraySpec(DataType, const ArrayShape&, const ArrayStrides&, const ArrayAlignment&); |
| 60 |
ArraySpec(DataType, const ArrayShape&, const ArrayStrides&, const ArrayLayout&, const ArrayAlignment&); |
| 61 |
size_t allocatedSize() const { return allocated_size_; } |
| 62 |
size_t size() const { return size_; } |
| 63 |
idx_t rank() const { return rank_; } |
| 64 |
DataType datatype() const { return datatype_; } |
| 65 |
const ArrayShape& shape() const { return shape_; } |
| 66 |
const ArrayAlignment& alignment() const { return alignment_; } |
| 67 |
const ArrayStrides& strides() const { return strides_; } |
| 68 |
const ArrayStrides& device_strides() const { return device_strides_; } |
| 69 |
const ArrayLayout& layout() const { return layout_; } |
| 70 |
const std::vector<int>& shapef() const; |
| 71 |
const std::vector<int>& stridesf() const; |
| 72 |
const std::vector<int>& device_stridesf() const; |
| 73 |
bool contiguous() const { return contiguous_; } |
| 74 |
bool hasDefaultLayout() const { return default_layout_; } |
| 75 |
|
| 76 |
private: |
| 77 |
void allocate_fortran_specs(); |
| 78 |
}; |
| 79 |
|
| 80 |
// -------------------------------------------------------------------------------------------- |
| 81 |
|
| 82 |
class label { |
| 83 |
public: |
| 84 |
label(std::string_view s) { |
| 85 |
previous_ = get(); |
| 86 |
set(s); |
| 87 |
} |
| 88 |
~label() { |
| 89 |
set(previous_); |
| 90 |
} |
| 91 |
static std::string_view get(); |
| 92 |
static void set(std::string_view); |
| 93 |
private: |
| 94 |
std::string previous_; |
| 95 |
}; |
| 96 |
|
| 97 |
//------------------------------------------------------------------------------------------------------ |
| 98 |
|
| 99 |
} // namespace array |
| 100 |
} // namespace atlas |