Given a two-dimensional matrix, write an efficient algorithm to calculate the maximum sum of any continuous submatrix.
Implement max_submatrix_sum(matrix). The input is a non-empty rectangular list of integer rows. Return the maximum integer sum over every non-empty rectangle whose rows and columns are contiguous. Single rows and single columns are valid submatrices.
def max_submatrix_sum(matrix):