-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Added the cumsum and cumprod functions similar to numpy's ones. #1700
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
Conversation
In the file theano/tensor/init.py import cumsum to have it available as the numpy interface theano.tensor.cumsum vs numpy.cumsum. |
Thanks for this PR! I did some small comment. They are very simple thing and in fact except for the import in tensor/init.py, they are small update that the user won't see, but doing them would be great. Just tell me if you will do them or not. thanks |
I'm working on it. Also, I was waiting for some feedback before I pushed the |
In the end it is your choise. If the delay is short, it can be simpler for On Tue, Jan 28, 2014 at 10:15 AM, Marc-Alexandre Côté <
|
Regarding Theano garbage collector, how can I make sure it is disabled? I printed the address of %(z)s and it always (nil) upon entering the c function. I tried compiling the theano function with
The output: |
Ok, I was wrong, I should have used cumsum(x).sum() to have an intermediate result. |
Another way to test it is to run with thoses 2 Theano flags: mode=DebugMode,DebugMode.check_preallocated_output=ALL This will explicitly test many type of preallocated outputs like if it was On Tue, Jan 28, 2014 at 12:09 PM, Marc-Alexandre Côté <
|
assert np.allclose(np.cumsum(a), f(a)) # Test axis=None | ||
|
||
# Test without garbage collector | ||
f = theano.function([x], cumsum(x).sum(), mode=theano.compile.Mode(linker="cvm_nogc", optimizer="fast_run") ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added these flags (mode=DebugMode,DebugMode.check_preallocated_output=ALL) in my .theanorc. Then changed cumsum(x).sum()
to cumsum(x)
. When I run the tests, it still prints (nil) each time the C function is called.
Maybe I didn't understand what @nouiz said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the theanorc file, they should be like this:
[global]
mode=DebugMode
[DebugMode]
check_preallocated_output=ALL
The syntax isn't the same, but it is related.
On Tue, Jan 28, 2014 at 4:08 PM, Marc-Alexandre Côté <
notifications@github.com> wrote:
In theano/tensor/tests/test_extra_ops.py:
- def setUp(self):
super(TestCumsumOp, self).setUp()
self.op_class = CumsumOp
self.op = CumsumOp()
- def test_cumsumOp(self):
x = T.tensor3('x')
a = np.random.random((3, 5, 2)).astype(config.floatX)
b = np.random.random((30, 5, 2)).astype(config.floatX)
f = theano.function([x], cumsum(x), mode="DebugMode")
assert np.allclose(np.cumsum(a), f(a)) # Test axis=None
# Test without garbage collector
f = theano.function([x], cumsum(x).sum(), mode=theano.compile.Mode(linker="cvm_nogc", optimizer="fast_run") )
I've added these flags
(mode=DebugMode,DebugMode.check_preallocated_output=ALL) in my .theanorc.
Then changed cumsum(x).sum() to cumsum(x). When I run the tests, it still
prints (nil) each time the C function is called.Maybe I didn't understand what @nouiz https://github.com/nouiz said.
Reply to this email directly or view it on GitHubhttps://github.com//pull/1700/files#r9244612
.
Ok I got it. So I changed the unit tests to use |
Hmm don't know what went wrong with Travis. |
The travis problem is not related to this PR. It is a temporary problem that is normally fixed by restarting the test job. I wasn't clear when I talked about check_preallocated_output. We don't want to run all test by default in DebugMode with that parameter, as this make it too long. I just wanted you to run in locally, not update the test to use it. Can you remove your last commit? This made me see one think that I missed. In test, we normally should use the default mode and not force DebugMode. So can you just remove the mode parameter when you call theano.function()? Otherwise the tests will be too slow by default. Our daily buildbot run all tests with DebugMode. |
Even though it passed the tests with check_preallocated_output, should we not check that strides match in addition to the shape when wrapping the xdecref/allocation? I asked that because I'm implementing a personal Op and it was causing memory error when omitting the strides check. EDIT: It might have something to do with my personnal Op printing warning message about Stride mismatch! |
This depend if the code depend of the strides. I suppose in your personnal In this case, PyArray_CumSum() don't do that supposition and check the On Wed, Jan 29, 2014 at 1:16 PM, Marc-Alexandre Côté <
|
Thanks, I merge it. @jsalvatier thanks for the first version. It is now merged in Theano. |
Added the cumsum and cumprod functions similar to numpy's ones.
This PR adds a cumsum Op which is a wrapper to one from numpy.
Grad is working for any Nd case.
Related to issue #1080
Based on @jsalvatier's gist: https://gist.github.com/jsalvatier/8378901
NEWS.txt: