template<typename VecX, typename VecB>
class mtl::itl::detail::scaled_rhs< VecX, VecB >
The right-hand side a Krylov solver works with, for the length of one solve.
A copy of b. The solvers read b again after they have written x: every true-residual check, and gmres on every restart. A call cg(A, x, x, M, iter) therefore read its own iterates as the right-hand side and returned x ~ 6e12 for a 4x4 SPD system (issue 924). The copy is taken before x is touched, so x may alias b, or share its storage through a view. It is also b evaluated once, when b is an expression.
Scaling. With scale, the system is solved as A (s x) = s b, where s is an exact power of two chosen so that ||s b|| is near 1. This happens only when ||b|| is outside [2^-E, 2^E], with E a quarter of the type's max_exponent (32 for float, 256 for double). Inside that band nothing changes, bit for bit. The dot products of cg, bicg, bicgstab, cgs, qmr, tfqmr and bicgstab_ell are quadratic in the residual. In float, b = 1e-30 * ones made dot(p, A p) underflow to 0, so cg and bicgstab reported a breakdown with x = 0. b = 1e20 made the dots overflow and x = NaN (issue 924). minres and idr_s scale their own dot products (#671, #874) and take the copy without the scaling.
Every operation of these solvers is homogeneous in (x, b) when the preconditioner is linear, and multiplying by 2^k is exact in a binary type away from overflow and the subnormals. So the scaled iterates are the unscaled ones times s. x is multiplied by s here and divided by it again when this object is destroyed, on every return and on an exception.
The iteration object sees the user's scale. Pass a residual norm through norm(r) or unscale(nr): the tolerance and norm_r0 are in the units of b.