# tinker.types.TensorData *Generated from tinker 0.30.4 at commit [`1e5777e`](https://github.com/thinking-machines-lab/tinker/tree/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d). Source links point at that snapshot.* ## *class* [**tinker.types.TensorData**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L26)() **Fields:** - [**dtype**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L27) (*[TensorDtype](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_dtype.py#L5)*) - [**shape**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L29) (*Optional\[List[int]\]*) – Optional. The shape of the tensor (see PyTorch tensor.shape). The shape of a one-dimensional list of length N is `(N,)`. Can usually be inferred if not provided, and is generally inferred as a 1D tensor. - [**sparse_crow_indices**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L37) (*Optional\[List[int]\]*) – Optional CSR compressed row pointers. When set, this tensor is sparse CSR: - data contains only the listed values (flattened); every other entry takes the `pad_value` given when converting to or from a dense tensor - sparse_crow_indices contains the row pointers (length = nrows + 1) - sparse_col_indices contains the column indices (length = nnz) - shape is required and specifies the dense shape - [**sparse_col_indices**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L46) (*Optional\[List[int]\]*) – Optional CSR column indices. Must be set together with sparse_crow_indices. ### *property* [**data**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L84) Flattened tensor data as array of numbers. **Returns:** *Union\[List[int], List[float]\]* ### [**from_torch_sparse**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L106)(*tensor*, *pad_value=0*) Create a sparse CSR TensorData from a dense 2-D torch tensor. Entries equal to `pad_value` are left out; the rest are stored as CSR values. Automatically detects sparsity and encodes as CSR when it saves space. Falls back to dense if the tensor is 1-D or mostly non-pad. `pad_value` must be an integer: the tensor is shifted by it so torch's zero-based CSR conversion can be reused, and an integer shift is exact for `int64` tensors. For `float32` tensors with a non-zero pad it may round values whose magnitude is far below `pad_value`. **Parameters:** - [**tensor**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L106) (*torch.Tensor*) - [**pad_value**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L106) (*int*, default: `0`) **Returns:** *[TensorData](https://tinker-docs.thinkingmachines.ai/tinker/api-reference/types/tensordata/index.md)* ### [**to_numpy**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L152)(*pad_value=0*) Convert TensorData to numpy array. A sparse CSR tensor is densified with `pad_value` in every unlisted entry. **Parameters:** - [**pad_value**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L152) (*int*, default: `0`) **Returns:** *npt.NDArray[Any]* ### [**to_torch**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L161)(*pad_value=0*) Convert TensorData to torch tensor. A sparse CSR tensor is densified with `pad_value` in every unlisted entry. `pad_value` must be an integer so the shift around torch's zero-based densification is exact for `int64` tensors. **Parameters:** - [**pad_value**](https://github.com/thinking-machines-lab/tinker/blob/1e5777ef1e0bb2bae6d9b8d63a6144eec405377d/src/tinker/types/tensor_data.py#L161) (*int*, default: `0`) **Returns:** *torch.Tensor* ## Referenced by - [SamplingClient.sample](https://tinker-docs.thinkingmachines.ai/tinker/api-reference/samplingclient/#sample) - [tinker.types.ForwardBackwardOutput](https://tinker-docs.thinkingmachines.ai/tinker/api-reference/types/forwardbackwardoutput/index.md) - [tinker.types.SampleResponse](https://tinker-docs.thinkingmachines.ai/tinker/api-reference/types/sampleresponse/index.md)