mod compute;
#[cfg(test)]
mod tests;
use crate::error::Result;
use crate::tensor::Tensor;
#[must_use]
pub fn wgsl_std_simple() -> &'static str {
static SHADER: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
include_str!("../../shaders/misc/std_simple_f64.wgsl").to_string()
});
std::sync::LazyLock::force(&SHADER).as_str()
}
pub(crate) const WGSL_STD_DIM_F64: &str = include_str!("../../shaders/reduce/std_dim_f64.wgsl");
static WGSL_STD_DIM_F32: std::sync::LazyLock<String> =
std::sync::LazyLock::new(|| WGSL_STD_DIM_F64.to_string());
pub struct Std {
input: Tensor,
dim: Option<usize>, keepdim: bool, }
impl Std {
#[must_use]
pub fn new(input: Tensor, dim: Option<usize>, keepdim: bool) -> Self {
Self {
input,
dim,
keepdim,
}
}
pub(crate) fn wgsl_shader_reduce() -> &'static str {
include_str!("../../shaders/reduce/std_reduce.wgsl")
}
pub(crate) fn wgsl_shader_dim() -> &'static str {
std::sync::LazyLock::force(&WGSL_STD_DIM_F32).as_str()
}
pub fn execute(self) -> Result<Tensor> {
compute::execute(self)
}
}
impl Tensor {
pub fn std(&self) -> Result<Self> {
Std::new(self.clone(), None, false).execute()
}
pub fn std_dim(&self, dim: usize, keepdim: bool) -> Result<Self> {
Std::new(self.clone(), Some(dim), keepdim).execute()
}
}