to#
- metatensor.to(tensor: TensorMap, backend: str | None = None, dtype: dtype | None = None, device: device | str | None = None) TensorMap [source]#
Converts a
TensorMap
to a different backend. Currently only supports converting to and from numpy- or torch-based tensors.- Parameters:
backend (str | None) –
str
indicating the backend to convert to. Currently only supports"numpy"
or"torch"
. If not provided, the backend of the inputtensor
will be used.dtype (dtype | None) – the dtype of the data in the resulting
TensorMap
. This is passed directly to numpy/torch, so can be specified as a variety of objects, such as (but not limited to)numpy.dtype
,torch.dtype
,str
, ortype
.device (device | str | None) – only applicable if
backend
is"torch"
. The device on which thetorch.Tensor
objects of the resultingTensorMap
should be stored. Can be specified as a variety of objects such as (but not limited to)torch.device
orstr
.
- Returns:
a
TensorMap
converted to the specified backend, data type, and/or device.- Return type:
- metatensor.block_to(block: TensorBlock, backend: str | None = None, dtype: dtype | None = None, device: device | str | None = None) TensorBlock [source]#
Converts a
TensorBlock
to a differentbackend
. Currently only supports converting to and from numpy- or torch-based tensors.- Parameters:
block (TensorBlock) – input
TensorBlock
.backend (str | None) –
str
, the backend to convert to. Currently only supports"numpy"
or"torch"
. If not specified, the backend is set to match the current backend of the inputblock
.dtype (dtype | None) – the dtype of the data in the resulting
TensorBlock
. This is passed directly to numpy/torch, so can be specified as a variety of objects, such as (but not limited to)numpy.dtype
,torch.dtype
,str
, ortype
.device (device | str | None) – only applicable if
backend
is"torch"
. The device on which thetorch.Tensor
of the resultingTensorBlock
should be stored. Can be specified as a variety of objects such as (but not limited to)torch.device
orstr
.
- Returns:
a
TensorBlock
converted to the specified backend, data type, and/or device.- Return type: