sympy / scipy-2017-codegen-tutorial

SymPy code generation tutorial at SciPy 2017
http://www.sympy.org/scipy-2017-codegen-tutorial/
Other
61 stars 26 forks source link

Addressing the objective that students see how to incoporate external C libraries #10

Closed moorepants closed 7 years ago

moorepants commented 7 years ago

Currently the Sundials examples have a large amount of overhead (C templates, etc) which is hidden to the student. The notebook is mostly a demonstration of the speed gains one can get from integrating the equations without any Python callbacks and using a third party C lib.

I mentioned to Bjorn my original intention when adding this objective to the tutorial proposal on gitter, which was:

when we originally wrote "show how to include 3rd party libs" I was thinking of something more like: 1) have an existing bit of generated code that works, 2) identify an operation in that code that could be done with an external lib (perhaps a matrix operation or a specialized math function, etc), and then 3) have them print a sympy subexpression using the new libs function name, include the lib's header, and supply one or two linker flags.

Bjorn then mentions cephes:

My suggestion would be that we show how to use a cephes function for this learning objective. It could be as simple as using powi from cephes instead of pow from the C math.

We could then leave Bjorn's sundials code as a demo for the end of the tutorial, i.e. to show off what is possible.

bjodah commented 7 years ago

Looking into cephes it looked a bit tricky to compile on Windows (didn't actually try though). I will look into using this: https://github.com/romeric/fastapprox/blob/master/fastapprox/src/fastexp.h#L64

moorepants commented 7 years ago

Where would we plan to put this. We currently don't have a explicit location for it in the outline anymore. Would this example be appropriate for @ixjlyons's section since his is the only one that is compiling code explicitly?

bjodah commented 7 years ago

Sure, why not?

moorepants commented 7 years ago

So we are going to try to get these into 1.1:

https://github.com/sympy/sympy/pull/9001 https://github.com/sympy/sympy/pull/12833

This will allow us to subclass the C printer with the fastexp function.

bjodah commented 7 years ago

Once the fastexp example using autowrap is in (and notebooks/55-C-calling-3rd-party-lib.ipynb hidden) this can be closed.

moorepants commented 7 years ago

Kenny's working on incorporating this into the third section of his notebook. So I think we are good. Nice that we got that working. Really makes autowrap quite a bit more useful.

ixjlyons commented 7 years ago

Yeah I've got it just about there but I haven't committed yet so CI isn't broken. Now we're on the release candidate I'll push up my progress later today or tomorrow morning.