Does `torch::IValue` hold and own the underlying tensor?

My code needs to use a tensor (wrapped by IValue) 's underlying data_ptr for some raw array operations (interacting with Eigen). I want to make sure I’m not messing up the object lifetime, and I want to ask if the following c++ code is safe:

// x is a `torch::IValue` which holds a float tensor
float* ptr = x.toTensor().data_ptr<float>();
// Do I have a valid pointer from now on?
// Guarantees: `x` will remain live and constant
// Worries: the `x.toTensor()` tmp object has gone out of scope.
// Question: does `x` hold the underlying tensor and data for me
//     even though the tmp is gone?