dxtb.components.base.ComponentCache#
- class dxtb.components.base.ComponentCache(device=None, dtype=None)[source]#
Bases:
TensorLikeCache of a component.
Methods
Returns a copy of the
TensorLikeinstance on the CPU.Override the device of the class object.
Override the dtype of the class object.
Returns a copy of the
TensorLikeinstance on the specified device.Returns a copy of the
TensorLikeinstance with specified floating point type.Attributes
Specification of dtypes that the
TensorLikeobject can take.Shortcut for device and dtype.
The device on which the class object resides.
Floating point dtype used by class object.
- Parameters:
device (torch.device | None)
dtype (torch.dtype | None)
- cpu()#
Returns a copy of the
TensorLikeinstance on the CPU.This method creates and returns a new copy of the
TensorLikeinstance on the CPU.- Return type:
Self- Returns:
A copy of the
TensorLikeinstance placed on the CPU.- Return type:
- override_device(device)#
Override the device of the class object. :rtype:
NoneWarning
This does not change the device of the underlying tensors. It only changes the device of the class object. Use with caution.
- Parameters:
device (
torch.device) – Device to override the current device.- Parameters:
device (device)
- Return type:
None
- override_dtype(dtype)#
Override the dtype of the class object. :rtype:
NoneWarning
This does not change the dtype of the underlying tensors. It only changes the dtype of the class object. Use with caution.
- Parameters:
dtype (
torch.dtype) – Floating point dtype to override the current dtype.- Parameters:
dtype (dtype)
- Return type:
None
- to(device=None, dtype=None)#
Returns a copy of the
TensorLikeinstance on the specified device.This method creates and returns a new copy of the
TensorLikeinstance on the specified device “device”.- Return type:
Self- Parameters:
device (
torch.device) – Device to which all associated tensors should be moved.- Returns:
A copy of the
TensorLikeinstance placed on the specified device.- Return type:
- Parameters:
Notes
If the
TensorLikeinstance is already on the desired deviceselfwill be returned.
- type(dtype)#
Returns a copy of the
TensorLikeinstance with specified floating point type. This method creates and returns a new copy of theTensorLikeinstance with the specified dtype.- Return type:
Self- Parameters:
dtype (
torch.dtype) – Floating point type.- Returns:
A copy of the
TensorLikeinstance with the specified dtype.- Return type:
- Parameters:
dtype (dtype)
Notes
If the
TensorLikeinstance has already the desired dtypeSelfwill be returned.
- property allowed_dtypes: tuple[dtype, ...]#
Specification of dtypes that the
TensorLikeobject can take. Defaults to float types and must be overridden by subclass if float are not allowed. The IndexHelper is an example that should only allow integers.- Returns:
Collection of allowed dtypes the
TensorLikeobject can take.- Return type:
tuple[torch.dtype, …]