Unlock this feature

This feature isn’t part of your plan yet

Contact sales to get upgraded to the full DevStudio experience.

Unlock this feature

This feature isn't part of your plan yet.

N-Dimensional Arrays

Using memory constructs from the C++ Standard Template Library (STL) in a Chimera Compute Library (CCL) development context is generally not supported or recommended.

In some cases, std::array may work, but it is highly recommend that developers attempt to use CCL-defined constructs, such as NDArray, when possible.

NDArray Type

NDArray is an address-space agnostic, fixed-size, aggregate type designed for use in a CCL development context in an embedded environment without support for the C++ Standard Template Library (STL). It is intended to be used in place of std::array objects.

It also has experimental support for multi-dimensional representations and indexing, but usage of these features is not encourage at this time.

NDArray is not inherently a Processing Element (PE) or IMD construct. An NDArray wraps a C-style array of elements, which can be classified as either [PE] or [IMD] to specify the intended usage. Usage of elements within the array will follow same rules as other [PE] and [IMD] types.

NDArraystruct
File: /src/core/types/ct_containers.hppLines 109–479

An address-space agnostic, fixed-size, aggregate type designed for use in a CCL development context in an embedded environment without support for the C++ Standard Template Library (STL).

It is intended to be used in place of std::array objects.

NameTypeDefaultDescription
TtypenameType of elements that make up the NDArray.

Public Members

Raw linear array of items of type T and of size linearElementCount matching the volume of the N-dimension array, i.e. dimN * ... * dim1 * dim0.

data
File: /src/core/types/ct_containers.hppLine 220

Linear storage for every element of the NDArray, in row-major order.

T data[linearElementCount] ;

Utility Methods

sizefunction
File: /src/core/types/ct_containers.hppLine 393

Get the size of the NDArray (which is the size of its leftmost dimension)

static constexpr std::size_t size()

static constexpr std::size_t — std::size_t The size of the NDArray.

maxSizefunction
File: /src/core/types/ct_containers.hppLine 398

Get the capacity of the NDArray, which equals its size (fixed-size container).

static constexpr std::size_t maxSize()

static constexpr std::size_t

Element Getter & Setter Methods

The overload of the [] operator is designed to act like raw multidimensional C arrays in row-major order.

When the defined NDArrayis one-dimensional, i.e. sizeof...(dimensions) == 1, the [] operator returns a reference to the element at the index provided.

When the defined NDArrayis multidimensional, i.e. sizeof...(dimensions) > 1, the [] operator returns a reference to the element N * dimN-1 * ... * dim0cast as a type of NDArray<T, dimN-1, ..., dim0>.

operator[]function
File: /src/core/types/ct_containers.hppLine 229

Access the element of the NDArray at a certain position

NextDimType & operator[](std::size_t index) operator[](index)
NameTypeDescription
indexthe position that will be accessed within the NDArray

NextDimType & operator[](std::size_t index) — NextDimType& the element at that position

slicefunction
File: /src/core/types/ct_containers.hppLines 375–385

Slices an NDArray into a sub-NDArray when given an outerDim (i.e. length of the slice) and an offsetIndex (i.e the starting index of the slice). Throws errors when the slice would go out of bounds.

template <std::size_t outerDim>
typename SlicedNDArray<outerDim, dimensions...>::type & slice(qVar_t<std::size_t> offsetIndex) slice(offsetIndex)
NameTypeDefaultDescription
outerDimstd::size_tthe length of the outer dimension of the NDArray included in the slice
NameTypeDescription
offsetIndexthe first index that the slice begins (offset from the beginning of the NDArray)

typename SlicedNDArray<outerDim, dimensions...>::type & slice(qVar_t<std::size_t> offsetIndex) — a NDArray containing the slice

fillfunction
File: /src/core/types/ct_containers.hppLines 406–410

Fills all elements of the NDArray with a certain value

constexpr void fill(const Tbase& val)
NameTypeDescription
valconst Tbase&the value that we are filling the NDArray with

constexpr void

fillfunction
File: /src/core/types/ct_containers.hppLines 406–410

Fills all elements of the NDArray with a certain value

constexpr void fill(const Tbase& val)
NameTypeDescription
valconst Tbase&the value that we are filling the NDArray with

constexpr void

intofunction
File: /src/core/types/ct_containers.hppLines 335–349

Copies over all values from the current ND Array into a new ND Array with different dimensions and different types. Note that the values are assigned into the new ND Array, so behavior is different than asCast(). The new dimensions must contain the same number of elements as the dimensions of the current ND Array.

