| 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 |
#include <iostream> |
| 12 |
|
| 13 |
#include "atlas/array/native/NativeIndexView.h" |
| 14 |
#include "atlas/array/helpers/ArrayAssigner.h" |
| 15 |
|
| 16 |
//------------------------------------------------------------------------------------------------------ |
| 17 |
|
| 18 |
namespace atlas { |
| 19 |
namespace array { |
| 20 |
|
| 21 |
#undef ENABLE_IF_NON_CONST |
| 22 |
#define ENABLE_IF_NON_CONST \ |
| 23 |
template <bool EnableBool, typename std::enable_if<(!std::is_const<Value>::value && EnableBool), int>::type*> |
| 24 |
|
| 25 |
//------------------------------------------------------------------------------------------------------ |
| 26 |
|
| 27 |
template <typename Value, int Rank> |
| 28 |
IndexView<Value, Rank>::IndexView(Value* data, const idx_t shape[Rank]): data_(data) { |
| 29 |
static_assert(Rank == 1); |
| 30 |
strides_[0] = 1; |
| 31 |
shape_[0] = shape[0]; |
| 32 |
} |
| 33 |
|
| 34 |
template <typename Value, int Rank> |
| 35 |
IndexView<Value, Rank>::IndexView(Value* data, const idx_t shape[Rank], const idx_t strides[Rank]): |
| 36 |
data_(const_cast<Value*>(data)) { |
| 37 |
static_assert(Rank == 1); |
| 38 |
strides_[0] = strides[0]; |
| 39 |
shape_[0] = shape[0]; |
| 40 |
} |
| 41 |
|
| 42 |
template <typename Value, int Rank> |
| 43 |
void IndexView<Value, Rank>::dump(std::ostream& os) const { |
| 44 |
os << "size: " << size() << " , values: "; |
| 45 |
os << "[ "; |
| 46 |
for (idx_t j = 0; j < size(); ++j) { |
| 47 |
os << (*this)(j) << " "; |
| 48 |
} |
| 49 |
os << "]" << std::endl; |
| 50 |
} |
| 51 |
|
| 52 |
template <typename Value, int Rank> |
| 53 |
ENABLE_IF_NON_CONST void IndexView<Value, Rank>::assign(const std::initializer_list<value_type>& list) { |
| 54 |
helpers::array_assigner<Value, Rank>::apply(*this, list); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
//------------------------------------------------------------------------------------------------------ |
| 59 |
// Explicit template instatiation |
| 60 |
|
| 61 |
#define EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(TYPE, RANK) \ |
| 62 |
template class IndexView<TYPE, RANK>; \ |
| 63 |
template class IndexView<const TYPE, RANK>; \ |
| 64 |
template void IndexView<TYPE, RANK>::assign<true, nullptr>(std::initializer_list<TYPE> const&); |
| 65 |
|
| 66 |
|
| 67 |
#define EXPLICIT_TEMPLATE_INSTANTIATION(RANK) \ |
| 68 |
EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(int, RANK) \ |
| 69 |
EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(long, RANK) |
| 70 |
|
| 71 |
EXPLICIT_TEMPLATE_INSTANTIATION(1) |
| 72 |
// EXPLICIT_TEMPLATE_INSTANTIATION(2) |
| 73 |
|
| 74 |
#undef EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK |
| 75 |
#undef EXPLICIT_TEMPLATE_INSTANTIATION |
| 76 |
|
| 77 |
//------------------------------------------------------------------------------------------------------ |
| 78 |
|
| 79 |
} // namespace array |
| 80 |
} // namespace atlas |