Types#
Support for runtime type validation and conversion.
- class tmol.types.Casting(*values)[source]#
Bases:
EnumCasting specifications for array types, see ndarray.astype.
- class tmol.types.ConvertAttrs[source]#
Bases:
objectConvert attrs fields according to their declared annotations.
- class tmol.types.Dim(size)[source]#
Bases:
objectOne dimension in a runtime-validated tensor shape.
- class tmol.types.NDArray[source]#
Bases:
_TensorTypeRuntime-checkable NumPy array annotation with dtype and shape metadata.
- class tmol.types.SubscriptableType[source]#
Bases:
typeThis metaclass will allow a type to become subscriptable.
>>> class SomeType(metaclass=SubscriptableType): ... pass >>> SomeTypeSub = SomeType['some args'] >>> SomeTypeSub.__args__ 'some args' >>> SomeTypeSub.__origin__.__name__ 'SomeType'
- class tmol.types.Tensor[source]#
Bases:
_TensorTypeRuntime-checkable PyTorch tensor annotation with dtype and shape metadata.
- class tmol.types.TensorGroup[source]#
Bases:
objectMixin for immutable structures whose fields are tensors or tensor groups.
- to(*args, **kwargs)[source]#
Perform dtype/device conversion for all subtensors.
Note that this may be an invalid operations if the TensorGroup contains heterogenous tensor dtypes.
Performs Tensor dtype and/or device conversion. A
torch.dtypeandtorch.deviceare inferred from the arguments ofself.to(*args, **kwargs).If all subtensors already have the correct dtype and device then
selfis returned.
- class tmol.types.ValidateAttrs[source]#
Bases:
objectValidate attrs fields according to their declared annotations.
- tmol.types.cat(seq, dim=0, out=None)[source]#
Concatenate tensors or compatible tensor groups along a dimension.
- tmol.types.constructor_convert(type_annotation='__no__default__', value='__no__default__')[source]#
Convert a value by calling the annotated type when necessary.
- tmol.types.convert_args(f)[source]#
Decorate a callable with runtime conversion of annotated values.
- tmol.types.get_converter(type_annotation)[source]#
Return the registered value converter for a type annotation.
- tmol.types.get_validator(type_annotation)[source]#
Return the registered runtime validator for a type annotation.
- tmol.types.like_kwargs(t: Tensor)[source]#
Extract kwargs args needed to initialize an identical tensor.
- tmol.types.register_converter(type_predicate, converter)[source]#
Register a converter factory for annotations matching a predicate.
- tmol.types.register_validator(type_predicate, validator)[source]#
Register a validator factory for annotations matching a predicate.
- tmol.types.torch_dtype(dt)[source]#
- tmol.types.torch_dtype(dt: dtype)
Resolve a torch dtype via numpy’s dtype parsing system.
- tmol.types.union_convert(union_annotation='__no__default__', value='__no__default__')[source]#
Convert a value using the first compatible member of a union.
- tmol.types.validate_args(f)[source]#
Decorate a callable with runtime validation of annotated values.