PERF: Use c++ inner_product and accumlate functions

Using standard functions makes code maintenance easier
and it can also provide significant processing speedups.