Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass data to fitfunction #217

Open
Optiuse opened this issue Oct 24, 2020 · 4 comments
Open

Pass data to fitfunction #217

Optiuse opened this issue Oct 24, 2020 · 4 comments

Comments

@Optiuse
Copy link

Optiuse commented Oct 24, 2020

Hi, is it possible to pass own data (by reference) from scope of upper_function directly to the FitFunc?
(directly from function to FitFunc, without use of global variables)

FitFunc fsphere = [](const double *x, const int N)
{
   // use Data from scope of upper_function() ?
}
void upper_function()
{
   // data. for example a struct/class/int/double/etc
   //...
   CMASolutions cmasols = cmaes<>(fsphere,cmaparams);
   //...
}
@beniz
Copy link
Collaborator

beniz commented Oct 25, 2020

Hi, I guess there's no placeholder into FitFunc for this (if I understand the issue correctly), what's wrong with using a global variable/pointer ?

@Optiuse
Copy link
Author

Optiuse commented Oct 25, 2020

Hi, because i want to run several different optimizations at the same time in several threads. The FitFunctions need access to identifiable individual data each from its thread.
Therefore a global variable/pointer is not possible because the fit functions will not get access to individual data.

Maybe something like a void pointer would be good to pass individual pointers to the FitFunc or other solution?
FitFunc fsphere = [](const double *x, const int N, void *ptr_Data)
Something like this or a placeholder to pass data would be great.

@beniz
Copy link
Collaborator

beniz commented Oct 26, 2020

Seems like a design issue for your application. You can modify FitFunc as needed I guess. If this proves useful somehow, you may provide a pull request once tested.

@RobertBlakeAnderson
Copy link

Function binding provides the solution to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants