Convert 0-dim torch::Tensor to torch::Scalar

This is a stupid question. I am trying to do a very simple thing. How do I convert a 0-dim torch::Tensor into a torch::Scalar.

Basically, what I am trying to achieve is the following:

auto center1 = torch::linspace(a[0], a[1], K+1);

My problem is that a[0] is a 0-dim Tensor but linspace requires a torch::Scalar.

When I tried to simply cast to a scalar, I get the following error:

error: no suitable user-defined conversion from “at::Tensor” to “c10::Scalar” exists

I figured this finally out.

The correct way of doing it, is: a[0].item<float>()