/* * (C) Copyright 2013 ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation * nor does it submit to any jurisdiction. */ #include "LocalView.h" #include #include "atlas/array/helpers/ArrayAssigner.h" #include "atlas/runtime/Exception.h" //------------------------------------------------------------------------------------------------------ namespace atlas { namespace array { //------------------------------------------------------------------------------------------------------ #define ENABLE_IF_NON_CONST \ template ::value && EnableBool), int>::type*> template ENABLE_IF_NON_CONST void LocalView::assign(const Value& value) { helpers::array_assigner::apply(*this, value); } //------------------------------------------------------------------------------------------------------ template void LocalView::dump(std::ostream& os) const { ATLAS_ASSERT(contiguous(), "Cannot dump non-contiguous view"); const value_type* data_ = data(); os << "size: " << size() << " , values: "; os << "[ "; for (idx_t j = 0; j < size(); ++j) { os << data_[j] << " "; } os << "]"; } //------------------------------------------------------------------------------------------------------ #define ENABLE_IF_NOT_CONST typename std::enable_if::value, Value>::type* #define ENABLE_IF_CONST typename std::enable_if::value, Value>::type* template LocalView make_view(Value data[], const ArrayShape& shape) { return LocalView(data, shape); } template LocalView make_view(const Value data[], const ArrayShape& shape) { return LocalView(data, shape); } template LocalView make_view(Value data[], const ArrayShape& shape) { return LocalView(data, shape); } template LocalView make_view(typename std::remove_const::type data[], const ArrayShape& shape) { return LocalView(data, shape); } //------------------------------------------------------------------------------------------------------ template LocalView make_view(Value data[], size_t size) { return LocalView(data, ArrayShape{idx_t(size)}); } template LocalView make_view(const Value data[], size_t size) { return LocalView(data, ArrayShape{idx_t(size)}); } template LocalView make_view(Value data[], size_t size) { return LocalView(data, ArrayShape{idx_t(size)}); } template LocalView make_view(typename std::remove_const::type data[], size_t size) { return LocalView(data, ArrayShape{idx_t(size)}); } //------------------------------------------------------------------------------------------------------ } // namespace array } // namespace atlas //----------------------------------------------------------------------- // Explicit instantiation namespace atlas { namespace array { #undef EXPLICIT_TEMPLATE_INSTANTIATION #define EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(TYPE, RANK) \ template LocalView make_view(TYPE data[], const ArrayShape&); \ template LocalView make_view(TYPE data[], const ArrayShape&); \ template LocalView make_view(const TYPE data[], const ArrayShape&); \ template LocalView make_view(const TYPE data[], const ArrayShape&); \ \ template class LocalView; \ template class LocalView; \ template void LocalView::assign(const TYPE&); #define EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK1(TYPE) \ template LocalView make_view(TYPE data[], size_t); \ template LocalView make_view(TYPE data[], size_t); \ template LocalView make_view(const TYPE data[], size_t); \ template LocalView make_view(const TYPE data[], size_t); #define EXPLICIT_TEMPLATE_INSTANTIATION(RANK) \ EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(int, RANK) \ EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(long, RANK) \ EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(long long, RANK) \ EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(float, RANK) \ EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK(double, RANK) // For each RANK in [1..9] EXPLICIT_TEMPLATE_INSTANTIATION(1) EXPLICIT_TEMPLATE_INSTANTIATION(2) EXPLICIT_TEMPLATE_INSTANTIATION(3) EXPLICIT_TEMPLATE_INSTANTIATION(4) EXPLICIT_TEMPLATE_INSTANTIATION(5) EXPLICIT_TEMPLATE_INSTANTIATION(6) EXPLICIT_TEMPLATE_INSTANTIATION(7) EXPLICIT_TEMPLATE_INSTANTIATION(8) EXPLICIT_TEMPLATE_INSTANTIATION(9) EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK1(int) EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK1(long) EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK1(long long) EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK1(float) EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK1(double) #undef EXPLICIT_TEMPLATE_INSTANTIATION } // namespace array } // namespace atlas