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
refactor for Codegen Routine #8082
Conversation
@jcrist: is this the right approach? I guess you rather mean a standard alone function, not part of the code_gen class. Lots of tests call Routine() directly: how would all of those know what language? I suspect the main user interface should be "name_expr" into "code_gen" rather than calling I'll play with having a standalone |
I think that would be best. Instances of |
Thanks for taking care of this, the codegen stuff is a bit messy and needs more cleanup than I did in my first pass. |
9e50f03
to
377e2b2
Compare
@jcrist How about this? In the other pr, OctaveCodeGen has its own It looks like a big change, but its just a copy-paste of the existing |
Ok, please review. I can rebase commits a bit before merging (if wanted). |
CodeGenArgumentListError, Result, ResultBase, CCodeGen | ||
) | ||
from sympy.utilities.codegen import routine as Routine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be explicit with this change. Disguising the function as a class doesn't seem like a good idea to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 30/09/14 03:38, Jim Crist wrote:
I think we should be explicit with this change.
Agree, done.
|
Should be fixed. |
I've looked at Result a bit more and it seems there are indeed language-specific assumptions made there. For example, it is not possible to give one a name, rather it automatically generates a hash name. This is fine for C/Fortran but not good for Octave which doesn't have Currently I'm (ab)using OutputArguments for Octave return values. I assume the "proper" thing is to fix Result? firstly by subclassing from Variable. I assume OutputArguments should be only used for "rhs-like" stuff, stuff that should be an argument but for pointers. |
I've added input checking for Routine init in 4dcaa33. @jcrist does that look about right? |
0dbc73d
to
16eac46
Compare
Two options then, leaving it up to you. Either name the
In my mind the distinction is this:
That could maybe work. Ideally |
b23d54b
to
6815ca8
Compare
@jcrist commit 1014510 has my attempt at C/Fortran are not effected. If you give them a NamedResult, they should treat it same as Result, although I didn't add a test for that (should I?) |
da04700
to
19a38f6
Compare
Rebased, hopefully easier to understand. No overall changes. |
# Check that all symbols in the expressions are covered by | ||
# InputArguments/InOutArguments---subset because user could | ||
# specify additional (unused) InputArguments or local_vars. | ||
assert symbols.issubset(input_symbols.union(local_vars)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do better than an assert for this, and throw an actual error message that will be more meaningful to the users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do better than an assert for this
done.
Ok, I have removed NamedResult. After a previous discussion with @moorepants, I'm unsure whether I should merge or rebase for the merge conflict. @jcrist: Preference? if not, I will rebase. |
Looks good to me. It would be nice to squash some of these commits together (specifically to remove the unused |
d82f8b2
to
9cac813
Compare
rebase done, no changes, just some squashing. |
Will merge in 24 hours if no dissents. |
precision -- FIXME | ||
"""Return a new variable. | ||
|
||
name : Symbol or MatrixSymbol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this missing:
Parameters
==========
?
@moorepants (since you're looking at it right now), and others: I'm +1 on this, but have one nagging thought. The old In general I think this is unavoidable. Further, I don't think anyone uses this functionality anyway. |
I fine with a nice big release note warning. The advanced users would be likely to be using the master branch and would notice this. I have no good idea about how much use of @bjodah What do you think of this? No deprecation cycle? |
👍 I'm fine with just a warning. It's nice to see the codegen stuff moving forward - good job! |
There are merge conflicts (I assume from the PR that Jason just merged). Please fix them (could also take this time to squash your last 3 fix-it commits together, but only if you feel like it). I'll merge once that's done. |
Put the existing Fortran/C `Routine.__init__` into Codegen class. Essentially unchanged. Codegen will now make appropriate instances of Routine. Routine is still essentially language agnostic, although a particular instance might be more appropriate for a particular Codegen.
1d0a34e
to
bba1454
Compare
Lines to 75 chars, follow numpy style. Some pylint fixes. Slightly simplify Argument and its subclasses.
1. Result subclasses Variable so it has a name. By default, name and result_var get the dummy "result_" symbol. This was already the case for result_var. 2. Add name and result_var kwargs: name defaults to None and result_var defaults to name. 3. Result can work with Matrix class. Result can take dimensions kwarg. Maybe not allowed in C/Fortran but others languages might allow this. 4. Document the difference between name and result_var. Perhaps these could/should be refactored, but for now, document that they are usually the same thing.
bba1454
to
eb38f4e
Compare
Ok, rebased. Please wait for tests to complete (the other merge meant more |
Merging. @cbm755, please add something in the release notes about this change. Thanks for your work! |
Ok, done, although might be a bit verbose for what is likely a minor issue! Feel free to edit. |
For OctaveCodeGen (pr #7824), I need some refactoring of
Routine
.Routine.__new__
see this comment #7824 (comment)