Let's allocate `dbeta` outside the loops, so we don't keep allocating a new one.