DASH  0.3.0
dash::ViewSpec< NumDimensions, IndexType > Class Template Reference

Specifies view parameters for implementing submat, rows and cols. More...

#include <Dimensional.h>

Public Types

typedef ViewRegion< NumDimensions, IndexType > region_type
 
typedef ViewRange< IndexType > range_type
 
using index_type = IndexType
 
using size_type = SizeType
 

Public Member Functions

 ViewSpec ()
 Default constructor, initialize with extent and offset 0 in all dimensions. More...
 
 ViewSpec (const std::array< SizeType, NumDimensions > &extents)
 Constructor, initialize with given extents and offset 0 in all dimensions. More...
 
 ViewSpec (const std::array< IndexType, NumDimensions > &offsets, const std::array< SizeType, NumDimensions > &extents)
 Constructor, initialize with given extents and offsets. More...
 
constexpr ViewSpec (const self_t &other)=default
 Copy constructor. More...
 
constexpr ViewSpec (self_t &&other)=default
 Move constructor. More...
 
self_toperator= (const self_t &other)=default
 Assignment operator. More...
 
self_toperator= (self_t &&other)=default
 Move-assignment operator. More...
 
constexpr bool operator== (const self_t &other) const
 Equality comparison operator. More...
 
constexpr bool operator!= (const self_t &other) const
 Equality comparison operator. More...
 
template<typename ... Args>
void resize (SizeType arg, Args... args)
 Change the view specification's extent in every dimension. More...
 
void resize (const std::array< ViewPair_t, NumDimensions > &view)
 Change the view specification's extent and offset in every dimension. More...
 
template<typename SizeType_ >
void resize (const std::array< SizeType_, NumDimensions > &extents)
 Change the view specification's extent in every dimension. More...
 
void resize_dim (dim_t dimension, IndexType offset, SizeType extent)
 Change the view specification's extent and offset in the given dimension. More...
 
ViewSpec< NumDimensions-1, IndexType > slice (dim_t dimension)
 Slice the view in the specified dimension at the given offset. More...
 
void set_rank (dim_t dimensions)
 Set rank of the view spec to a dimensionality between 1 and NumDimensions. More...
 
constexpr SizeType size () const
 
constexpr SizeType size (dim_t dimension) const
 
constexpr const std::array< SizeType, NumDimensions > & extents () const
 
constexpr SizeType extent (dim_t dim) const
 
constexpr const std::array< IndexType, NumDimensions > & offsets () const
 
constexpr range_type range (dim_t dim) const
 
constexpr IndexType offset (dim_t dim) const
 
region_type region () const
 

Static Public Member Functions

static constexpr auto ndim ()
 

Friends

template<dim_t NDim_, typename IndexType_ >
std::ostream & operator<< (std::ostream &os, const ViewSpec< NDim_, IndexType_ > &viewspec)
 

Detailed Description

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
class dash::ViewSpec< NumDimensions, IndexType >

Specifies view parameters for implementing submat, rows and cols.

(DashCartesianSpaceConcept)

Definition at line 430 of file Dimensional.h.

Constructor & Destructor Documentation

◆ ViewSpec() [1/5]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
dash::ViewSpec< NumDimensions, IndexType >::ViewSpec ( )
inline

Default constructor, initialize with extent and offset 0 in all dimensions.

Definition at line 464 of file Dimensional.h.

