macro_rules! with_scalar {
($tensor:expr, all, backend = $backend:expr, op = $op:expr, |$typed:ident| $(-> $ret:ty)? $body:block) => { ... };
($tensor:expr, numeric, backend = $backend:expr, op = $op:expr, |$typed:ident| $(-> $ret:ty)? $body:block) => { ... };
($tensor:expr, float_complex, backend = $backend:expr, op = $op:expr, |$typed:ident| $(-> $ret:ty)? $body:block) => { ... };
($tensor:expr, float_only, backend = $backend:expr, op = $op:expr, |$typed:ident| $(-> $ret:ty)? $body:block) => { ... };
}Expand description
Dispatch a dtype-erased Tensor to a typed tensor body.
The dtype-set guard keeps unsupported dtype rejection at the boundary where the backend and operation name are still visible.
ยงExamples
use tenferro_tensor::{BackendId, Tensor};
let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
let shape = tenferro_tensor::with_scalar!(
&tensor,
float_only,
backend = BackendId::Cpu,
op = "shape_probe",
|typed| -> tenferro_tensor::Result<Vec<usize>> { Ok(typed.shape().to_vec()) }
)?;
assert_eq!(shape, vec![2]);