bittensor.core.tensor#
Attributes#
Classes#
Functions#
|
Casts the raw value to a string representing the numpy data type, or the torch data type if using torch. |
|
Casts the raw value to a string representing the tensor shape. |
Module Contents#
- class bittensor.core.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.
- class bittensor.core.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.
- _extract_dtype#
- _extract_shape#
- 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.
- model_config#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 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.
- tensor()[source]#
- Return type:
Union[numpy.ndarray, bittensor.utils.registration.torch.Tensor]
- bittensor.core.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.core.tensor.cast_shape(raw)[source]#
Casts the raw value to a string representing the tensor shape.
- bittensor.core.tensor.dtypes#