triangularmap.tmap.TensorTMap
- class triangularmap.tmap.TensorTMap(n, value, *args, **kwargs)[source]
Bases:
TMapSame as
ArrayTMap()but use a PyTorch tensor (torch.full) instead.Public Data Attributes:
Inherited from
TMapSize of the triangular map, i.e., the width at the triangle base.
Underlying storage container.
Shape of the values stored in the map.
A convenience property that uses
get_lslice()andset_lslice()as getter and setter, respectively.A convenience property that uses
get_dslice()andset_dslice()as getter and setter, respectively.A convenience property that uses
get_sslice()andset_sslice()as getter and setter, respectively.A convenience property that uses
get_eslice()andset_eslice()as getter and setter, respectively.A convenience property that uses
get_sblock()andset_sblock()as getter and setter, respectively.A convenience property that uses
get_eblock()andset_eblock()as getter and setter, respectively.Public Methods:
__new__(cls, n, value, *args, **kwargs)Same as
ArrayTMap()but use a PyTorch tensor (torch.full) instead.Inherited from
TMapsize_from_n(n)Calculate the size N of the underlying 1D array for a given width
nof the triangular map: N = n (n + 1)) / 2.n_from_size(n)Calculate width
nof the map given the size N of the underlying 1D array: n = (\sqrt{8 * N + 1} - 1) / 2.For a map of width
n, get an index array of length n (n + 1)) / 2 to reindex from start-end order to top-down order.Reindex
arrfrom start-end order to top-down order.For a map of width
n, get an index array of length n (n + 1)) / 2 to reindex from top-down order to start-end order.Reindex
arrfrom top-down order to start-end order.__init__(arr[, linearise_blocks, _n])depth(start, end)Compute the depth d corresponding to (start, end): d = n - (end - start).
level(*args)Compute the level from depth or (start, end).
linear_from_start_end(start, end)Compute the linear index (in the underlying 1D array) corresponding to a (start, end) pair.
__getitem__(item)Get the item corresponding to (start, end) or the sub-map corresponding to slice start:end.
__setitem__(key, value)Set the item corresponding to (start, end).
copy()Copy the map.
top([depth])Return the sub-map corresponding to the top-most levels.
linear_start_end_from_level(level)Compute the linear 1D start and end index corresponding to all values in the respective level of the map.
get_lslice(level)Slice the map at the given level, returning a view of the values.
set_lslice(level, value)get_dslice(depth)Slice the map at the given depth, returning a view of the values.
set_dslice(depth, value)get_sslice(item)Return a slice for the given start index.
set_sslice(key, value)Like get_sslice but set value instead of returning values.
get_eslice(item)Return a slice for the given end index.
set_eslice(key, value)Like get_eslice but set value instead of returning values.
get_sblock(item)Return a block of sslices down from the specified level.
set_sblock(key, value)Like get_sblock but set value.
get_eblock(item)Return a block of eslices down from the specified level.
set_eblock(key, value)Like get_sblock but set value.
flatten([order])Return map in linear order.
__repr__()Return repr(self).
__str__()Return a string representation of the map, consisting of consecutive dslices.
pretty([cut, str_func, detach_pytorch, scf, ...])Pretty-print a triangular map.
Private Data Attributes:
Inherited from
TMap_flatten_regexPrivate Methods:
Inherited from
TMap_to_int(i)Convert i to integer, no matter whether it is a single number or a numpy array.
_unpack_item(item)_is_pytorch()_check(start, end)Check whether 0 <= start < end < n.
_end_indices_for_sslice(start)Compute the end indices corresponding to a slice at the give start index.
_start_indices_for_eslice(end)Compute the start indices corresponding to a slice at the give end index.
_get_sblock_index(item)_get_eblock_index(item)