template <typename TNew, std::enable_if_t<(sizeof...(dims) > 0), int> = 0>
NDArray<TNew, dims...> into()
NameTypeDefaultDescription
TNewtypenamethe new type for the returned ND Array

NDArray<TNew, dims...> — a new ND Array with values copied over from the current ND Array with different dimensions and a different type

Reshape Methods

All of these operations are only useful for multi-dimensional arrays and are considered experimental.

flattenCastfunction
File: /src/core/types/ct_containers.hppLines 244–249

Flattens the current ND Array by returning a 1D NDArray that contains all tiles. A static_assert verifies that flattening is possible.

FlatCastType & flattenCast() flattenCast()

FlatCastType & flattenCast() — a new 1D NDArray containing all tiles

Returns a reference to the array, cast to a different shape with the same number of elements as the original array. TCast may also be provided as an explicit reinterpretation to another data type, in which the number of elements is proportional to the difference in element sizes. In other words, the resulting cast will represent the exact same memory size.

reshapeCastfunction
File: /src/core/types/ct_containers.hppLines 260–268

Reshapes the current ND Array given a set of dimensions. If this reshaping is not possible, raise an error.

template <newDims>
NDArray<T, newDims...> & reshapeCast() reshapeCast()
NameTypeDefaultDescription
newDimsthe dimensions of the reshaped ND Array

NDArray<T, newDims...> & reshapeCast() — a ND Array reshaped to the parameters needs

intofunction
File: /src/core/types/ct_containers.hppLines 335–349

Copies over all values from the current ND Array into a new ND Array with different dimensions and different types. Note that the values are assigned into the new ND Array, so behavior is different than asCast(). The new dimensions must contain the same number of elements as the dimensions of the current ND Array.

template <typename TNew, std::enable_if_t<(sizeof...(dims) > 0), int> = 0>
NDArray<TNew, dims...> into()
NameTypeDefaultDescription
TNewtypenamethe new type for the returned ND Array

NDArray<TNew, dims...> — a new ND Array with values copied over from the current ND Array with different dimensions and a different type

Data Type Casting Methods

reinterpretCastfunction
File: /src/core/types/ct_containers.hppLines 298–303

Reinterperet casts the current ND Array to a new ND Array containing a different type, possibly with different size. Note that this type conversion is a reinterpretation of the underlying bit pattern. Thus, the size of the new ND Array must match the size of the old ND Array.

template <typename TAs, std::enable_if_t<sizeof...(newDims) != 0, std::int32_t> = 0>
NDArray<TAs, newDims...> & reinterpretCast() reinterpretCast()
NameTypeDefaultDescription
TAstypenamethe new type of the returned ND Array

NDArray<TAs, newDims...> & reinterpretCast() — a ND Array reinterpreted to a new type

reinterpretCastfunction
File: /src/core/types/ct_containers.hppLines 314–320

Reinterpret casts the current ND Array to a new ND Array containing a different type. This overload is for the use case where we don't have manual output dimension specification (i.e. we keep the same dimensions), we require that the new type is the same width as the old type.

template <typename TAs>
NDArray<TAs, dimensions...> & reinterpretCast() reinterpretCast()
NameTypeDefaultDescription
TAstypenamethe new type of the returned ND Array

NDArray<TAs, dimensions...> & reinterpretCast() — an ND Array reinterpreted to a new type

Examples

File: /tests/sweep_tests/ndarray_reinterpret_cast/sweep_ndarray_reinterpret_cast.cpp
  container::NDArray<qVar_t<sweeps::InType>, dim1 * dim2 * dim3 * dim4> arr = readFlow.read();

  // reshape input 1d NDArray to 4d NDArray.
  auto reshaped = arr.reshapeCast<dim1, dim2, dim3, dim4>();
intofunction
File: /src/core/types/ct_containers.hppLines 335–349

Copies over all values from the current ND Array into a new ND Array with different dimensions and different types. Note that the values are assigned into the new ND Array, so behavior is different than asCast(). The new dimensions must contain the same number of elements as the dimensions of the current ND Array.

template <typename TNew, std::enable_if_t<(sizeof...(dims) > 0), int> = 0>
NDArray<TNew, dims...> into()
NameTypeDefaultDescription
TNewtypenamethe new type for the returned ND Array

NDArray<TNew, dims...> — a new ND Array with values copied over from the current ND Array with different dimensions and a different type

Sign in to your account

Don't have an account? 
By signing in, you are agreeing to our Terms of Use and Privacy Policy.
Quadric // One architecture. Every algorithm.

Develop.

Simulate.

Profile.

Collaborate.