Skip to main content

Transform

Trait Transform 

Source
pub trait Transform: Send + Sync {
    // Required methods
    fn apply(&self, sample: Sample) -> TransformResult;
    fn name(&self) -> &str;
}
Expand description

A stateless transform that operates on individual samples.

For stateful operations (shuffle, batch), use StatefulTransform.

§Implementing a Transform

use tenshift_core::transform::{Transform, TransformResult};
use tenshift_core::sample::Sample;

struct Normalize {
    mean: f32,
    std: f32,
}

impl Transform for Normalize {
    fn apply(&self, sample: Sample) -> TransformResult {
        // Normalize a tensor field in-place
        TransformResult::Sample(sample)
    }

    fn name(&self) -> &str {
        "normalize"
    }
}

Required Methods§

Source

fn apply(&self, sample: Sample) -> TransformResult

Apply this transform to a sample.

Source

fn name(&self) -> &str

Human-readable name for logging.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F> Transform for FilterTransform<F>
where F: Fn(&Sample) -> bool + Send + Sync,

Source§

impl<F> Transform for FlatMapTransform<F>
where F: Fn(Sample) -> Result<Vec<Sample>, Error> + Send + Sync,

Source§

impl<F> Transform for MapTransform<F>
where F: Fn(Sample) -> Result<Sample, Error> + Send + Sync,