How can I initialize an at::Scalar?

  api, c++, pytorch

I was trying to invoke a PyTorch C++ API function called linspace. When I tried to write it like Python style, I wrote:

torch::Tensor x = torch::linspace(-1, 1, 100);

and this code got a segmentation fault:

[1]    6038 segmentation fault  ./example-app

I read the C++ docs in, and it gave the format of linspace:

at::Tensor torch::linspace(const at::Scalar &start, const at::Scalar &end, c10::optional<int64_t> steps = c10::nullopt, at::TensorOptions options = {})

Here I didn’t know what exactly at::Scalar means, so I searched it in the docs about at namespace, but I didn’t find any class called Scalar.

However, I did find many functions in the at namespace that have a parameter of Scalar type.

This is the docs about linspace function, and this is the docs about at namespace.

Source: Windows Questions C++