All problems
Diagonal Preconditioner Apply
Problem
Apply the diagonal (Jacobi) preconditioner to residual r, returning z with
z[i] = r[i] / A[i][i]
Assume all diagonal entries of A are nonzero.
Hint
This is one application of the inverse diagonal of A to a vector.
Test cases
case 1
in: [[[2,0],[0,4]],[2,8]]
expected: [1,2]
case 2
in: [[[1,1],[1,3]],[4,8]]
expected: [4,2.6666666666666665]
case 3
in: [[[5]],[10]]
expected: [2]
case 4
in: [[[-2,0],[0,1]],[1,-1]]
expected: [-0.5,-1]
Starter codePython
def apply_diagonal_preconditioner(A, r):
# Your code here
pass4 test cases · run your code against them in the editor