/// Parallel tensor operations
/// 並列テンソル操作
use crate::tensor::Tensor;
use num_traits::Float;
/// Parallel tensor wrapper for automatic parallelization
pub struct ParallelTensor<T: Float + 'static + ndarray::ScalarOperand + num_traits::FromPrimitive> {
tensor: Tensor<T>,
}
impl<T: Float + 'static + ndarray::ScalarOperand + num_traits::FromPrimitive> ParallelTensor<T> {
/// Create parallel tensor from regular tensor
pub fn from_tensor(tensor: Tensor<T>) -> Self {
Self { tensor }
}
/// Parallel sum operation
pub fn sum(&self) -> T {
// Mock implementation - in reality would use parallel reduction
self.tensor
.as_slice()
.unwrap_or(&[])
.iter()
.fold(T::zero(), |acc, &x| acc + x)
}
/// Parallel map operation
pub fn map<F>(&self, f: F) -> Tensor<T>
where
F: Fn(T) -> T + Send + Sync,
{
// Mock implementation - in reality would use rayon
let result_data: Vec<T> = self.tensor.data.iter().map(|&x| f(x)).collect();
Tensor::from_vec(result_data, self.tensor.shape().to_vec())
}
}