use crate::error::{BarracudaError, Result};
use crate::tensor::Tensor;
mod compute;
#[cfg(test)]
mod tests;
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub(super) struct UniqueParams {
pub(super) input_size: u32,
pub(super) num_buckets: u32,
pub(super) _pad1: u32,
pub(super) _pad2: u32,
}
pub struct Unique {
input: Tensor,
}
impl Unique {
pub fn new(input: Tensor) -> Result<Self> {
if input.is_empty() {
return Err(BarracudaError::invalid_op(
"unique",
"Cannot find unique elements in empty tensor",
));
}
Ok(Self { input })
}
pub(super) fn wgsl_shader() -> &'static str {
include_str!("../../shaders/misc/unique_f32.wgsl")
}
pub(super) fn prefix_sum_shader() -> &'static str {
include_str!("../../shaders/misc/prefix_sum.wgsl")
}
pub(super) fn input(&self) -> &Tensor {
&self.input
}
pub fn execute(self) -> Result<Tensor> {
compute::execute(self)
}
}