Nevermind, I figured it out. I had to disable constant folding and wrap 
with tensor.elemwise.

On Sunday, March 5, 2017 at 10:28:39 AM UTC+8, Adam Becker wrote:
>
> Hi,
>
> I'm writing a elemwise Op with special purpose, it's c_code should be 
> different when it's working with tensor objects. (Actually, it's for 
> gh:#5471 <https://github.com/Theano/Theano/issues/5471>)
>
> Current I'm only working with the CPU version.
>
> Here's the approach I'm taking so far, I modified this line in 
> tensor/elemwise.py 
> <https://github.com/Theano/Theano/blob/master/theano/tensor/elemwise.py#L946> 
> into:
>
> defines = "#define TENSOR_ELEMWISE"
> undefs = "#undef TENSOR_ELEMWISE"
>
> The elemwise Op looks like:
>
> class MyOp(scalar.ScalarOp):
>     nin = 0
>     # < ... >
>     def c_code(self, node, name, inputs, outputs, sub):
>         out, = outputs
>         op_name = type(self).__name__
>         code = '''
>         #ifndef TENSOR_ELEMWISE
>         %(out)s = 1227;
>         #else
>         %(out)s = 1337;
>         #endif
>         ''' % locals()
>         return code
>
> However, even though I build a graph with matrix input, the elemwise Op 
> still takes the "1227" branch.
> Further investigation of generated code shows MyOp is compiled into a 
> separate mod.cpp than the main elemwise loop.
>
> I suppose this could be due to a few optimizations. However, as I'm still 
> unfamiliar with opt code base, I couldn't figure out where.
>
> Any clue how to force the c_code of MyOp into the elemwise loop, so that 
> the "1337" branch will be taken when dealing with tensor?
>
> Thanks.
>
>

-- 

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

Reply via email to