Transform a 2D matrix from one input format into a specified output format, handling large test cases with tricky edge cases
Asked in the Round 2 - Technical Assessment stage. The candidate gave a garbled example: input [[1,2],[3,4]] -> output [[1,3],[4,10]]; this output is the 2D prefix sum matrix.
Implement prefix_sum_matrix(matrix). For each position (r, c), return the sum of all input values in the rectangle from (0, 0) through (r, c).
Input is a non-empty rectangular list of lists of integers. Return a matrix with the same dimensions.
def prefix_sum_matrix(matrix):