atlas
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
atlas::array::ArrayView< Value, Rank > Class Template Reference

Multi-dimensional access to a Array object or Field object. More...

#include <NativeArrayView.h>

Public Types

using value_type = Value
 
using non_const_value_type = typename std::remove_const< Value >::type
 
using data_view_t = gridtools::data_view_tt< Value, Rank, gridtools::get_access_mode< Value >()>
 
using value_type = Value
 
using non_const_value_type = typename std::remove_const< Value >::type
 

Public Member Functions

ATLAS_HOST_DEVICE ArrayView (const ArrayView &other)
 
 ArrayView (const Array &array, bool device_view)
 
 ArrayView (const ArrayView< value_type, Rank > &other)
 
 operator const ArrayView< value_type, Rank > & () const
 
value_type * data ()
 
value_type const * data () const
 
template<typename... Coords, typename = typename std::enable_if<( sizeof...( Coords ) == Rank ), int>::type>
ATLAS_HOST_DEVICE value_type & operator() (Coords... c)
 
template<typename... Coords, typename = typename std::enable_if<( sizeof...( Coords ) == Rank ), int>::type>
ATLAS_HOST_DEVICE value_type const & operator() (Coords... c) const
 
template<typename Int , bool EnableBool = true>
ATLAS_HOST_DEVICE std::enable_if<(Rank==1 &&EnableBool), const value_type & >::type operator[] (Int idx) const
 
template<typename Int , bool EnableBool = true>
ATLAS_HOST_DEVICE std::enable_if<(Rank==1 &&EnableBool), value_type & >::type operator[] (Int idx)
 
template<unsigned int Dim>
ATLAS_HOST_DEVICE idx_t shape () const
 
ATLAS_HOST_DEVICE data_view_t & data_view ()
 
ATLAS_HOST_DEVICE data_view_t const & data_view () const
 
template<unsigned int Dim>
ATLAS_HOST_DEVICE idx_t stride () const
 
size_t size () const
 
bool valid () const
 
bool contiguous () const
 
void dump (std::ostream &os) const
 
ENABLE_IF_NON_CONST void assign (const value_type &value)
 
ENABLE_IF_NON_CONST void assign (const std::initializer_list< value_type > &list)
 
const idx_tstrides () const
 
const idx_tshape () const
 
template<typename Int >
idx_t shape (Int idx) const
 
template<typename Int >
idx_t stride (Int idx) const
 
template<typename... Args>
slice_t< Args... >::type slice (Args... args)
 
template<typename... Args>
const_slice_t< Args... >::type slice (Args... args) const
 
bool isDeviceView () const
 
 ArrayView (const ArrayView &other)
 
 ArrayView (const ArrayView< value_type, Rank > &other)
 
 ArrayView (value_type *data, const ArrayShape &shape, const ArrayStrides &strides)
 
 operator const ArrayView< value_type, Rank > & () const
 
template<typename... Idx>
value_type & operator() (Idx... idx)
 Multidimensional index operator: view(i,j,k,...)
 
template<typename... Ints>
const value_type & operator() (Ints... idx) const
 Multidimensional index operator: view(i,j,k,...)
 
template<typename Int , bool EnableBool = true>
std::enable_if<(Rank==1 &&EnableBool), const value_type & >::type operator[] (Int idx) const
 Access to data using square bracket [idx] operator {m-label m-warning} Rank==1. More...
 
template<typename Int , bool EnableBool = true>
std::enable_if<(Rank==1 &&EnableBool), value_type & >::type operator[] (Int idx)
 Access to data using square bracket [idx] operator {m-label m-warning} Rank==1 More...
 
template<unsigned int Dim>
idx_t shape () const
 Return number of values in dimension Dim (template argument) More...
 
template<unsigned int Dim>
idx_t stride () const
 Return stride for values in dimension Dim (template argument)
 
size_t size () const
 Return total number of values (accumulated over all dimensions)
 
const idx_tstrides () const
 
const idx_tshape () const
 
template<typename Int >
idx_t shape (Int idx) const
 Return number of values in dimension idx.
 
template<typename Int >
idx_t stride (Int idx) const
 Return stride for values in dimension idx.
 
value_type const * data () const
 Access to internal data. {m-label m-danger} dangerous
 
