Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def f(x, y, z):
# Solve for x[:n]:
#
# A*x[:n] = bx[:n] + P' * ( ((D1-D2)*(D1+D2)^{-1})*bx[n:]
# + (2*D1*D2*(D1+D2)^{-1}) * (bz[:m] - bz[m:]) ).
blas.copy(( mul( div(d1-d2, d1+d2), x[n:]) +
mul( 2*D, z[:m]-z[m:] ) ), u)
blas.gemv(P, u, x, beta = 1.0, trans = 'T')
lapack.potrs(A, x)
# x[n:] := (D1+D2)^{-1} * (bx[n:] - D1*bz[:m] - D2*bz[m:]
# + (D1-D2)*P*x[:n])
base.gemv(P, x, u)
x[n:] = div( x[n:] - mul(d1, z[:m]) - mul(d2, z[m:]) +
mul(d1-d2, u), d1+d2 )
# z[:m] := d1[:m] .* ( P*x[:n] - x[n:] - bz[:m])
# z[m:] := d2[m:] .* (-P*x[:n] - x[n:] - bz[m:])
z[:m] = mul(di[:m], u-x[n:]-z[:m])
z[m:] = mul(di[m:], -u-x[n:]-z[m:])
def fA(x, y, trans = 'N', alpha = 1.0, beta = 0.0):
base.gemv(A, x, y, trans = trans, alpha = alpha, beta = beta)
else:
def fA(x, y, trans='N', alpha=1.0, beta=0.0):
base.gemv(A, x, y, trans=trans, alpha=alpha, beta=beta)
else:
# x := P' * L^{-T} * (x - Asc'*y)
# = S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz - A'*y)
# (if not F['singular'])
# = S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz + A'*by - A'*y)
# (if F['singular'])
base.gemv(Asct, y, x, alpha=-1.0, beta=1.0)
if type(F['S']) is matrix:
blas.trsv(F['S'], x, trans='T')
else:
cholmod.solve(F['Sf'], x, sys=5)
cholmod.solve(F['Sf'], x, sys=8)
# W*z := GGs*x - z = W^{-T} * (GG*x - bz)
if mnl:
base.gemv(F['Dfs'], x, z, beta=-1.0)
base.gemv(F['Gs'], x, z, beta=-1.0, offsety=mnl)
def f(x, y, z):
# Solve for x[:n]:
#
# A*x[:n] = bx[:n] + P' * ( ((D1-D2)*(D1+D2)^{-1})*bx[n:]
# + (2*D1*D2*(D1+D2)^{-1}) * (bz[:m] - bz[m:]) ).
blas.copy((mul(div(d1-d2, d1+d2), x[n:]) +
mul(2*D, z[:m]-z[m:])), u)
blas.gemv(P, u, x, beta=1.0, trans='T')
lapack.potrs(A, x)
# x[n:] := (D1+D2)^{-1} * (bx[n:] - D1*bz[:m] - D2*bz[m:]
# + (D1-D2)*P*x[:n])
base.gemv(P, x, u)
x[n:] = div(x[n:] - mul(d1, z[:m]) - mul(d2, z[m:]) +
mul(d1-d2, u), d1+d2)
# z[:m] := d1[:m] .* ( P*x[:n] - x[n:] - bz[:m])
# z[m:] := d2[m:] .* (-P*x[:n] - x[n:] - bz[m:])
z[:m] = mul(di[:m], u-x[n:]-z[:m])
z[m:] = mul(di[m:], -u-x[n:]-z[m:])
scale(z, W, trans='T', inverse='I')
# If not F['singular']:
# x := L^{-1} * P * (x + GGs'*z)
# = L^{-1} * P * (x + GG'*W^{-1}*W^{-T}*bz)
#
# If F['singular']:
# x := L^{-1} * P * (x + GGs'*z + A'*y))
# = L^{-1} * P * (x + GG'*W^{-1}*W^{-T}*bz + A'*y)
if mnl:
base.gemv(F['Dfs'], z, x, trans='T', beta=1.0)
base.gemv(F['Gs'], z, x, offsetx=mnl, trans='T',
beta=1.0)
if F['singular']:
base.gemv(A, y, x, trans='T', beta=1.0)
if type(F['S']) is matrix:
blas.trsv(F['S'], x)
else:
cholmod.solve(F['Sf'], x, sys=7)
cholmod.solve(F['Sf'], x, sys=4)
# y := K^{-1} * (Asc*x - y)
# = K^{-1} * (A * S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz) - by)
# (if not F['singular'])
# = K^{-1} * (A * S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz +
# A'*by) - by)
# (if F['singular']).
base.gemv(Asct, x, y, trans='T', beta=-1.0)
if type(F['K']) is matrix:
lapack.potrs(F['K'], y)
# = S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz - A'*y)
# (if not F['singular'])
# = S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz + A'*by - A'*y)
# (if F['singular'])
base.gemv(Asct, y, x, alpha=-1.0, beta=1.0)
if type(F['S']) is matrix:
blas.trsv(F['S'], x, trans='T')
else:
cholmod.solve(F['Sf'], x, sys=5)
cholmod.solve(F['Sf'], x, sys=8)
# W*z := GGs*x - z = W^{-T} * (GG*x - bz)
if mnl:
base.gemv(F['Dfs'], x, z, beta=-1.0)
base.gemv(F['Gs'], x, z, beta=-1.0, offsety=mnl)
def fA(x, y, trans = 'N', alpha = 1.0, beta = 0.0):
base.gemv(A, x, y, trans = trans, alpha = alpha, beta = beta)
else:
def newfDf(u, v, alpha = 1.0, beta = 0.0, trans = 'N'):
base.gemv(newDf, u, v, alpha = alpha, beta =
beta, trans = trans)
else:
# S*ux = bx + GG'*W^{-1}*W^{-T}*bz + A'*by - A'*y.
# W*uz = W^{-T} * ( GG*ux - bz ).
# z := W^{-1} * z = W^{-1} * bz
scale(z, W, trans='T', inverse='I')
# If not F['singular']:
# x := L^{-1} * P * (x + GGs'*z)
# = L^{-1} * P * (x + GG'*W^{-1}*W^{-T}*bz)
#
# If F['singular']:
# x := L^{-1} * P * (x + GGs'*z + A'*y))
# = L^{-1} * P * (x + GG'*W^{-1}*W^{-T}*bz + A'*y)
if mnl:
base.gemv(F['Dfs'], z, x, trans='T', beta=1.0)
base.gemv(F['Gs'], z, x, offsetx=mnl, trans='T',
beta=1.0)
if F['singular']:
base.gemv(A, y, x, trans='T', beta=1.0)
if type(F['S']) is matrix:
blas.trsv(F['S'], x)
else:
cholmod.solve(F['Sf'], x, sys=7)
cholmod.solve(F['Sf'], x, sys=4)
# y := K^{-1} * (Asc*x - y)
# = K^{-1} * (A * S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz) - by)
# (if not F['singular'])
# = K^{-1} * (A * S^{-1} * (bx + GG'*W^{-1}*W^{-T}*bz +
# A'*by) - by)
# (if F['singular']).