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

Improve build_function for CTarget() #112

Merged
merged 3 commits into from
Mar 12, 2021

Conversation

philbit
Copy link
Contributor

@philbit philbit commented Mar 12, 2021

Consistent function signature for C code generated by build_function (plus valid code in more cases), fixes #106

@philbit philbit changed the title Improve build_function for CTarget() #106 Improve build_function for CTarget() Mar 12, 2021
@philbit
Copy link
Contributor Author

philbit commented Mar 12, 2021

This fixes #106 (i.e. the fourth argument is now a proper scalar both in the C function signature and in the julia function signature), but in the process I noticed that C code generation also suffers from other problems. It's using the regular string representation of julia expressions for code generation which causes problems if C syntax is not similar enough to julia syntax. For example, scalar multiplication a la 4a is not allowed in C, but happens automatically in the string conversion of Expr(:call, :*, 4, :a). Another problem is non-existence of certain operators (e.g., :^).

I addressed the problems I noticed so far with workarounds (still using julia expressions, but modifying them before obtaining their string representation), but in the long run it might be necessary to write a proper C code generation engine. This is more to make build_function usable for more-than-trivial cases at all.

I also added #include <math.h> to the generated C code by default, so special functions like sin and exp can be used.

Tests are included.

@philbit philbit marked this pull request as ready for review March 12, 2021 15:12
@ChrisRackauckas
Copy link
Member

Awesome! Yes, I think the last thing needed really is to setup a find-replace dictionary for a lot of Julia->C translations and then I think it's pretty good. Thanks!

@ChrisRackauckas ChrisRackauckas merged commit 37f2166 into JuliaSymbolics:master Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling of time argument in build_function for CTarget()
2 participants