macro_rules! same_variant_unary {
($input:expr, |$t:ident| $call:expr, |$value:ident| $wrap:expr, $fallback:expr) => { ... };
}Expand description
Dispatch a single tensor to a typed kernel and erase its result.
The typed result is wrapped by the scalar’s own constructor, so a real-valued result of a complex input still lands in the matching real variant without the call site naming a variant.
§Examples
use tenferro_internal_cpu_kernels::same_variant_unary;
use tenferro_tensor::{Error, Tensor, TensorScalar};
fn negate(input: &Tensor) -> tenferro_tensor::Result<Tensor> {
same_variant_unary!(
input,
|t| t.duplicate(),
|value| TensorScalar::typed_tensor_into_tensor(value),
Err(Error::dtype_mismatch("negate", input.dtype(), input.dtype()))
)
}
let value = Tensor::from_vec_col_major(vec![1], vec![3.0_f64])?;
assert_eq!(negate(&value)?.as_slice::<f64>()?, &[3.0]);