bittensor.tensor#
Attributes#
Classes#
Functions#
|
Casts the raw value to a string representing the |
|
Casts the raw value to a string representing the tensor shape. |
Module Contents#
- class bittensor.tensor.DTypes(*args, **kwargs)[source]#
Bases:
dict
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Initialize self. See help(type(self)) for accurate signature.
- bittensor.tensor.dtypes#
- bittensor.tensor.cast_dtype(raw)[source]#
Casts the raw value to a string representing the numpy data type, or the torch data type if using torch.
- Parameters:
raw (Union[None, numpy.dtype, torch.dtype, str]) – The raw value to cast.
- Returns:
The string representing the numpy/torch data type.
- Return type:
- Raises:
Exception – If the raw value is of an invalid type.
- bittensor.tensor.cast_shape(raw)[source]#
Casts the raw value to a string representing the tensor shape.
- class bittensor.tensor.Tensor(/, **data)[source]#
Bases:
pydantic.BaseModel
Represents a Tensor object.
- Parameters:
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_config#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- tensor()[source]#
- Return type:
Union[numpy.ndarray, bittensor.utils.registration.torch.Tensor]
- deserialize()[source]#
Deserializes the Tensor object.
- Returns:
The deserialized tensor object.
- Return type:
np.array or torch.Tensor
- Raises:
Exception – If the deserialization process encounters an error.
- static serialize(tensor_)[source]#
Serializes the given tensor.
- Parameters:
tensor (np.array or torch.Tensor) – The tensor to serialize.
tensor_ (Union[numpy.ndarray, bittensor.utils.registration.torch.Tensor])
- Returns:
The serialized tensor.
- Return type:
- Raises:
Exception – If the serialization process encounters an error.
- _extract_shape#
- _extract_dtype#