pub trait CumulativeOps<R: Runtime> {
// Provided methods
fn cumsum(&self, a: &Tensor<R>, dim: isize) -> Result<Tensor<R>> { ... }
fn cumprod(&self, a: &Tensor<R>, dim: isize) -> Result<Tensor<R>> { ... }
fn logsumexp(
&self,
a: &Tensor<R>,
dims: &[usize],
keepdim: bool,
) -> Result<Tensor<R>> { ... }
}Expand description
Cumulative operations
Provided Methods§
Sourcefn cumsum(&self, a: &Tensor<R>, dim: isize) -> Result<Tensor<R>>
fn cumsum(&self, a: &Tensor<R>, dim: isize) -> Result<Tensor<R>>
Cumulative sum along a dimension
Returns the cumulative sum of elements along the specified dimension. For input [a, b, c, d], output is [a, a+b, a+b+c, a+b+c+d].
§Arguments
a- Input tensordim- Dimension along which to compute cumulative sum (supports negative indexing)
§Returns
Tensor with same shape as input containing cumulative sums
§Example
let a = Tensor::<CpuRuntime>::from_slice(&[1.0, 2.0, 3.0, 4.0], &[4], &device);
let result = client.cumsum(&a, 0)?; // [1, 3, 6, 10]Sourcefn cumprod(&self, a: &Tensor<R>, dim: isize) -> Result<Tensor<R>>
fn cumprod(&self, a: &Tensor<R>, dim: isize) -> Result<Tensor<R>>
Cumulative product along a dimension
Returns the cumulative product of elements along the specified dimension. For input [a, b, c, d], output is [a, ab, abc, abcd].
§Arguments
a- Input tensordim- Dimension along which to compute cumulative product (supports negative indexing)
§Returns
Tensor with same shape as input containing cumulative products
§Example
let a = Tensor::<CpuRuntime>::from_slice(&[1.0, 2.0, 3.0, 4.0], &[4], &device);
let result = client.cumprod(&a, 0)?; // [1, 2, 6, 24]Sourcefn logsumexp(
&self,
a: &Tensor<R>,
dims: &[usize],
keepdim: bool,
) -> Result<Tensor<R>>
fn logsumexp( &self, a: &Tensor<R>, dims: &[usize], keepdim: bool, ) -> Result<Tensor<R>>
Log-sum-exp along specified dimensions (numerically stable)
Computes log(sum(exp(x))) in a numerically stable way: logsumexp(x) = max(x) + log(sum(exp(x - max(x))))
This is commonly used in softmax computation and log-probability calculations.
§Arguments
a- Input tensordims- Dimensions to reduce overkeepdim- If true, reduced dimensions are kept with size 1
§Returns
Tensor containing log-sum-exp values
§Example
let a = Tensor::<CpuRuntime>::from_slice(&[1.0, 2.0, 3.0], &[3], &device);
let result = client.logsumexp(&a, &[0], false)?;
// result ≈ log(exp(1) + exp(2) + exp(3)) ≈ 3.4076Implementors§
impl CumulativeOps<CpuRuntime> for CpuClient
CumulativeOps implementation for CPU runtime.