Shortcuts

Function torch::nested::as_nested_tensor

Function Documentation

inline at::Tensor torch::nested::as_nested_tensor(at::TensorList list, c10::optional<at::ScalarType> dtype = c10::nullopt, c10::optional<at::Device> device = c10::nullopt)

Nested tensor.

See https://pytorch.org/docs/main/nested.html#torch.nested.nested_tensor

``` */ // implemented on python object to allow torch.nested.nested_tensor to be // constructed with arbitrarily nested python objects - for now, only arbitrary // python lists and lists of Tensors // See torch/csrc/autograd/python_nested_functions_manual.cpp for Python // implementation // See here for C++ implementation inline at::Tensor nested_tensor( at::TensorList nested_tensor_data, const at::TensorOptions& options = {}) { auto out = at::nested_tensor_from_tensor_list( nested_tensor_data, c10::typeMetaToScalarType(options.dtype()), c10::nullopt, options.device(), options.pinned_memory()); if (options.has_requires_grad() && options.requires_grad()) { out.requires_grad(true); } return out; }

inline at::Tensor nested_tensor( at::ArrayRef<detail::TensorDataContainer> nested_tensor_data, const at::TensorOptions& options = {}) { for (const auto& tdc : nested_tensor_data) {

if (( !( tdc.is_init_list() ) )) { c10::detail::torchCheckFail( func, FILE, static_cast<uint32_t>(LINE), (c10::detail::torchCheckMsgImpl( “Expected ” “tdc.is_init_list()” ” to be true, but got false. ” “(Could this error message be improved? If so, ” “please report an enhancement request to PyTorch.)”,”nested_tensor() not implemented for these parameters” ))); }; } // Construct a TensorList using nested_tensor_data std::vector<at::Tensor> tensor_list(nested_tensor_data.size()); std::transform( nested_tensor_data.begin(), nested_tensor_data.end(), tensor_list.begin(), [&](const detail::TensorDataContainer& tdc) { return tdc.convert_to_tensor(options); }); auto out = at::nested_tensor_from_tensor_list( tensor_list, c10::typeMetaToScalarType(options.dtype()), c10::nullopt, options.device(), options.pinned_memory()); if (options.has_requires_grad() && options.requires_grad()) { out.requires_grad(true); } return out; }

/** As Nested Tensor

See
https://pytorch.org/docs/main/nested.html#torch.nested.as_nested_tensor

```

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources