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

Add data pointer (C layer only) #86

Merged
merged 1 commit into from
Sep 20, 2023
Merged

Add data pointer (C layer only) #86

merged 1 commit into from
Sep 20, 2023

Conversation

jschueller
Copy link
Collaborator

@jschueller jschueller commented Sep 20, 2023

In the C layer it can be useful to be able to reach user data from
the objective function callback, this adds an extra pointer argument
that is re-passed through the objective callback.

@jschueller jschueller changed the title Data Add data pointer (C layer only) Sep 20, 2023
@jschueller jschueller marked this pull request as ready for review September 20, 2023 13:32
@zaikunzhang
Copy link
Member

zaikunzhang commented Sep 20, 2023

Hi @jschueller Julien, I agree that it will be useful. It sounds like the C version of "user defined args, f(x, *args)", right?

  1. Since we implement it, could we also test it to some extent?
  2. To implement the Python version of "user defined args, f(x, *args)", you will not need to use the data_ptr in the C interface, right? As far as I see, it can be implemented using a lambda function (if I understand this concept correctly) easily, right?

Thanks

@jschueller
Copy link
Collaborator Author

  1. ok lets do that
  2. yes, in Python the language is more powerful: its done it using the objective function decorator

@zaikunzhang zaikunzhang mentioned this pull request Sep 20, 2023
@jschueller
Copy link
Collaborator Author

all good

@zaikunzhang
Copy link
Member

f = 0.0/0.0;

What about

f = NAN;

where NAN is a macro from math.h.

cmake --build . --target tests --parallel 4

Do we still run the C and Fortran examples? Or they have been renamed to tests? I think we should run them, and examples is a better name.

Thanks.

@jschueller
Copy link
Collaborator Author

jschueller commented Sep 20, 2023

  1. I read NAN is not alwasy supported, but let me try
  2. yes, we run every tests that are not a stress test, this command only build the tests including tests based on examples

@zaikunzhang
Copy link
Member

zaikunzhang commented Sep 20, 2023

  // check data is ok
  if (data != data_ref)
  {
    printf("invalid data\n");
    *f = NAN;
  }

So we will not be informed by the test if there is a discrepancy between data and data_ref unless we check the message. What about raising an error so that we know if there is a problem?

@jschueller
Copy link
Collaborator Author

we check at the end that the evaluation number is ok

@zaikunzhang
Copy link
Member

I read NAN is not alwasy supported, but let me try

If it is not always supported, we should not use it in the production code, but maybe ok for a test ...

@zaikunzhang
Copy link
Member

we check at the end that the evaluation number is ok

It is here, return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); right? If yes, OK.

@jschueller
Copy link
Collaborator Author

yes

In the C layer it can be useful to be able to reach user data from
the objective function callback, this adds an extra pointer argument
that is passed to the objective callback.
@zaikunzhang zaikunzhang merged commit 657e324 into libprima:main Sep 20, 2023
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants