For better performance, we should use while instead of for, or cast both to DoubleMatrix and use addi from jblas.