aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/fitter.hpp2
-rw-r--r--interface/opt.cc2
-rw-r--r--models/dl_model.hpp181
-rw-r--r--models/models.cc3
4 files changed, 23 insertions, 165 deletions
diff --git a/core/fitter.hpp b/core/fitter.hpp
index 2a81d70..cb2c799 100644
--- a/core/fitter.hpp
+++ b/core/fitter.hpp
@@ -566,11 +566,11 @@ namespace opt_utilities
{
return *this;
}
+ param_info_list=rhs.param_info_list;
if(rhs.p_param_modifier!=0)
{
set_param_modifier(*(rhs.p_param_modifier));
}
- param_info_list=rhs.param_info_list;
null_param=rhs.null_param;
return *this;
}
diff --git a/interface/opt.cc b/interface/opt.cc
index 0e2f3b4..1025d60 100644
--- a/interface/opt.cc
+++ b/interface/opt.cc
@@ -18,7 +18,7 @@ struct fit_space
/// dopt::model model;
fit_space()
{
- fit.set_method(dopt::powell_method());
+ fit.set_opt_method(dopt::powell_method());
dopt::chisq cq;
dopt::leastsq lsq;
// cq.verbose(true);
diff --git a/models/dl_model.hpp b/models/dl_model.hpp
index 7221fd1..9729335 100644
--- a/models/dl_model.hpp
+++ b/models/dl_model.hpp
@@ -12,169 +12,30 @@
namespace opt_utilities
{
+
template <typename T>
- class dl_model
- :public model<T,T,std::vector<T>,std::string>
+ model<T,T,std::vector<T>,std::string>* load_model(const char* fname)
{
- private:
- T (*calc_model)(T x,const T* p);
- int nparams;
- mutable void* handle;
- private:
- model<T,T,std::vector<T> >* do_clone()const
- {
- dl_model<T>* result=new dl_model<T>(*this);
- this->handle=NULL;
- return result;
- }
+ void* handle;
- const char* do_get_type_name()const
- {
- return "shared object wrapping model";
- }
-
- // public:
- public:
- dl_model()
- :handle(NULL)
- {}
-
-
- public:
- dl_model(const char* file_name)
- :handle(NULL)
- {
-
- handle=dlopen(file_name,RTLD_LAZY);
-
- if(!handle)
- {
- throw opt_exception("faild loading object");
- }
-
- calc_model=(T (*)(T,const T*))dlsym(handle,"calc_model");
-
- if(!calc_model)
- {
- throw opt_exception("symble undefined");
- }
-
- const char* (*get_param_name)(int)
- =(const char* (*)(int))dlsym(handle,"get_param_name");
-
- if(!get_param_name)
- {
- throw opt_exception("symble undefined");
- }
-
- int (*get_num_params)()
- =(int (*)())dlsym(handle,"get_num_params");
-
- if(!get_num_params)
- {
- throw opt_exception("symble undefined");
- if(!get_num_params)
- {
- throw opt_exception("symble undefined");
- } }
-
- T (*get_default_value)(int)
- =(T (*)(int))dlsym(handle,"get_default_value");
-
- if(!get_default_value)
- {
- throw opt_exception("symble undefined");
- }
-
- nparams=get_num_params();
-
- for(int i=0;i!=nparams;++i)
- {
- this->push_param_info(param_info<std::vector<T> >(get_param_name(i),
- get_default_value(i)));
- }
- }
-
- ~dl_model()
- {
- if(handle)
- {
- dlclose(handle);
- }
- }
-
- void bind(const char* file_name)
- {
- if(handle)
- {
- dlclose(handle);
- }
- this->clear_param_info();
- handle=dlopen(file_name,RTLD_LAZY);
-
- if(!handle)
- {
- throw opt_exception("faild loading object");
- }
-
- calc_model=(T (*)(T,const T*))dlsym(handle,"calc_model");
-
- if(!calc_model)
- {
- throw opt_exception("symble undefined");
- }
-
- const char* (*get_param_name)(int)
- =(const char* (*)(int))dlsym(handle,"get_param_name");
-
- if(!get_param_name)
- {
- throw opt_exception("symble undefined");
- }
-
-
- int (*get_num_params)()
- =(int (*)())dlsym(handle,"get_num_params");
-
- if(!get_num_params)
- {
- throw opt_exception("symble undefined");
- }
-
-
- T (*get_default_value)(int)
- =(T (*)(int))dlsym(handle,"get_default_value");
-
-
- if(!get_default_value)
- {
- throw opt_exception("symble undefined");
- }
-
-
- nparams=get_num_params();
- for(int i=0;i!=nparams;++i)
- {
- this->push_param_info(param_info<std::vector<T> >(get_param_name(i),
- get_default_value(i)));
- }
- }
-
- T do_eval(const T& x,const std::vector<T>& param)
- {
- if(handle==NULL)
- {
- throw opt_exception("dl object unloaded");
- }
- return calc_model(x,&get_element(param,0));
- }
-
- std::string do_to_string()const
- {
- return "Dynamical load model\n"
- "Should be loaded from an shared object file\n";
- }
- };
+ handle=dlopen(fname,RTLD_LAZY);
+
+ if(!handle)
+ {
+ throw opt_exception("faild loading object");
+ }
+
+
+ model<T,T,std::vector<T>,std::string>* (*func_create)();
+
+ func_create=(model<T,T,std::vector<T>,std::string>* (*)())dlsym(handle,"create_model_object");
+
+ if(!func_create)
+ {
+ throw opt_exception("symble undefined");
+ }
+ return func_create();
+ }
}
diff --git a/models/models.cc b/models/models.cc
index 8a63037..e1c6d34 100644
--- a/models/models.cc
+++ b/models/models.cc
@@ -108,9 +108,6 @@ model<double,vecn<double,2>,std::vector<double>,std::string>& get_2dmodel_by_nam
model_map["poly1d3"]=new poly1d<double,3>;
model_map["poly1d4"]=new poly1d<double,4>;
model_map["poly1d5"]=new poly1d<double,5>;
-#ifdef __linux__
- model_map["dlmodel"]=new dl_model<double>;
-#endif
//DECL_POLY(7)
}