Wraps an existing Storage and tensor geometry into a new TensorImpl with autograd disabled.
See Also
helpers::allocate_cpu — typical Storage producer for the
first argument.
TensorImpl — concrete wrapper type returned.
Parameters
sStorage&&TensorImpl — no copy of the underlying buffer occurs. May be CPU, GPU, or Shared storage.shapeShapedtDtypedeviceDeviceReturns
TensorImplPtrstd::shared_ptr<TensorImpl> to a freshly constructed tensor. The stride is initialised to the C-contiguous default by the TensorImpl constructor; requires_grad is false.
Notes
"Fresh" here means newly produced by an op kernel — neither a view onto an existing tensor nor an autograd leaf that needs gradient tracking. Callers that want a gradient-tracking output must set the autograd metadata after construction.
Storage is moved (rvalue reference), so the input is consumed. This matches the kernel pattern where storage and tensor are produced in adjacent statements and the storage handle is no longer needed after wrapping.
Examples
Build a kernel output tensor in one statement: auto out = helpers::fresh(
helpers::allocate_cpu(out_shape, dt),
out_shape, dt, Device::CPU);