Table Of Contents
Table Of Contents

RowSparseNDArray

class mxnet.ndarray.sparse.RowSparseNDArray(handle, writable=True)[source]

A sparse representation of a set of NDArray row slices at given indices.

A RowSparseNDArray represents a multidimensional NDArray using two separate arrays: data and indices. The number of dimensions has to be at least 2.

  • data: an NDArray of any dtype with shape [D0, D1, …, Dn].

  • indices: a 1-D int64 NDArray with shape [D0] with values sorted in ascending order.

The indices stores the indices of the row slices with non-zeros, while the values are stored in data. The corresponding NDArray dense represented by RowSparseNDArray rsp has

dense[rsp.indices[i], :, :, :, ...] = rsp.data[i, :, :, :, ...]

>>> dense.asnumpy()
array([[ 1.,  2., 3.],
       [ 0.,  0., 0.],
       [ 4.,  0., 5.],
       [ 0.,  0., 0.],
       [ 0.,  0., 0.]], dtype=float32)
>>> rsp = dense.tostype('row_sparse')
>>> rsp.indices.asnumpy()
array([0, 2], dtype=int64)
>>> rsp.data.asnumpy()
array([[ 1.,  2., 3.],
       [ 4.,  0., 5.]], dtype=float32)

A RowSparseNDArray is typically used to represent non-zero row slices of a large NDArray of shape [LARGE0, D1, .. , Dn] where LARGE0 >> D0 and most row slices are zeros.

RowSparseNDArray is used principally in the definition of gradients for operations that have sparse gradients (e.g. sparse dot and sparse embedding).

See also

row_sparse_array

Several ways to construct a RowSparseNDArray

Array attributes

RowSparseNDArray.context

Device context of the array.

RowSparseNDArray.data

A deep copy NDArray of the data array of the RowSparseNDArray.

RowSparseNDArray.dtype

Data-type of the array’s elements.

RowSparseNDArray.indices

A deep copy NDArray of the indices array of the RowSparseNDArray.

RowSparseNDArray.shape

Tuple of array dimensions.

RowSparseNDArray.stype

Storage-type of the array.

Array conversion

RowSparseNDArray.as_in_context

Returns an array on the target device with the same value as this array.

RowSparseNDArray.asnumpy

Return a dense numpy.ndarray object with value copied from this array

RowSparseNDArray.asscalar

Returns a scalar whose value is copied from this array.

RowSparseNDArray.astype

Return a copy of the array after casting to a specified type.

RowSparseNDArray.copy

Makes a copy of this NDArray, keeping the same context.

RowSparseNDArray.copyto

Copies the value of this array to another array.

RowSparseNDArray.tostype

Return a copy of the array with chosen storage type.

Array inspection

RowSparseNDArray.check_format

Check whether the NDArray format is valid.

Array creation

RowSparseNDArray.zeros_like

Convenience fluent method for zeros_like().

Array reduction

RowSparseNDArray.norm

Convenience fluent method for norm().

Array rounding

RowSparseNDArray.ceil

Convenience fluent method for ceil().

RowSparseNDArray.fix

Convenience fluent method for fix().

RowSparseNDArray.floor

Convenience fluent method for floor().

RowSparseNDArray.rint

Convenience fluent method for rint().

RowSparseNDArray.round

Convenience fluent method for round().

RowSparseNDArray.trunc

Convenience fluent method for trunc().

Trigonometric functions

RowSparseNDArray.arcsin

Convenience fluent method for arcsin().

RowSparseNDArray.arctan

Convenience fluent method for arctan().

RowSparseNDArray.degrees

Convenience fluent method for degrees().

RowSparseNDArray.radians

Convenience fluent method for radians().

RowSparseNDArray.sin

Convenience fluent method for sin().

RowSparseNDArray.tan

Convenience fluent method for tan().

Hyperbolic functions

RowSparseNDArray.arcsinh

Convenience fluent method for arcsinh().

RowSparseNDArray.arctanh

Convenience fluent method for arctanh().

RowSparseNDArray.sinh

Convenience fluent method for sinh().

RowSparseNDArray.tanh

Convenience fluent method for tanh().

Exponents and logarithms

RowSparseNDArray.expm1

Convenience fluent method for expm1().

RowSparseNDArray.log1p

Convenience fluent method for log1p().

Powers

RowSparseNDArray.sqrt

Convenience fluent method for sqrt().

RowSparseNDArray.square

Convenience fluent method for square().

Indexing

RowSparseNDArray.__getitem__

x.__getitem__(i) <=> x[i]

RowSparseNDArray.__setitem__

x.__setitem__(i, y) <=> x[i]=y

RowSparseNDArray.retain

Convenience fluent method for retain().

Lazy evaluation

RowSparseNDArray.wait_to_read

Waits until all previous write operations on the current array are finished.

Miscellaneous

RowSparseNDArray.abs

Convenience fluent method for abs().

RowSparseNDArray.clip

Convenience fluent method for clip().

RowSparseNDArray.sign

Convenience fluent method for sign().