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

Retrieve fortran source code #28

Closed
jbcaillau opened this issue Aug 1, 2020 · 4 comments
Closed

Retrieve fortran source code #28

jbcaillau opened this issue Aug 1, 2020 · 4 comments

Comments

@jbcaillau
Copy link

jbcaillau commented Aug 1, 2020

@mgaitan Hi, very nice piece of work.

One question: is there any easy way to retrieve the original fortran code, e.g. as a mere string, from the generated function ? Something like

In[2]: %load_ext fortranmagic

In[3]: %%fortran

       subroutine f1(x, y, z)
            real, intent(in) :: x,y
            real, intent(out) :: z

            z = sin(x+y)

       end subroutine f1

In[4]: print(f1.__source__)

       subroutine f1(x, y, z)
            real, intent(in) :: x,y
            real, intent(out) :: z

            z = sin(x+y)

       end subroutine f1

The motivation can be to reuse the source code for further transformations, such as automatic differentiation (e.g. with Tapenade online tool).

@mgaitan
Copy link
Owner

mgaitan commented Aug 1, 2020

@jbcaillau hi, I've just pushed that little request, thanks for the idea.

However, it's very limited what could be done without a fortran parser. For instance, if your source compile to several object, all of them will share all the source from the cell.

@jbcaillau
Copy link
Author

Thanks for the quick reply.

Yes, sharing all the source from the cell for every compiled can be misleading. Still, one can work piece by piece. All in all, I think it makes sense to keep track of the original code as it allows to iterate static operations on it (automatic differentiation, e.g.)

@jbcaillau
Copy link
Author

PS. A more general question: it is a bit strange to me that no one has made for C/C++ a magic as easy to use as the one you did for fortran. (Of course there are cython and other stuff...)

@mgaitan
Copy link
Owner

mgaitan commented Aug 2, 2020

PS. A more general question: it is a bit strange to me that no one has made for C/C++ a magic as easy to use as the one you did for fortran. (Of course there are cython and other stuff...)

this attempt exists
https://github.com/D3f0/ipython_gcc

@mgaitan mgaitan closed this as completed Jun 16, 2023
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

2 participants