singleMaxPooling = (mat, kernelWidth=2, stride=2, padding='VALID') => {
  console.assert(kernelWidth === 2, 'Only supports kernen = [2,2]');
  console.assert(stride === 2, 'Only supports stride = 2');
  console.assert(padding === 'VALID', 'Only support valid padding');

  // Handle odd length mat
  // 'VALID': ignore edge rows and columns
  // 'SAME': add zero padding to make the mat have even length
  if (mat.length % 2 === 1 && padding === 'VALID') {
    mat = matrixSlice(mat, 0, mat.length - 1, 0, mat.length - 1);
  }

  let stepSize = (mat.length - kernelWidth) / stride + 1;
  let result = init2DArray(stepSize, stepSize, 0);

  for (let r = 0; r < stepSize; r++) {
    for (let c = 0; c < stepSize; c++) {
      let curWindow = matrixSlice(mat, r * stride, r * stride + kernelWidth,
        c * stride, c * stride + kernelWidth);
      result[r][c] = matrixMax(curWindow);
    }
 }
 return result;
}
Max pool one matrix.
@param {[[number]]} mat Matrix
@param {int} kernelWidth Pooling kernel length (only supports 2)
@param {int} stride Pooling sliding stride (only supports 2)
@param {string} padding Pading method when encountering odd number mat,
currently this function only supports 'VALID'