def sum(mat, axis, target=None):
  """
  Sum the matrix along the given dimension, where 0 represents the leading
  dimension and 1 represents the non-leading dimension. If a target is
  not prvided, a new vector is created for storing the result.
  """

  m = _eigenmat.get_leading_dimension(mat.p_mat)
  n = _eigenmat.get_nonleading_dimension(mat.p_mat)

  if axis == 0:
    # sum along leading dimension
    if not target:
      target = empty((1, n))
 
  elif axis == 1:
    # sum along non-leading dimension
    if not target:
      target = empty((m, 1))

  err_code = _eigenmat.sum_by_axis(mat.p_mat, target.p_mat, ct.c_int(axis))

  if err_code:
    raise generate_exception(err_code)

  return target

  Sum the matrix along the given dimension, where 0 represents the leading
  dimension and 1 represents the non-leading dimension. If a target is
  not prvided, a new vector is created for storing the result.
  
eigenmat/eigenmat.py