concepts.dsl.tensor_value.TensorValue#
- class TensorValue[source]#
Bases:
ValueBase
A value object with an internal
torch.Tensor
storage.Methods
clone
([clone_tensor, dtype])expand
(batch_variables, batch_sizes)expand_as
(other)fast_index
(arguments[, wrap])fast_set_index
(arguments, value)format
([content, short])from_optimistic_value
(value)from_optimistic_value_int
(identifier, dtype)from_scalar
(value[, dtype])from_tensor
(value[, dtype, batch_variables, ...])from_tensorized_pyobj
(value[, dtype, ...])from_values
(*args[, dtype])get_variable_size
(variable_name_or_index)index
(key)item
()iter_batched_indexing
([dim])Iterate over one of the batch dimensions.
make_empty
(dtype[, batch_variables, ...])rename_batch_variables
(new_variables[, ...])set_index
(key, value)set_print_options
([max_tensor_size])to_masked_tensor_storage
([clone_tensor])Attributes
The data type of the Value object.
The list of batch variable names.
Additional batch dimensions at the beginning.
Whether the values in self.tensor is quantized.
The internal tensor storage.
A mask of the tensor, indicating which elements are valid.
The optimistic values for the tensor.
The quantized values for the tensor.
- __init__(dtype, batch_variables, tensor, batch_dims=0, quantized=None, *, _check_tensor=False, _mask_certified_flag=True)[source]#
Instantiate a Value object for storing intermediate computation results.
The tensor is assumed to have the following layout:
tensor[B1, B2, B3, ..., V1, V2, V3, ..., D1, D2, D3, ...]
.The first batch_dims dimensions are “batch”.
The next len(batch_variables) dimensions are “variables”.
The next dtype.ndim() dimensions are data dimensions (e.g., images, vectors).
A special case is that dtype.ndim() can be zero (scalar).
- Parameters:
dtype (TensorValueTypeBase | PyObjValueType | BatchedListType) – The data type of the Value object.
batch_variables (Iterable[str] | int) – A sequence of variables that are processed in “batch.” This typically corresponds to “quantified variables.” It can also be a single integer, indicating the number of batched variables.
tensor (Tensor | TensorizedPyObjValues | MaskedTensorStorage) – The actual tensor
batch_dims (int) – The additional batch dimensions at the beginning. Defaults to 0.
_check_tensor (bool) – internal flag, whether to run the tensor shape/type sanity check.
_mask_certified_flag (bool) – internal flag, indicating whether self.tensor_mask is guaranteed to be the correct mask. This flag will be marked false when we do expand_as.
quantized (bool | None)
- __new__(**kwargs)#
- clone(clone_tensor=True, dtype=None)[source]#
- Parameters:
dtype (TensorValueTypeBase | PyObjValueType | BatchedListType | None)
- Return type:
- expand_as(other)[source]#
- Parameters:
other (TensorValue)
- Return type:
- fast_set_index(arguments, value)[source]#
- Parameters:
value (Tensor | Any | OptimisticValue)
- classmethod from_optimistic_value(value)[source]#
- Parameters:
value (OptimisticValue)
- Return type:
- classmethod from_optimistic_value_int(identifier, dtype)[source]#
- Parameters:
identifier (int)
dtype (TensorValueTypeBase | PyObjValueType)
- Return type:
- classmethod from_scalar(value, dtype=None)[source]#
- Parameters:
value (Any)
dtype (TensorValueTypeBase | PyObjValueType | None)
- Return type:
- classmethod from_tensor(value, dtype=None, batch_variables=None, batch_dims=0)[source]#
- Parameters:
value (Tensor)
dtype (TensorValueTypeBase | BatchedListType | None)
batch_dims (int)
- Return type:
- classmethod from_tensorized_pyobj(value, dtype=None, batch_variables=None, batch_dims=0)[source]#
- Parameters:
value (TensorizedPyObjValues)
dtype (PyObjValueType | None)
batch_dims (int)
- Return type:
- classmethod from_values(*args, dtype=None)[source]#
- Parameters:
args (Any)
dtype (TensorValueTypeBase | None)
- Return type:
- item()[source]#
- Return type:
Tensor | Any | OptimisticValue
- iter_batched_indexing(dim=0)[source]#
Iterate over one of the batch dimensions.
- Parameters:
dim (int)
- Return type:
- classmethod make_empty(dtype, batch_variables=tuple(), batch_sizes=tuple(), batch_dims=0)[source]#
- Parameters:
dtype (TensorValueTypeBase | PyObjValueType | BatchedListType)
batch_dims (int)
- rename_batch_variables(new_variables, dtype=None, force=False, clone=False)[source]#
- Parameters:
dtype (TensorValueTypeBase | PyObjValueType | BatchedListType | None)
force (bool)
clone (bool)
- single_elem()[source]#
- Return type:
Tensor | Any | OptimisticValue
- FALSE: TensorValue = Value[bool, axes=[], tdtype=torch.int64, tdshape=(), quantized]{tensor(0)}#
- STR_MAX_TENSOR_SIZE = 100#
- TRUE: TensorValue = Value[bool, axes=[], tdtype=torch.int64, tdshape=(), quantized]{tensor(1)}#
- dtype: TensorValueTypeBase | PyObjValueType | BatchedListType#
The data type of the Value object.
- property is_scalar#
- property is_single_elem#
- property is_tensorized_pyobj#
- property is_torch_tensor#
- property nr_variables#
- tensor: Tensor | TensorizedPyObjValues#
The internal tensor storage.
- tensor_optimistic_values: Tensor | None#
The optimistic values for the tensor. 0 for non-optimistic values.
- tensor_quantized_values: Tensor | None#
The quantized values for the tensor. -1 for non-quantized values.
- property total_batch_dims#