Discussion:
[theano-users] function output cumsum() vs cumsum() function output
DL_user
2018-10-03 21:09:33 UTC
Permalink
Got another question that can't find guidelines from Theano document.
Consider these two cases:

Case 1:
a = T.dmatrix('a')
b = T.dmatrix('b')
c = T.dmatrix('c')
y = T.pow(a,b)-c
f = theano.function([a,b,c], y)

f(np.reshape(np.ogrid[0:1:4j],(2,2)),np.reshape(np.ogrid[0:1:4j],(2,2)),
np.reshape(np.ogrid[0:1:4j],(2,2))).cumsum()

Case 2:
a = T.dmatrix('a')
b = T.dmatrix('b')
c = T.dmatrix('c')
y = T.pow(a,b)-c
f = theano.function([a,b,c], y.cumsum())

f(np.reshape(np.ogrid[0:1:4j],(2,2)),np.reshape(np.ogrid[0:1:4j],(2,2)),
np.reshape(np.ogrid[0:1:4j],(2,2)))

These two functions have the same output. So it seems theano.function() can
take any (???) Python built-in operators like cumsum()? What else functions
can be blended inside theano.function(), like ufunc or customized functions?
--
---
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Buruk Aregawi
2018-10-04 01:07:02 UTC
Permalink
I believe the way it works is through operator overloading. In python you
can change the behavior of operators. I could explain it more here but
ThePythonGuru has a great write-up on how operator overloading works in
Python: https://thepythonguru.com/python-operator-overloading/

The way it applies to Theano is that Theano tensors and symbolic variables
can override the operators +, *, /, %, <, >, <=, >=, etc. by adding methods
to their object that override/add the behavior you want. The corresponding
methods look like, __add__, __mul__, __truediv__, __mod__, __lt__, etc. I'm
sure it takes a few more tricks to make it work smoothly but I believe this
is the main way that flexibility is implemented.
Post by DL_user
Got another question that can't find guidelines from Theano document.
a = T.dmatrix('a')
b = T.dmatrix('b')
c = T.dmatrix('c')
y = T.pow(a,b)-c
f = theano.function([a,b,c], y)
f(np.reshape(np.ogrid[0:1:4j],(2,2)),np.reshape(np.ogrid[0:1:4j],(2,2)),
np.reshape(np.ogrid[0:1:4j],(2,2))).cumsum()
a = T.dmatrix('a')
b = T.dmatrix('b')
c = T.dmatrix('c')
y = T.pow(a,b)-c
f = theano.function([a,b,c], y.cumsum())
f(np.reshape(np.ogrid[0:1:4j],(2,2)),np.reshape(np.ogrid[0:1:4j],(2,2)),
np.reshape(np.ogrid[0:1:4j],(2,2)))
These two functions have the same output. So it seems theano.function()
can take any (???) Python built-in operators like cumsum()? What else
functions can be blended inside theano.function(), like ufunc or customized
functions?
--
---
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...