use crate::BackendOps;
use coeus_core::Scalar;
use coeus_tensor::Tensor;
#[inline]
pub fn cumsum<T: Scalar + leto_ops::Scalar, B: BackendOps<T> + Default>(
x: &Tensor<T, B>,
dim: usize,
) -> Result<Tensor<T, B>, B::Error> {
let ndim = x.ndim();
assert!(
dim < ndim,
"cumsum: dim {dim} out of range for {ndim}D tensor"
);
let backend = B::default();
let shape = x.shape_cloned();
let mut out = unsafe { Tensor::alloc_on(shape, &backend) }?;
let (out_storage, out_layout) = out.storage_mut_and_layout()?;
backend.cumsum(x.storage(), x.layout(), dim, out_storage, out_layout)?;
Ok(out)
}
#[inline]
pub fn suffix_sum<T: Scalar + leto_ops::Scalar, B: BackendOps<T> + Default>(
x: &Tensor<T, B>,
dim: usize,
) -> Result<Tensor<T, B>, B::Error> {
let ndim = x.ndim();
assert!(
dim < ndim,
"suffix_sum: dim {dim} out of range for {ndim}D tensor"
);
let backend = B::default();
let shape = x.shape_cloned();
let mut out = unsafe { Tensor::alloc_on(shape, &backend) }?;
let (out_storage, out_layout) = out.storage_mut_and_layout()?;
backend.suffix_sum(x.storage(), x.layout(), dim, out_storage, out_layout)?;
Ok(out)
}