TensorFormat#

class nvmath.sparse.ust.TensorFormat(dimensions, levels, *, name=None)[source]#

A universal sparse tensor format maps dimension specifications (dimensions for short) to level specifications (levels for short).

Parameters:
  • dimensions – a sequence of Dimension objects.

  • levels – an ordered dictionary from a LevelExpr or Dimension object to a LevelFormat, or a (LevelFormat, LevelProperty) pair.

  • name – a name for the format as a string. If the format corresponds to an existing format like CSR, COO, etc. use the canonical name. A name will be generated based on the level specification if none is provided.

Attributes

dimensions#

Get the dimension specifications for this format.

is_identity#

Determine whether the format uses identity mapping between dimensions and levels.

is_ordered#

Determine whether the format is ordered.

is_unique#

Determine whether the format is unique.

levels#

Get the level specifications for this format.

name#

Get the name of the sparse tensor format.

num_dimensions#

Get the number of dimensions (rank of tensor).

num_levels#

Get the number of levels (rank of storage).

Methods

dim2lvl(dim_indices, as_size=False)[source]#

Maps the dimension index list to the level index list.

Examples

CSR: [0,4] -> [0,4] CSC: [0,4] -> [4,0] BSRRight(2,2): [1,2] -> [0,1,0]

lvl2dim(lvl_indices)[source]#

Maps the level index list to the dimension index list (the inverse of dim2lvl). We can safely assume that the mapping is invertible given that the tensor format passed validation.

Examples

CSR: [0,4] -> [0,4] CSC: [4,0] -> [0,4] BSRRight(2,2): [0,1,0] -> [1,2]