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

[WIP] LFortran code printing #16931

Open
wants to merge 14 commits into
base: master
from

Conversation

Projects
None yet
7 participants
@anpandey
Copy link
Contributor

commented May 30, 2019

References to other Issues or PRs

Brief description of what is fixed or changed

This pull request adds functionality to convert a SymPy expression to an LFortran abstract syntax tree node. Fortran code may then be generated utilizing the LFortran library.

Other comments

Release Notes

  • codegen
    • add support for code generation through LFortran project

anpandey added some commits May 25, 2019

Modify the ASR conversion class to extend CodePrinter
The ASR converter extends `CodePrinter`, and the conversion functions now follow
the naming conventions of methods in the `CodePrinter` class. This will allow us
to use some of the existing methods in the class in the future.
@sympy-bot

This comment has been minimized.

Copy link

commented May 30, 2019

Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • codegen
    • add support for code generation through LFortran project (#16931 by @anpandey)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed

This pull request adds functionality to convert a SymPy expression to an [LFortran](https://lfortran.org/) abstract syntax tree node. Fortran code may then be generated utilizing the LFortran library.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* codegen
  * add support for code generation through LFortran project
<!-- END RELEASE NOTES -->

convertmethod = '_print_' + type(expr).__name__
if hasattr(self, convertmethod):
return getattr(self, convertmethod)(expr, **kwargs)
else:

This comment has been minimized.

Copy link
@czgdp1807

czgdp1807 May 31, 2019

Member

This else isn't needed.

This comment has been minimized.

Copy link
@asmeurer

asmeurer Jun 6, 2019

Member

Is it actually necessary to define this method at all? It should be handled in the superclass.

This comment has been minimized.

Copy link
@anpandey

anpandey Jun 12, 2019

Author Contributor

It works with the superclass method, but opens up the possibility of the printer returning something other than an AST. I've gotten rid of it for now, since it seems this can be adjusted in the superclass settings.

Show resolved Hide resolved sympy/codegen/lfort.py Outdated

anpandey added some commits May 31, 2019

Use `sympy.external` for importing lfortran
Import errors can then be handled by sympy.
Change up some of the functions
`sympy_to_lfortran` instead of `sympy_to_asr` to more accurately reflect the
output. Also split into to functions: one that wraps and one that doesn't.
from sympy.external import import_module

lfortran = import_module("lfortran")
asr = lfortran.asr.asr

This comment has been minimized.

Copy link
@ArighnaIITG

ArighnaIITG Jun 3, 2019

Contributor

You might have to add a None check here.

anpandey added some commits Jun 3, 2019

Add more (untested) visitor methods
- Float
- Rational
- Pow
- Function
Default symbols to real
The other code generators also assume that symbols are real numbers
Fix floating point conversions
Needed to initialize the superclass to access `_settings`
Add negative one printer
Currently cannot be tested, because the AST -> ASR node visitor hasn't been
implemented
Order the terms in a binary expression
Follows the same pattern as `fcode`, resulting in the same AST.
Fix infinite loop on printing Mult
`_as_ordered_terms` doesn't split Mult, so the recursive call was being passed
with the same arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.