Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

n_index_t

Variadic template class n_index_t describes a position inside of the N-dimensional container. Specifically, the number of dimensions and the of index value of each.

Syntax

template<typename... TypeListT>
class n_index_t

Description

n_index_t represents a position inside an n-dimensional space as a sequence of index value for each dimension. The index of each dimension can be represented by different types. This flexibility allows the same interface to be used to declare n_index_t with indices that are fully known at compile time with fixed<int NumberT>, or to be only known at runtime with int, or only known at runtime but with a guarantee will be a multiple of an alignment with aligned<int Alignment>. For more details, see the Number representation section.

Objects of this class may be used to identify a cell in a container, describe the inclusive lower bounds for n_bounds(), n-dimensional position for accessor's translated_to().

The following table provides information about the template arguments for n_index_t.

Template Argument

Description

typename... TypeListT

Comma separated list of types, where the number of types provided controls how many dimensions there are. Each type in the list identifies how the index of the corresponding dimension is to be represented. The order of the dimensions is the same order as C++ subscripts declaring a multi-dimensional array, from leftmost to rightmost.

Requirements: Type must be int, or fixed<NumberT>, or aligned<AlignmentT>.

The following table provides information about the members of n_index_t

Member

Description

static constexpr int rank;

Number of dimensions.

static constexpr int row_dimension = rank-1;
Index of last dimension, row.
n_index_t()

Default constructor. Uses default values for extent types.

Requirements: Every type in TypeListT is default constructible.

Effects: Construct n_index_t, uses default values of each type in TypeListT for the dimesnion sizes. In general only correctly initialized when every type is a fixed<NumberT>.

n_index_t(const n_extent_t &a_other)

Copy constructor.

Effects: Construct n_index_t, copying index value of each dimension from a_other.

explicit n_index_t(const TypeListT & … a_values)

Returns: The last extent in its native type

Effects: Construct n_index_t, initializing each dimension with the corresponding value from the list of a_values passed as an argument. In use, a_values is a comma separate list of values whose length and types are defined by TypeListT.

template<int DimensionT> 
auto get() const

Requirements: DimenstionT >=0 and DimensiontT < rank.

Effects: Determine the index value of DimensionT.

Returns: In the type declared by the DimensionT position of 0-based TypeListT, the index value of the specified DimensionT

n_index_t operator +() const

Effects: Determine the positive unary value of each dimension's index, effectively no operation is performed

Returns: Copy of the current instance.

auto operator -() const

Effects: Determine the negative unary value of each dimension's index

Returns: n_index[-get<0>()]

[-get<1>()]

[-get<…>()]

[-get<row_dimension>()]

template<class... OtherTypeListT>
auto operator +(
   const n_index_t<OtherTypeListT...> & a_other) const

Requirements: Rank of a_other is the same as this instance's.

Effects: Build n_index_t whose values are the result of adding the index value for each dimension with those of a_other

Returns: n_index[get<0>() + a_other.get<0>()]

[get<1>() + a_other.get<1>()]

[get<…>() + a_other.get<…>()]

[get<row_dimension>() +

a_other.get<row_dimension>()]

template<class... OtherTypeListT>
auto operator -(
   const n_index_t<OtherTypeListT...> & a_other) const

Requirements: Rank of a_other is the same as this instance's.

Effects: Build n_index_t whose values are the result of subtracting the index value for each dimension of a_other with this instance's.

Returns: n_index[get<0>() - a_other.get<0>()]

[get<1>() - a_other.get<1>()]

[get<…>() - a_other.get<…>()]

[get<row_dimension>() -

a_other.get<row_dimension>()]

template<class... OtherTypeListT>
bool operator == (const n_index_t<OtherTypeListT...> a_other) const

Requirements: Rank of a_other is the same as this instance's.

Effects: Compare index of each dimension for equality. Only compares numeric values, not the types of each dimension.

Returns:true if all dimensions are numerically equal, false otherwise.

template<class... OtherTypeListT>
bool operator != (const n_index_t<OtherTypeListT...> a_other) const

Requirements: Rank of a_other is the same as this instance's.

Effects: Compare index of each dimension for inequality. Only compares numeric values, not the types of each dimension.

Returns: true if any dimensions are numerically different, false otherwise.

template<int DimensionT> 
auto rightmost_dimensions() const

Requirements: DimenstionT >=0 and DimensiontT <= rank.

Effects: Construct a n_index_t with a lower rank by copying the righmost DimensionT values from this instance.

Returns: n_index[get<rank - DimensionT>()]

[get<rank + 1 - DimensionT>()]

[get<…>()]

[get<row_dimension>()]

template<class... OtherTypeListT>
auto overlay_rightmost(const n_index_t<OtherTypeListT...> & a_other) const

Requirements: rank of a_other is <= rank

Effects: Construct copy of n_index_t where the rightmost dimensions' values are copied from a_other, effectively overlaying a_other ontop of rightmost dimensions of this instance.

Returns: n_index[get<0>()]

[get<1 >()]

[get<…>()]

[get<rank-a_other::rank>()]

[a_other.get<0>()]

[a_other.get<…>()]

[a_other.get<a_other::row_dimension>()]

The following table provides information about the friend functions of n_index_t

Friend Function Description
std::ostream& operator << (std::ostream& output_stream, const n_index_t & a_indices)

Effects: Append string representation of a_indices' values to a_output_stream.

Returns: Reference to a_output_stream for chained calls.