465  : _size(0),
466  _rank(NumDimensions)
467  {
468  for (dim_t i = 0; i < NumDimensions; i++) {
469  _extents[i] = 0;
470  _offsets[i] = 0;
471  }
472  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ ViewSpec() [2/5]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
dash::ViewSpec< NumDimensions, IndexType >::ViewSpec ( const std::array< SizeType, NumDimensions > &  extents)
inline

Constructor, initialize with given extents and offset 0 in all dimensions.

Definition at line 478 of file Dimensional.h.

480  : _size(1),
481  _rank(NumDimensions),
482  _extents(extents)
483  {
484  for (auto i = 0; i < NumDimensions; ++i) {
485  _offsets[i] = 0;
486  _size *= _extents[i];
487  }
488  }

◆ ViewSpec() [3/5]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
dash::ViewSpec< NumDimensions, IndexType >::ViewSpec ( const std::array< IndexType, NumDimensions > &  offsets,
const std::array< SizeType, NumDimensions > &  extents 
)
inline

Constructor, initialize with given extents and offsets.

Definition at line 493 of file Dimensional.h.

496  : _size(1),
497  _rank(NumDimensions),
498  _extents(extents),
499  _offsets(offsets)
500  {
501  for (auto i = 0; i < NumDimensions; ++i) {
502  _size *= _extents[i];
503  }
504  }

◆ ViewSpec() [4/5]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
constexpr dash::ViewSpec< NumDimensions, IndexType >::ViewSpec ( const self_t other)
default

Copy constructor.

◆ ViewSpec() [5/5]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
constexpr dash::ViewSpec< NumDimensions, IndexType >::ViewSpec ( self_t &&  other)
default

Move constructor.

Member Function Documentation

◆ operator!=()

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
constexpr bool dash::ViewSpec< NumDimensions, IndexType >::operator!= ( const self_t other) const
inline

Equality comparison operator.

Definition at line 541 of file Dimensional.h.

542  {
543  return !(*this == other);
544  }

◆ operator=() [1/2]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
self_t& dash::ViewSpec< NumDimensions, IndexType >::operator= ( const self_t other)
default

Assignment operator.

◆ operator=() [2/2]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
self_t& dash::ViewSpec< NumDimensions, IndexType >::operator= ( self_t &&  other)
default

Move-assignment operator.

◆ operator==()

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
constexpr bool dash::ViewSpec< NumDimensions, IndexType >::operator== ( const self_t other) const
inline

Equality comparison operator.

Definition at line 531 of file Dimensional.h.

532  {
533  return (_extents == other._extents &&
534  _offsets == other._offsets &&
535  _rank == other._rank);
536  }

◆ resize() [1/3]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
template<typename ... Args>
void dash::ViewSpec< NumDimensions, IndexType >::resize ( SizeType  arg,
Args...  args 
)
inline

Change the view specification's extent in every dimension.

Definition at line 550 of file Dimensional.h.

551  {
552  static_assert(
553  sizeof...(Args) == (NumDimensions-1),
554  "Invalid number of arguments");
555  std::array<SizeType, NumDimensions> extents =
556  { arg, (SizeType)(args)... };
557  resize(extents);
558  }
void resize(SizeType arg, Args... args)
Change the view specification&#39;s extent in every dimension.
Definition: Dimensional.h:550

◆ resize() [2/3]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
void dash::ViewSpec< NumDimensions, IndexType >::resize ( const std::array< ViewPair_t, NumDimensions > &  view)
inline

Change the view specification's extent and offset in every dimension.

Definition at line 563 of file Dimensional.h.

564  {
565  _rank = NumDimensions;
566  for (dim_t i = 0; i < NumDimensions; i++) {
567  _offsets[i] = view[i].offset;
568  _extents[i] = view[i].extent;
569  }
570  update_size();
571  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ resize() [3/3]

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
template<typename SizeType_ >
void dash::ViewSpec< NumDimensions, IndexType >::resize ( const std::array< SizeType_, NumDimensions > &  extents)
inline

Change the view specification's extent in every dimension.

Definition at line 577 of file Dimensional.h.

578  {
579  _rank = NumDimensions;
580  for (dim_t i = 0; i < NumDimensions; i++) {
581  _extents[i] = extents[i];
582  }
583  update_size();
584  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ resize_dim()

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
void dash::ViewSpec< NumDimensions, IndexType >::resize_dim ( dim_t  dimension,
IndexType  offset,
SizeType  extent 
)
inline

Change the view specification's extent and offset in the given dimension.

Definition at line 590 of file Dimensional.h.

594  {
595  _offsets[dimension] = offset;
596  _extents[dimension] = extent;
597  update_size();
598  }
constexpr DimensionalType::extent_type extent(dim_t dim, const DimensionalType &d)
Definition: Dimensional.h:82

◆ set_rank()

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
void dash::ViewSpec< NumDimensions, IndexType >::set_rank ( dim_t  dimensions)
inline

Set rank of the view spec to a dimensionality between 1 and NumDimensions.

Definition at line 643 of file Dimensional.h.

644  {
645  DASH_ASSERT_LT(
646  dimensions, NumDimensions+1,
647  "Maximum dimension for ViewSpec::set_rank is " << NumDimensions);
648  _rank = dimensions;
649  update_size();
650  }

◆ slice()

template<dim_t NumDimensions, typename IndexType = dash::default_index_t>
ViewSpec<NumDimensions-1, IndexType> dash::ViewSpec< NumDimensions, IndexType >::slice ( dim_t  dimension)
inline

Slice the view in the specified dimension at the given offset.

This is different from resizing the dimension to extent 1 (resize_dim) which does not affect the view dimensionality or rank. Slicing removes the specified dimension and reduces the view dimensionality by 1.

All dimensions higher than the sliced dimension are projected downwards. Example:

dimensions: 0 1 2 3 : : : : extents: 3 4 5 6 | slice_dim(1, 2) | v dimensions: 0 x 1 2 : : : extents: 3 5 6

Returns
A copy if this view spec as a new instance of ViewSpec<NDim-1> with the sliced dimension removed

Definition at line 627 of file Dimensional.h.

628  {
629  std::array<SizeType, NumDimensions-1> slice_extents;
630  std::array<IndexType, NumDimensions-1> slice_offsets;
631  for (dim_t d = dimension; d < _rank-1; d++) {
632  slice_offsets[d] = _offsets[d+1];
633  slice_extents[d] = _extents[d+1];
634  }
635  return ViewSpec<NumDimensions-1, IndexType>(slice_offsets,
636  slice_extents);
637  }
ViewSpec()
Default constructor, initialize with extent and offset 0 in all dimensions.
Definition: Dimensional.h:464
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

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