DiagonalScale() seemed to work. It turns out that I also need elementwise multiplication of two matrices. That looks hidden in Hadamard(). Looking at the definition of Hadamard in Wikipedia leaves me confused. Is Hadamard() supposed to be doing something else?