The C++ interface for grad. More...

void grad (array &dcols, array &drows, const array &in)
 

Detailed Description

The C++ interface for grad.

grad computes the gradient of a matrix using a central difference along a given dimension. For an interior point in the matrix, \( n_i \), the central difference is computed as \( \frac{n_{i+1} - n_{i-1}}{2} \). For exterior points (those along the edge of the matrix), a one-sided difference is used.

array a; //a = [4 5 3]
// [8 10 9]
// [9 15 20]
array dx,dy;
grad(dcol,drow,a);
// Vertical gradient (along columns)
// dcol = [4 5 6]
// [2.5 5 8.5]
// [1 5 11]
// Horizontal gradient (along rows)
// drow = [1 -0.5 -2]
// [2 0.5 -1]
// [6 5.5 5]

Function Documentation

void af::grad ( array &  dcols,
array &  drows,
const array &  in 
)
Parameters
[in]in2D
[out]dcolsgradient along columns
[out]drowsgradient along rows
Examples:
examples/machine_learning/neuralnetwork.cpp.