atlas
|
This file contains the ArrayView class, a class that allows to wrap any contiguous raw data into a view which is accessible with multiple indices. More...
#include "atlas/library/config.h"
#include "atlas/array/native/NativeArrayView.h"
Go to the source code of this file.
Namespaces | |
atlas | |
Contains all atlas classes and methods. | |
atlas::array | |
Contains classes to operate with multidimensional arrays. | |
Macros | |
#define | EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK(TYPE, RANK) |
#define | EXPLICIT_TEMPLATE_DECLARATION(RANK) |
This file contains the ArrayView class, a class that allows to wrap any contiguous raw data into a view which is accessible with multiple indices.
All it needs is the strides for each index, and the shape of each index. ATTENTION: The last index is stride 1
Bounds-checking can be turned ON by defining "ATLAS_ARRAYVIEW_BOUNDS_CHECKING" before including this header.
Example 1: int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9}; int[2] strides = { 3, 1 }; int[2] shape = { 3, 3 }; ArrayView<int,2> matrix( array, shape, strides ); for( idx_t i=0; i<matrix.shape(0); ++i ) { for( idx_t j=0; j<matrix.shape(1); ++j ) { matrix(i,j) *= 10; } }
Strides can also be omitted as for most common cases it can be inferred from the shape.
Example 2: int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9}; int[2] shape = { 3, 3 }; ArrayView<int,2> matrix( array, shape ); which is identical for this matrix to previous Example 1
There is also an easier way to wrap Field and Array classes:
Example 3: ArrayView<int,3> fieldview( Field ); ArrayView<int,2> arrayview( Array );
#define EXPLICIT_TEMPLATE_DECLARATION | ( | RANK | ) |
#define EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK | ( | TYPE, | |
RANK | |||
) |