Skip to main content

ClikaRT::ops::diff

function

diff()

Tensor diff(
    Tensor x,
    int64_t n = 1,
    int64_t dim = -1,
    OptionalTensor prepend = {},
    OptionalTensor append = {}
)

n-th order finite difference along dim.

diff(x)i=xi+1xi(applied n times along dim)\mathrm{diff}(x)_i = x_{i+1} - x_i \quad \text{(applied } n \text{ times along } \mathit{dim}\text{)}

Each application shortens the axis by one, so the output's dim extent is size(dim) - n. prepend / append are concatenated onto the axis before differencing (they must match x's shape outside dim).

Parameters

  • x: the input tensor.
  • n: how many times to difference. Default 1.
  • dim: the axis. Negative counts from the end. Default -1.
  • prepend: optional tensor concatenated before x along dim.
  • append: optional tensor concatenated after x along dim.

Throws

  • ClikaRT::Error: when dim is out of range, n exceeds the (extended) axis length, or a prepend/append shape does not match (code_name() carries the reason).

Returns: dtype of x; dim shortened by n (after any prepend/append extension).

auto d1 = ClikaRT::ops::diff(series); // first difference
auto d2 = ClikaRT::ops::diff(series, 2); // second difference

Declared in ClikaRT/compute/ops.h, line 4862