Updated the matrix functions to extend a class _matrixfunc

This allows a matrix function to encapsulate logic for computing the
function and its gradient. This will allow a network trainer to run
backpropogation on the network.