concepts.dsl.dsl_types.TensorValueTypeBase#

class TensorValueTypeBase[source]#

Bases: ValueType

A value type refers to a type of some features associated with physical objects.

Methods

assignment_type()

Return the value type for assignment.

downcast_compatible(other[, ...])

Check if the type is downcast-compatible with the other type; that is, if this type is a subtype of the other type.

from_tensor(tensor)

Create a value type from a pytorch tensor.

is_intrinsically_quantized()

Return whether the value type can be quantized.

long_str()

Return the long string representation of the type.

ndim()

Return the number of dimensions of the value type.

short_str()

Return the short string representation of the type.

size()

Return the total size of the value type.

size_tuple()

Return the size of the value type as a tuple.

tensor_dtype()

Return the corresponding PyTorch tensor dtype.

Attributes

alias

An optional alias of the type.

is_list_type

Return whether the type is a list type.

parent_type

The parent type of the type.

parent_typename

Return the typename of the parent type.

quantized

Whether the tensor is quantized.

typename

The (full) typename of the type.

__init__(typename, quantized, alias=None)[source]#

Initialize the type.

Parameters:
  • typename (str) – The name of the type.

  • alias (str | None) – The alias of the type.

  • quantized (bool) –

__new__(**kwargs)#
assignment_type()#

Return the value type for assignment.

Return type:

ValueType

downcast_compatible(other, allow_self_list=False, allow_list=False)#

Check if the type is downcast-compatible with the other type; that is, if this type is a subtype of the other type.

Parameters:
  • other (TypeBase) – the other type.

  • allow_self_list (bool) – if True, this type can be a list type derived from the other type.

  • allow_list (bool) – if True, the other type can be a list type derived from the type.

Return type:

bool

static from_tensor(tensor)[source]#

Create a value type from a pytorch tensor.

Parameters:

tensor (Tensor) – the tensor.

Returns:

the tensor value type.

Return type:

TensorValueTypeBase

is_intrinsically_quantized()[source]#

Return whether the value type can be quantized. In this project, quantizable means we can transform the value into a single integer scalar. Therefore, only BOOL-valued and INTxx-valued tensors are quantizable.

Returns:

True if the value type can be quantized.

Return type:

bool

long_str()#

Return the long string representation of the type.

Return type:

str

ndim()[source]#

Return the number of dimensions of the value type.

Return type:

int

short_str()#

Return the short string representation of the type.

Return type:

str

size()[source]#

Return the total size of the value type.

Return type:

int

size_tuple()[source]#

Return the size of the value type as a tuple.

Return type:

Tuple[int]

tensor_dtype()[source]#

Return the corresponding PyTorch tensor dtype.

Return type:

dtype

property alias: str | None#

An optional alias of the type.

property is_list_type#

Return whether the type is a list type.

property parent_type: TypeBase | None#

The parent type of the type.

property parent_typename#

Return the typename of the parent type.

property quantized: bool#

Whether the tensor is quantized.

property typename: str#

The (full) typename of the type.