-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Make sure the output of julia_code
is reasonable and correct.
#23736
Comments
If you know your variables are matrices and you want to perform matrix operations, you should use SymPy's MatrixExpr classes to represent that. This looks correct: >>> x = MatrixSymbol('x', n, n)
>>> y = MatrixSymbol('y', n, n)
>>> julia_code(x*y)
'x*y'
>>> x, y = symbols('x y')
>>> julia_code(x*y)
'x.*y' Generally speaking, SymPy is going to generate code for expressions assuming they represent the thing they represent in SymPy (except a scalar I think the concern is that if you know that your variables are scalars, then the dot notation is unnecessary. It wasn't exactly clear to me if it actually matters for performance (if I understand #23667 (comment) correctly, it doesn't). One could argue that it's unreadable to use the dots when they are unnecessary, i.e., when the variables are scalars instead of arrays. Or if you use the Actually I just tested it and it looks like
Alternately, the second and third could be combined and it can just use I would suggest making the second of these the default since that's already the current behavior and since that should automatically work in all cases. But I'm not really a use of julia_code or even Julia, so your feedback on this would be appreciated. |
Thank you for your reply!
The performance issues are due to my bad use of Julia Benchmark, so I guess we can ignore the difference in performance ( And in most cases there will be no difference in performance ).
Yes,
I agree that it is better to extend other output styles with Flag without changing the existing default output styles.
We will normally use |
Sorry. I didn't see this issue before leaving this comment. I think Aaron's three options sound good. The only thing I would add is that rather than failing, option 3 could just provide the ugly translations |
Thank you! I think I'd like to work on this. |
When I fixed the issue #23667 , I found that the output of Julia_code was not quite right at the moment.
The default printer will use the vectorized
"dot" operator
to print julia code when use binary operators and the arg is not a number.For example:
I am not sure if we should use
"dot" operator
on all possible mathematical operations to make sure it is compatible with the vectorization in Julia.If we do this, probably any mathematical function will have to print a
"dot" operator
that looks a bit strange, although in Julia it is not necessary, for example:I think it's up to users to decide whether they want
.*
or*
, depending on what type x and y are in Julia.We just need to return a correct and beautiful Julia expression
x * y
, its specific behavior is determined by the user in Julia:As @moble said in #23729 (review), we can also use
@.
macro in Julia to give the user the option to make all of the operations in the current expression vectorized, for example:The text was updated successfully, but these errors were encountered: