mod compute;
#[cfg(test)]
mod tests;
use crate::error::Result;
use crate::tensor::Tensor;
const WGSL_VARIANCE_DIM_F64: &str = include_str!("../../shaders/reduce/variance_dim_f64.wgsl");
static WGSL_VARIANCE_DIM_F32: std::sync::LazyLock<String> =
std::sync::LazyLock::new(|| WGSL_VARIANCE_DIM_F64.to_string());
pub struct Variance {
input: Tensor,
dim: Option<usize>, keepdim: bool, }
impl Variance {
#[must_use]
pub fn new(input: Tensor, dim: Option<usize>, keepdim: bool) -> Self {
Self {
input,
dim,
keepdim,
}
}
pub(super) fn wgsl_shader_reduce() -> &'static str {
include_str!("../../shaders/reduce/variance_reduce.wgsl")
}
pub(super) fn wgsl_shader_dim() -> &'static str {
&WGSL_VARIANCE_DIM_F32
}
pub(super) fn input(&self) -> &Tensor {
&self.input
}
pub(super) fn dim(&self) -> Option<usize> {
self.dim
}
pub(super) fn keepdim(&self) -> bool {
self.keepdim
}
}
impl Tensor {
pub fn variance(&self) -> Result<Self> {
Variance::new(self.clone(), None, false).execute()
}
pub fn variance_dim(&self, dim: usize, keepdim: bool) -> Result<Self> {
Variance::new(self.clone(), Some(dim), keepdim).execute()
}
pub fn var(self) -> Result<Self> {
Variance::new(self, None, false).execute()
}
}