(Python, R, C/C++) Minimize a function subject to non-negativity constraints on variables (conjugate gradient)