value_type * data ()
 Access to internal data. {m-label m-danger} dangerous
 
bool valid () const
 
bool contiguous () const
 Return true when all values are contiguous in memory. More...
 
ENABLE_IF_NON_CONST void assign (const value_type &value)
 
ENABLE_IF_NON_CONST void assign (const std::initializer_list< value_type > &list)
 
void dump (std::ostream &os) const
 
template<typename... Args>
slice_t< Args... >::type slice (Args... args)
 Obtain a slice from this view: view.slice( Range, Range, ... More...
 
template<typename... Args>
const_slice_t< Args... >::type slice (Args... args) const
 Obtain a slice from this view: view.slice( Range, Range, ... )
 

Static Public Member Functions

static constexpr idx_t rank ()
 
static constexpr idx_t rank ()
 Return the number of dimensions.
 

Static Public Attributes

static constexpr bool is_const = std::is_const<Value>::value
 
static constexpr bool is_non_const = !std::is_const<Value>::value
 
static constexpr int RANK {Rank}
 

Friends

template<typename friendValue , int friendRank>
class ArrayView
 

Detailed Description

template<typename Value, int Rank>
class atlas::array::ArrayView< Value, Rank >

Multi-dimensional access to a Array object or Field object.

An ArrayView enables access to the inner data-memory-storage of the Array. It is required to create the view using the make_view helper functions.

Example 1:

auto view = make_view<double,2>( Array );
double sum = 0;
for( idx_t i=0; i<view.shape(0); ++i ) {
for( idx_t j=0; j<view.shape(1); ++j ) {
sum += view(i,j);
}
}

Data storage

Depending on whether atlas was compiled with the Feature GRIDTOOLS_STORAGE, the internal data allocation of the Array object is managed by GridTools (ATLAS_HAVE_GRIDTOOLS==1) or by Atlas itself (ATLAS_HAVE_GRIDTOOLS==0).

The ArrayView class is therefore also compiled differently dependening on this feature.

Member Function Documentation

◆ contiguous()

template<typename Value, int Rank>
bool atlas::array::ArrayView< Value, Rank >::contiguous ( ) const
inline

Return true when all values are contiguous in memory.

This means that if there is e.g. padding in the fastest dimension, or if the ArrayView represents a slice, the returned value will be false.

◆ operator[]() [1/2]

template<typename Value, int Rank>
template<typename Int , bool EnableBool = true>
std::enable_if<( Rank == 1 && EnableBool ), const value_type&>::type atlas::array::ArrayView< Value, Rank >::operator[] ( Int  idx) const
inline

Access to data using square bracket [idx] operator {m-label m-warning} Rank==1.

Note that this function is only present when Rank == 1

◆ operator[]() [2/2]

template<typename Value, int Rank>
template<typename Int , bool EnableBool = true>
std::enable_if<( Rank == 1 && EnableBool ), value_type&>::type atlas::array::ArrayView< Value, Rank >::operator[] ( Int  idx)
inline

Access to data using square bracket [idx] operator {m-label m-warning} Rank==1

Note that this function is only present when Rank == 1

◆ shape()

template<typename Value, int Rank>
template<unsigned int Dim>
idx_t atlas::array::ArrayView< Value, Rank >::shape ( ) const
inline

Return number of values in dimension Dim (template argument)

Example use:

for( idx_t i=0; i<view.shape<0>(); ++i ) {
for( idx_t j=0; j<view.shape<1>(); +j ) {
...
}
}

◆ slice()

template<typename Value, int Rank>
template<typename... Args>
slice_t<Args...>::type atlas::array::ArrayView< Value, Rank >::slice ( Args...  args)
inline

Obtain a slice from this view: view.slice( Range, Range, ...

)

The return type of this function is intentionally auto and is guaranteed to have the same API as ArrayView, but is not necessarily this type.

If the current view has Rank == 2, a Rank == 1 slice can be created in several ways:

auto slice1 = view.slice( Range(0,2), Range::all() );
auto slice2 = view.slice( Range::To(2), Range::all() );

Sometimes it may be required to extend the rank of the current view to cater for certain algorithms requiring an extra rank.

auto slice3 = view.slice( Range::all(), Range::all(), Range::dummy() );

The documentation for this class was generated from the following files: