I need to say that c++ is much faster than python in linear algebra. Here I implement several optimization algorithms in c++ and found that we need the eigen package to finish the computation just like importing packages in python.
//here we define a template function typedefdouble(*fun)(double);
classFast_gradient{ public: Fast_gradient(fun, fun, double, double);//this is the construction function doublefast_gradient(); doublenewton(); doublearmoji(double); doublequasi_newton(double); doubleCG(double); private: fun target_function; fun grad_fast_gradient; double init_x; double tol; };