The OpenD Programming Language

pairwise

Pairwise map for tensors.

The computation is performed on request, when the element is accessed.

import mir.ndslice.topology;
@fmamath
alias pairwise(alias fun, size_t lag = 1) = slide!(lag + 1, fun)

Parameters

fun

function to accumulate

lag

an integer indicating which lag to use

Return Value

lazy ndslice composed of fun(a_n, a_n+1) values.

Examples

import mir.ndslice.slice: sliced;
assert([2, 4, 3, -1].sliced.pairwise!"a + b" == [6, 7, 2]);

N-dimensional

// performs pairwise along each dimension
// 0 1 2 3
// 4 5 6 7
// 8 9 10 11
assert([3, 4].iota.pairwise!"a + b" == [[10, 14, 18], [26, 30, 34]]);

See Also

Meta