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,
) -> Tensor<T, B> {
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 = 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)
.expect("cumsum backend dispatch failed");
out
}
#[inline]
pub fn suffix_sum<T: Scalar + leto_ops::Scalar, B: BackendOps<T> + Default>(
x: &Tensor<T, B>,
dim: usize,
) -> Tensor<T, B> {
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 = 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)
.expect("suffix_sum backend dispatch failed");
out
}