Skip to main content

TypedTensorMaskSessionOpsExt

Trait TypedTensorMaskSessionOpsExt 

Source
pub trait TypedTensorMaskSessionOpsExt {
    // Required method
    fn where_select<U: TensorScalar>(
        &self,
        on_true: &TypedTensor<U>,
        on_false: &TypedTensor<U>,
        session: &mut dyn BackendSession,
    ) -> Result<TypedTensor<U>>;
}
Expand description

Backend-explicit bool-mask session operations for typed tensors.

This trait keeps where_select available as a method on bool TypedTensors while preserving the crate-root extension-trait surface. It is public because downstream users call it directly; the implementation helper in the private typed_tensor module is not a compatibility API.

§Examples

use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorMaskSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let condition =
    TypedTensor::<bool>::from_vec_col_major(vec![2], vec![true, false]).unwrap();
let on_true = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
let on_false = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![3.0, 4.0]).unwrap();
let selected = backend
    .with_backend_session(|session| condition.where_select(&on_true, &on_false, session))
    .unwrap();
assert_eq!(selected.host_data().unwrap(), &[1.0, 4.0]);

Required Methods§

Source

fn where_select<U: TensorScalar>( &self, on_true: &TypedTensor<U>, on_false: &TypedTensor<U>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<U>>

Select typed values using this bool tensor as condition.

§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch::IncompatibleShapes when the condition or either branch cannot broadcast to the other operands, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§