public:
const f_type func;
const g_type grad;
private:
static array _def_gradienta(const f_type& _func, const array& x,
const double step = 1.e-8){
return derive::derive_nd<dim>(_func, x, step);
};
static array _def_gradient(const f_type& _func, const array& x){
return fdf_function::_def_gradienta(_func, x);
};
public:
static gsl_vector to_gsl_vec(const array& x){
const auto vw = gsl_vector_const_view_array(x.data(), dim);
return vw.vector;
};
static gsl_vector to_gsl_vec(array& x){
auto vw = gsl_vector_view_array(x.data(), dim);
return vw.vector;
};
static array to_std_arr(const gsl_vector* x){
array ret_val;
std::copy(&(x->data[0]), &(x->data[dim]), ret_val.begin());
return ret_val;
};
static array to_std_arr(gsl_vector* x){
return to_std_arr(reinterpret_cast<const gsl_vector*>(x));
};
private:
static double gsl_func(const gsl_vector* x, void* param){
fdf_function* th = reinterpret_cast<fdf_function*>(param);
const array arr = to_std_arr(x);
return (th->func)(arr);
};
static void gsl_grad(const gsl_vector* x, void* param, gsl_vector* y){
fdf_function* th = reinterpret_cast<fdf_function*>(param);
const array arr = to_std_arr(x);
const auto gvec = (th->grad)(arr);
std::copy(gvec.cbegin(), gvec.cend(), &(y->data[0]));
};
static void gsl_full(const gsl_vector* x, void* param, double* f, gsl_vector* y){
fdf_function* th = reinterpret_cast<fdf_function*>(param);
const array arr = to_std_arr(x);
*f = (th->func)(arr);
const auto gvec = (th->grad)(arr);
std::copy(gvec.cbegin(), gvec.cend(), &(y->data[0]));
};
public:
gslf gen_gslf(void){
std::cout << "Gen gslf" << std::endl;
gslf ret_val{
&fdf_function::gsl_func,
&fdf_function::gsl_grad,
&fdf_function::gsl_full,
dim,
reinterpret_cast<void*>(this)};
return ret_val;
};
public:
array def_gradient(const array& x,
const double step = 1.e-8) const{
return _def_gradienta(func, x, step);
};
fdf_function(const f_type& _func, const g_type& _grad):
func(_func),
grad(_grad)
{
std::cout << "S0" << std::endl;
};
fdf_function(const f_type& _func):
fdf_function(
_func,
std::bind(_def_gradient, func, std::placeholders::_1))
{
std::cout << "S1" << std::endl;
};
};
Вывааливается с fatal error: in "OptimizeTests/OptimizeND": memory access violation at address: 0x10f54e3f0: non-existent physical address
Тебя не банят за портянки кода только в связи с праздниками....
paste.ubuntu.com
Обсуждают сегодня