class nbla::NdArray

class NdArray : public nbla::BaseNdArray, public std::enable_shared_from_this<NdArray>

Dtype and backend agnostic multi-dimensional array.Shared pointer of NdArray.

Public Functions

NBLA_API NdArray(const Shape_t &shape = {})

Ctor given shape.

Create an SyncedArray instance with corresponding size.

Parameters:

shape[in] Shape of creating array.

NBLA_API NdArray(SyncedArrayPtr array, const Shape_t &shape = {})

Ctor given previously created SyncedArray and shape.

Parameters:
NBLA_API void reshape (const Shape_t &shape, bool force=false)

Reshape.

Parameters:
  • shape[in] N-d array will be reshaped to this shape.

  • force[in] If total size doesn’t match and true is given, array will reset to total size, which means the content of array will become totally different one.

NBLA_API Ptr view (const Shape_t &shape)

Create an another instance with different shape but sharing array content.

Parameters:

shape[in] N-d array reshaped to.

NBLA_API Shape_t shape () const

Get shape.

NBLA_API Shape_t strides () const

Get strides.

NBLA_API Size_t size (Size_t axis=-1) const

Get total size (product of shape array).

Parameters:

axis – Size followed by given axis is computed.

NBLA_API Size_t ndim () const

Get number of dimensions.

NBLA_API void zero ()

Set all value to zero.

Note

This will be lazily evaluated when data is used.

NBLA_API void fill (double v)

Set all value to given value.

Note

This will be lazily evaluated when data is used.

Parameters:

value[in] Value array filled with.

NBLA_API const Array * get (dtypes dtype, const Context &ctx)

Get const array with specified dtype and backend description.

Parameters:
  • dtype[in] Enum of data type.

  • ctx[in] Descriptor of array backend.

NBLA_API shared_ptr< const Array > get_sp (dtypes dtype, const Context &ctx)

Get const array as a shared_ptr.

See also

get

NBLA_API unsigned long data_ptr (dtypes dtype, const Context &ctx, bool write_only=false)

Get array’s ptr.

Parameters:
  • dtype[in] Enum of data type.

  • ctx[in] Descriptor of array backend.

  • write_only[in] No synchronization happens.

NBLA_API Array * cast (dtypes dtype, const Context &ctx, bool write_only=false)

Get mutable array with specified dtype and backend description.

Parameters:
  • dtype[in] Enum of data type.

  • ctx[in] Descriptor of array backend.

  • write_only[in] No synchronization happens.

NBLA_API shared_ptr< Array > cast_sp (dtypes dtype, const Context &ctx, bool write_only=false)

Get a mutable array as a shared_ptr.

See also

cast

NBLA_API Ptr narrow (const Size_t dim, const Size_t start, const Size_t length)

Returns a new array that is a narrowed part of this array.

The narrowed part is specified by the slice of this array from `start` to `start` + `length` along the dimension `dim`. The returned array and this array share the same underlying allocated memory.

Parameters:
  • dim[in] Dimension along which to narrow. Currently, only 0 can be specified.

  • start[in] Starting index in specified dimension.

  • length[in] Distance to the ending index from `start`.

Public Static Functions

template<typename ...Args>
static inline Ptr create(Args... args)

Create a shared_ptr instance of NdArray.