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

Document c++ interface #623

Open
DiamonDinoia opened this issue Jan 31, 2025 · 5 comments
Open

Document c++ interface #623

DiamonDinoia opened this issue Jan 31, 2025 · 5 comments

Comments

@DiamonDinoia
Copy link
Collaborator

@mreineck we now have a pure c++ interface.

I think we should document it even if it is marked as experimental and unstable we can start testing it and receive feedback on it.

@mreineck
Copy link
Collaborator

I'm excited and slightly worried about this at the same time...

The main open issue I see with the C++ interface is that it communicates warnings/errors via return codes, which is not idiomatic at all. Especially in the constructor we have to jump through a lot of hoops to still support the original C interface:

  FINUFFT_PLAN_T(int type, int dim, const BIGINT *n_modes, int iflag, int ntrans, TF tol,
                 finufft_opts *opts, int &ier);

The ier variable is necessary just to get a return value out of the constructor, which I feel bad about.

I'm not sure we can present this to end users in this state.
There are other aspects (perhaps converting pointers to single objects into references, making more members of FINUFFT_PLAN_T private ...), but I think they are minor in comparison and I'm happy to work on those during the next weeks. But I'm not sure about the error reporting.

In principle I can replace almost everything with exceptions (and keep the C interface unchanged), but there's nothing I can do about the constructur warning "you have requested a too small epsilon, but I'm continuing nonetheless".
Do you have any suggestions?

@DiamonDinoia
Copy link
Collaborator Author

Yes, we can wrap FINUFFT_PLAN_T into finufft_plan as a member. Then we can throw an exception in the constructor.

This also allows for changing FINUFFT_PLAN_T to accomodate c-style functions with no impact to the cpp-interface.

If we believe that eps too small should crash the nufft.

I am drafting the cmake structure of what I think is best and we can take it from there.

@ahbarnett
Copy link
Collaborator

ahbarnett commented Jan 31, 2025 via email

@DiamonDinoia
Copy link
Collaborator Author

DiamonDinoia commented Jan 31, 2025

Not sure. A warning is generally a print to std:cerr.

I have seen using the factory pattern with std::expected otherwise, but that is c++23.

Using int is c-style, I agree with @mreineck , I do not think we should use ier in c++. It feels weird.

Maybe a make_nufft function that returns a plan is not a bad idea. I think we need to prototype a bit. Not ready for 2.4.

edit:
variant are c++17, should we already use a factory mechanism? This way the interface will be forward is compatible.

@DiamonDinoia
Copy link
Collaborator Author

@mreineck this is how more or less I see the API: https://github.com/DiamonDinoia/finufft/tree/documenting-cpp-interface

The issue is that I need to make the namespace work in the .cpp which I am not sure how to go about it as of now. Open to ideas.

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