added fast cost_and_grad. not exactly the same results, 99% sure it's due to rounding errors