All problems
Multigrid Restriction Apply
Problem
Apply the 1D multigrid restriction operator to a fine-grid vector of odd length 2m+1, producing a coarse vector of length m:
coarse[i] = 0.25*fine[2i] + 0.5*fine[2i+1] + 0.25*fine[2i+2]
Hint
The stencil [1/4, 1/2, 1/4] smooths the residual onto the coarser grid.
Test cases
case 1
in: [[1,0,1,0,1]]
expected: [0.5,0.5]
case 2
in: [[0,0,0]]
expected: [0]
case 3
in: [[1,2,3,4,5]]
expected: [2,4]
case 4
in: [[2,1,2]]
expected: [1.5]
Starter codePython
def multigrid_restrict(fine):
# Your code here
pass4 test cases · run your code against them in the editor