Skip to main content

TestInputBuilder

Struct TestInputBuilder 

Source
pub struct TestInputBuilder { /* private fields */ }
Expand description

Fluent builder for TestInput.

Use TestInput::builder to start one. The builder holds the shape, dtype, and stride spec. Call a finalizer (arange, eye, zeros, uniform, bernoulli, random, custom) to produce a TestInput ready to generate a tensor handle, host data, or test tensor.

§Example

use cubek_test_utils::{TestInput, StrideSpec, Distribution};

let (handle, host) = TestInput::builder(client, [4, 4])
    .stride(StrideSpec::ColMajor)
    .uniform( 0, -1.0, 1.0)
    .generate_with_f32_host_data();

Implementations§

Source§

impl TestInputBuilder

Source

pub fn dtype(self, dtype: impl Into<InputDataType>) -> Self

Override the dtype. Defaults to f32.

Source

pub fn stride(self, stride_spec: StrideSpec) -> Self

Override the stride layout. Defaults to StrideSpec::RowMajor.

Source

pub fn arange(self) -> TestInput

0, 1, 2, … in row-major order.

Source

pub fn arange_scaled(self, scale: f32) -> TestInput

arange with each value multiplied by scale.

Source

pub fn eye(self) -> TestInput

Identity matrix (1 on the diagonal, 0 elsewhere).

Source

pub fn zeros(self) -> TestInput

All-zeros tensor.

Source

pub fn random(self, seed: u64, distribution: Distribution) -> TestInput

Random tensor with a custom Distribution.

Source

pub fn uniform(self, seed: u64, lo: f32, hi: f32) -> TestInput

Uniform random in [lo, hi].

Source

pub fn bernoulli(self, seed: u64, p: f32) -> TestInput

Bernoulli random with probability p of 1.

Source

pub fn normal(self, seed: u64, mean: f32, std: f32) -> TestInput

Normal (Gaussian) random with the given mean and std.

Source

pub fn custom(self, data: Vec<f32>) -> TestInput

Tensor populated from an explicit row-major Vec<f32>.

Source

pub fn linspace(self, start: f32, end: f32) -> TestInput

Evenly-spaced values from start to end inclusive, populated in row-major order. The number of points equals the tensor’s element count.

Equivalent to NumPy’s np.linspace(start, end, num=shape.numel()).reshape(shape).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,