DimensionSize¶
- class nvtripy.DimensionSize(data: int, name: str | None = None)[source]¶
Bases:
Tensor
A 0D,
int32
tensor that represents a scalar value extracted from the shape of a tensor.- Parameters:
data (int) – The value of the DimensionSize, which should be a scalar integer.
name (str | None) – An optional name.
- eval() Tensor [source]¶
Immediately evaluates this tensor. By default, tensors are evaluated lazily.
Note that an evaluated tensor will always reside in device memory.
- Returns:
The evaluated tensor.
- Return type:
Example
1import time 2 3start = time.perf_counter() 4tensor = tp.ones((3, 3)) 5init_time = time.perf_counter() 6tensor.eval() 7eval_time = time.perf_counter() 8 9print(f"Tensor init_time took: {(init_time - start) * 1000.0:.3f} ms") 10print(f"Tensor evaluation took: {(eval_time - init_time) * 1000.0:.3f} ms")
Local Variables¶>>> tensor tensor( [[1, 1, 1], [1, 1, 1], [1, 1, 1]], dtype=float32, loc=gpu:0, shape=(3, 3))
Output¶Tensor init_time took: 9.500 ms Tensor evaluation took: 3957.263 ms
- tolist() List | Number ¶
Returns the tensor as a nested list. If the tensor is a scalar, returns a python number.
- Returns:
The tensor represented as a nested list or a python number.
- Return type:
List | Number
Example: Ranked tensor
1tensor = tp.ones((2, 2)) 2tensor_list = tensor.tolist()
Local Variables¶>>> tensor_list [[1.0, 1.0], [1.0, 1.0]]
Example: Scalar
1tensor = tp.Tensor(2.0, dtype=tp.float32) 2tensor_scalar = tensor.tolist()
Local Variables¶>>> tensor_scalar 2.0