Code Monkey home page Code Monkey logo

Comments (9)

jameskermode avatar jameskermode commented on August 17, 2024

Thanks for reporting, I'm sure we can come up with a fix. As you can see, Python does not allow optional arguments to come before non-optional ones. One possible solution would be to re-order the arguments, so the Python interface to the function above would become wrap(def_, opt=None). Would that be an acceptable solution?

(By the way, as a quick work around, if you don't need access to the routines that are causing this problem, you could omit them from the wrapper generation with the --skip argument to f90wrap.)

from f90wrap.

nelsyeung avatar nelsyeung commented on August 17, 2024

Thank you very much for your reply.

One possible solution would be to re-order the arguments, so the Python interface to the function above would become wrap(def_, opt=None). Would that be an acceptable solution?

That was exactly the solution I was thinking so it's definitely an acceptable solution.

(By the way, as a quick work around, if you don't need access to the routines that are causing this problem, you could omit them from the wrapper generation with the --skip argument to f90wrap.)

Unfortunately, it's in some pretty big part of the program so we can't just skip them.

from f90wrap.

nelsyeung avatar nelsyeung commented on August 17, 2024

@jameskermode Just wondering whether you have any update on this? I'm thinking of writing a script which would reorder the variables during build time myself, if you are currently working on this and are making progress then I guess I'd wait.

from f90wrap.

jameskermode avatar jameskermode commented on August 17, 2024

Hi Nelson, sorry, I didn't manage to work on this yet. I'd hope to be able to do it in the next week or so.

Rather than writing a script to modify your Fortran, if I point you to the relevant part of the f90wrap code would you be willing to try to add this feature directly? You would need to add a new subclass of FortranVisitor to transform.py and call this from transform_to_py_wrapper. The new class should be similar to RenameArgumentsPython but should instead re-order the arguments so any optionals come at the end.

from f90wrap.

jameskermode avatar jameskermode commented on August 17, 2024

Should now be fixed - as is often the case, it was not much work when I got round to it!

I added a version of your test case as a examples/optional_args_issue53, and this is now working correctly. (Note that I had to change from a program to a standalone subroutine to get it to link correctly but this is unrelated to the wrapping issue).

I will leave this issue open for the moment,so you can let me know of any further problems, but if all is well we can close it soon.

from f90wrap.

nelsyeung avatar nelsyeung commented on August 17, 2024

Sorry for the late reply. I can't actually get f90wrap working again. Following my details in this issue, I will get the error:

ImportError: /home/theory/phukgm/Documents/test/_test.so: undefined symbol: wrap_

For ONETEP, I'm getting the error

ImportError: dynamic module does not define init function (PyInit__onetep)

I feel like this is simply a setup issue with my system, but I can't quite figure out what.

from f90wrap.

jameskermode avatar jameskermode commented on August 17, 2024

I think the first error may be due to how you set up the Fortran code to be wrapped. Can you try to build the example in f90wrap/examples/optional_args_issue53 by running make from that directory?

from f90wrap.

nelsyeung avatar nelsyeung commented on August 17, 2024

I get ImportError: dynamic module does not define init function (PyInit_sizeof_fortran_t) during the make process.

from f90wrap.

jameskermode avatar jameskermode commented on August 17, 2024

Fixed (in person rather than on Github!). Problem as a mixture of Python 2 and 3, and of intel and GNU compilers.

from f90wrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.