Skip to main content

lift

Function lift 

Source
pub fn lift(
    context: &CpuExecutionContext,
    tensor: Tensor,
) -> Result<EagerTensor, ConversionError>
Expand description

Adopt a plain concrete value into context’s eager runtime.

This is the explicit plain to AD boundary: the result is a tracked value in a graph owned by context’s own eager runtime, and nothing about it is inferred from the caller’s ambient no_grad or capture state. The value is moved into the runtime, because a concrete tensor has one owner. Use detach for the opposite direction.

§Errors

Returns ConversionError::Lift when the context’s eager runtime cannot be initialized or when the value cannot be adopted, for example because it is not a concrete host value.

§Examples

use tensor4all_tensorbackend::{explicit, CpuExecutionContext};
use tenferro::Tensor;
use tensor4all_tensorbackend::CpuBackend;

let context = CpuExecutionContext::from_backend(CpuBackend::with_threads(1)?);
let plain = Tensor::from_vec_col_major(vec![2], vec![3.0_f64, 4.0])?;
let tracked = explicit::lift(&context, plain)?;
// The adopted value is tracked, and its runtime is the context's own.
let back = context.with_backend(|backend| explicit::detach(&tracked, backend.engine_mut()))?;
assert_eq!(back.as_slice::<f64>()?, &[3.0, 4.0]);