Documentation
af_diff

The C interface for diff. More...

## Device pointer interface: Difference along a dimension

Difference function

Parameters
 [in] ndims_out number of output dimensions [in] dims_out output dimensions [out] d_out The output of the function [in] ndims_in number of input dimensions [in] dims_in input dimensions [in] d_in The input to the function [in] order The order of the difference [in] dim The dimension along which the operation is performed
afError af_diff_S (float *d_out, unsigned ndims_in, const unsigned *dims_in, const float *d_in, int order, int dim)
Single precision, difference function. More...

afError af_diff_D (double *d_out, unsigned ndims_in, const unsigned *dims_in, const double *d_in, int order, int dim)
Double precision difference function. More...

## Detailed Description

The C interface for diff.

The difference functions compute either the first or second order difference between adjacent elements in an array along a given dimension.

diff1 computes the first order difference (basic adjacent difference) along a given dimension. If the input array has N elements in the dimension of interest, the resulting array has N-1 elements along the given dimension.

array a; // a = [0 1 2 3 4 5]
print(diff1(a)); // [1 1 1 1 1]
array b; // b = [0 2 4]
// [1 3 5]
//Difference along first dimension, down columns
print(diff1(b)); // diff1(b) = [1 1 1]
//Difference alone second dimension, across rows
print(diff1(b,1)); // diff1(b,1) = [2 2]
a // [2 2]

diff2 computes the second order difference (i.e. the difference between the adjacent first order differences) along a given dimension.

float f[] = { 5, 10, 20, 25, 50, 100};
array a(6,1,f); //a = f
// Take diff1 twice
array b = diff1(a); // b = [5 10 5 25 50]
array c = diff1(b); // c = [5 -5 20 25]
//or use diff2 once
array d = diff2(a); // d = c = [5 -5 20 25]

## Function Documentation

 afError af_diff_S ( float * d_out, unsigned ndims_in, const unsigned * dims_in, const float * d_in, int order, int dim )

Single precision, difference function.

 afError af_diff_D ( double * d_out, unsigned ndims_in, const unsigned * dims_in, const double * d_in, int order, int dim )

Double precision difference function.