A draft for a SymPy CCode op is here
https://github.com/Theano/Theano/pull/1486




On Thu, Aug 8, 2013 at 10:20 PM, Frédéric Bastien <no...@nouiz.org> wrote:

> For your codegen.py example, it is easy to reuse it manually in a Theano
> Op. A good example is to look at the GpuEye op (and just pretend the the
> GPU kernel is a CPU one). I don't know of a simpler CPU example that
> demonstrate that:
>
>
> https://github.com/Theano/Theano/blob/master/theano/sandbox/cuda/basic_ops.py#L3421
>
> You put the c function in c_support_code() function and call it with code
> returned by the c_code() fct.
>
> If we want to automate that, we need a way to know the order of the
> parameter passed to the c function if there is more then 1 parameter. Is
> that possible? Ideally, we need to separate the include from the c
> function, but I think it work even if we don't.
>
> About the Theano speed up, the problem is located in the parsing of the
> Theano fct inputs. This is done in pure python code. I think we can always
> use the trust_input=True argument. In the case there is an error, you will
> get an error message that is harder to understands, as it is an op that
> will complain that it have bad input. But you won't be easily able to know
> to witch input it correspond.
>
> It could also happen that you don't pass a good input and there is no
> error. For example if it is used in an op with only python code. But in
> that case, the computation is probably done correctly, but with the input
> object received, not the one specified when compiling the theano function.
> I can't certify this always happen, but I would be surprised to see
> something else being done.
>
> So if you want, just always add trust_input=True, but be ready to have
> uglier error message and remove the flag to have a better error message in
> case you have a problem.
>
> Ideally, Theano should move that to C code, but I don't think it will
> happen shortly.
>
>
> On Thu, Aug 8, 2013 at 7:27 PM, Matthew Rocklin <mrock...@gmail.com>wrote:
>
>> @Fred, what easy things can we do on the Theano side to support
>> performant scalar codes?  Your two tricks above were impressive.  How can
>> we make this behavior default?  Should this happen on the SymPy side or the
>> Theano side (Theano side seems better if there is a place for it).
>>
>>
>> On Thu, Aug 8, 2013 at 4:05 PM, Aaron Meurer <asmeu...@gmail.com> wrote:
>>
>>>
>>>
>>> On Thursday, August 8, 2013, Matthew Rocklin wrote:
>>>
>>>>
>>>>   It should be simple to translate SymPy.Piecewise to a recursive
>>>>>> Theano.switch (after translating SymPy.LT to theano.lt, etc.)  I'll
>>>>>> get on this soon.  Does this sound reasonable to you Fred?
>>>>>>
>>>>>
>>>>> It sound reasonable and is the first thing I suggest to try.
>>>>>
>>>>
>>>> Working on this now.
>>>>
>>>>  > SymPy C Codegen and Theano
>>>>>>
>>>>>> @Fred, how hard would it be to leverage SymPy's C codegen in Theano?
>>>>>>  This might be a lot cleaner than wrapping raw SymPy operations and might
>>>>>> substantially extend Theano's support of scalar expressions.  Do you 
>>>>>> have a
>>>>>> performant Bessel function op?  I'll bet SymPy could be made to do this
>>>>>> quite well.
>>>>>>
>>>>>> @Aaron / @Ondrej, if you're reading this thread could you point us to
>>>>>> the best place to start looking at C codegen in SymPy?  Alternatively can
>>>>>> you point to an active community member who would be able to do so?
>>>>>>
>>>>>>
>>>>> @Matt, you already did a new Theano op with C code. I think it is the
>>>>> only "easy" way to wrap other people c code in Theano. If the person
>>>>> already know this C code AND a little of Python AND NumPy C-API, it isn't
>>>>> very hard to a new Theano op with C code. Otherwise, doing the first such
>>>>> op ask to learn a few think and could ask a few days. You already did 
>>>>> this,
>>>>> so you have a good idea of the work it need.
>>>>>
>>>>> Now the questions is how is done the SymPy code gen? Is just just
>>>>> string template that is filled with dtype and other stuff? If we can just
>>>>> call one SymPy function with the information of what we want and it return
>>>>> a string with the C code it could be relatively easy. The only questions 
>>>>> is
>>>>> about how to handle the variable name to pass the information around. At
>>>>> worst, we wrap the sympy c code in a c function, then make a small wrapper
>>>>> c code that take the Theano c variable name and call this function. So not
>>>>> very hard as Theano provide what is needed.
>>>>>
>>>>
>>>> It looks like codegen is the relevant high-level api call
>>>>
>>>> In [1]: from sympy.utilities.codegen import
>>>>
>>>> In [2]: expr = sin(x)**2
>>>>
>>>> In [3]: [(c_name, c_code), (h_name, c_header)] = codegen(("f", expr),
>>>> 'C', 'test', header=False)
>>>>
>>>> In [4]: print c_code
>>>> #include "test.h"
>>>> #include <math.h>
>>>>
>>>> double f(double x) {
>>>>
>>>>    return pow(sin(x), 2);
>>>>
>>>> }
>>>>
>>>> The work I did rarely dealt with making and using functions.  I'll go
>>>> over past work and see what I can do.  Expect some calls for help though!
>>>>
>>>
>>> If you figure out how to do something that's under-documented, please
>>> document it. Our code generation needs a lot more documentation, especially
>>> high-level narrative documentation.
>>>
>>> Aaron Meurer
>>>
>>>
>>>>   --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "sympy" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to sympy+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to sympy@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/sympy.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "sympy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to sympy+unsubscr...@googlegroups.com.
>>> To post to this group, send email to sympy@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/sympy.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sympy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sympy@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sympy.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to