Shortcuts

Function torch::tensor

Function Documentation

inline at::Tensor torch::tensor(detail::TensorDataContainer tensor_data_container, const at::TensorOptions &options = {})

NOTE: Currently torch::tensor(...) doesn’t support mixed data types (i.e.

torch::tensor({{bool, 2.0}}) doesn’t work). We might be able to support it in the future by iterating over all sub-lists to find the largest data type that can represent all of the elements, or by using variadic templates.

NOTE: C++ torch::tensor with a floating-point type or an at::ArrayRef / std::vector / (nested) braced-init-list of floating-point types always produces a tensor of dtype torch::get_default_dtype(), matching Python torch.tensor behavior.

NOTE: C++ torch::tensor with an integer type or an at::ArrayRef / std::vector / (nested) braced-init-list of integer types always produces a tensor of dtype at::kLong (aka. int64_t), matching Python torch.tensor behavior.

NOTE: The following dtypes are not supported by torch::tensor currently:

  • unsigned int

  • unsigned long int

  • unsigned long long int

  • long long int

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