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
C code generation line break issue #263
Comments
Thanks for reporting the issue. Can you give an example that will reproduce this error? |
This can probably be solved by setting Lines 35 to 48 in df1e7fe
|
@blumenta Please provide an small example that demonstrates this bug, otherwise it is difficult for us to track it down. |
Hi, sorry I have been trying to reproduce the bug in a small example but haven't been able to do so. It occurs in the code I'm working on, but I'm kind of in a bind because I am not currently allowed to distribute it. Maybe I could save the problematic expression in a text file directly and then have a script that loads it and runs the C code generator on it. I'll get back to you |
Thanks for the update. If you can save the expression to the text file that
|
Hi, you will find attached source code that reproduces the bug. I saved the Alejandro 2015-10-09 12:15 GMT+02:00 Oliver Lee notifications@github.com:
|
I think you forgot to attach the files (or maybe you can't do so by email). |
@blumenta Please email to the pydy list (or our personal email address) or make a gist or something with the code. |
Text wrap doesn't know that it can insert newlines after multiplication or division operators. We see output like this: double pydy_1462 = (1.0L/8.0L)*input_1[1]*pydy_1317*pydy_25*pydy_29*pydy_41
1*pydy_63*pydy_78*pydy_99; and this: double pydy_1462 = (1.0L/8.0L)*input_1[1]*pydy_1317*pydy_25*pydy_29*pydy_41
1*pydy_63*pydy_78*pydy_99; |
Some generated expressions, particularly those that contain only '*' and '/' operands, have no whitespace. In this case, the textwrap module may break the line in the middle of a symbol or mathematical expression if the line is long, resulting in code that cannot compile. This commit adds whitespace before and after the '*', '/' operands so that textwrap will have more options for inserting line breaks. The textwrap option 'break_long_words' is also set to True, allowing long lines in the event that no whitespace is present. This commit resolves pydy#263.
Fixed here: #292 |
Some generated expressions, particularly those that contain only '*' and '/' operands, have no whitespace. In this case, the textwrap module may break the line in the middle of a symbol or mathematical expression if the line is long, resulting in code that cannot compile. This commit adds whitespace before and after the '*', '/' operands so that textwrap will have more options for inserting line breaks. The textwrap option 'break_long_words' is also set to True, allowing long lines in the event that no whitespace is present. This commit resolves pydy#263.
@blumenta Can you verify that this patch fixes things for you? |
Some generated expressions, particularly those that contain only '*' and '/' operands, have no whitespace. In this case, the textwrap module may break the line in the middle of a symbol or mathematical expression if the line is long, resulting in code that cannot compile. This commit adds whitespace before and after the '*', '/' operands so that textwrap will have more options for inserting line breaks. The textwrap option 'break_long_words' is also set to True, allowing long lines in the event that no whitespace is present. This commit resolves pydy#263.
Some generated expressions, particularly those that contain only '*' and '/' operands, have no whitespace. In this case, the textwrap module may break the line in the middle of a symbol or mathematical expression if the line is long, resulting in code that cannot compile. This commit adds whitespace before and after the '*', '/' operands so that textwrap will have more options for inserting line breaks. The textwrap option 'break_long_words' is also set to True, allowing long lines in the event that no whitespace is present. This commit resolves pydy#263.
Hi, I just tested it and it works perfectly, nice work. 2015-10-20 19:35 GMT+02:00 Jason K. Moore notifications@github.com:
|
Some generated expressions, particularly those that contain only '*' and '/' operands, have no whitespace. In this case, the textwrap module may break the line in the middle of a symbol or mathematical expression if the line is long, resulting in code that cannot compile. This commit adds whitespace before and after the '*', '/' operands so that textwrap will have more options for inserting line breaks. The textwrap option 'break_long_words' is also set to True, allowing long lines in the event that no whitespace is present. This commit resolves pydy#263.
Some generated expressions, particularly those that contain only '*' and '/' operands, have no whitespace. In this case, the textwrap module may break the line in the middle of a symbol or mathematical expression if the line is long, resulting in code that cannot compile. This commit adds whitespace before and after the '*', '/' operands so that textwrap will have more options for inserting line breaks. The textwrap option 'break_long_words' is also set to True, allowing long lines in the event that no whitespace is present. This commit resolves pydy#263.
Fix codegen line break. This resolves #263.
Hello, while using CythonMatrixGenerator and CMatrixGenerator I stumbled upon the following issue:
the generated C code appears to have some undesirable line breaks which render the code uncompilable. For example, this generated statement
double pydy_2382 = (1.0L/4.0L)pydy_1930pydy_203pydy_204pydy_2339pydy_2
95pydy_345*pydy_60;
yields the following gcc error:
error: expected ‘,’ or ‘;’ before numeric constant
95pydy_345pydy_60;
Of course there shouldn't be a line break in the middle of the variable name pydy_295. That happens when attempting to compile the C code on my own. When I try using the CythonMatrixGenerator.compile() method, the Exception('Failed to compile and import Cython module.') is raised, I guess because of the same issue.
For now I managed to correct the generated c code manually since there are only 2 occurrences of this error, but maybe this is an issue that could be easily fixed in pydy.
Thanks in advance,
Alejandro
The text was updated successfully, but these errors were encountered: