use crate::wasm::common::{WasmError, WasmResult, WasmValidation};
use crate::wasm::tensor::WasmTensor;
use js_sys::Array;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct WasmTransformPipeline {
transforms: Vec<String>,
cache_enabled: bool,
}
#[wasm_bindgen]
impl WasmTransformPipeline {
#[wasm_bindgen(constructor)]
pub fn new(cache_enabled: bool) -> WasmTransformPipeline {
WasmTransformPipeline {
transforms: Vec::new(),
cache_enabled,
}
}
pub fn add_transform(&mut self, transform_name: &str) -> WasmResult<()> {
if transform_name.is_empty() {
return Err(WasmError::invalid_param(
"transform_name",
transform_name,
"cannot be empty",
));
}
self.transforms.push(transform_name.to_string());
Ok(())
}
pub fn length(&self) -> usize {
self.transforms.len()
}
pub fn clear(&mut self) {
self.transforms.clear();
}
pub fn execute(&self, input: &WasmTensor) -> WasmResult<WasmTensor> {
input.validate_non_empty()?;
Ok(WasmTensor::new(input.data(), input.shape()))
}
pub fn get_stats(&self) -> String {
format!(
"{{\"transforms\":{},\"cache_enabled\":{}}}",
self.transforms.len(),
self.cache_enabled
)
}
}
#[wasm_bindgen]
pub struct WasmProcessingPipeline {
operations: Vec<String>,
parallel_execution: bool,
}
#[wasm_bindgen]
impl WasmProcessingPipeline {
#[wasm_bindgen(constructor)]
pub fn new(parallel_execution: bool) -> WasmProcessingPipeline {
WasmProcessingPipeline {
operations: Vec::new(),
parallel_execution,
}
}
pub fn add_operation(&mut self, operation_name: &str) -> WasmResult<()> {
if operation_name.is_empty() {
return Err(WasmError::invalid_param(
"operation_name",
operation_name,
"cannot be empty",
));
}
self.operations.push(operation_name.to_string());
Ok(())
}
pub fn operation_count(&self) -> usize {
self.operations.len()
}
pub fn get_config(&self) -> String {
format!(
"{{\"operations\":{},\"parallel\":{}}}",
self.operations.len(),
self.parallel_execution
)
}
}