Thanks for the idea. At a few places, we allow to pass return_list=True to force the return a of list. I added that option to scan in that PR:
https://github.com/Theano/Theano/pull/5420 Why we don't always return a list? It is because the best interface depend of what you want. If you use Theano normally not returning a list is better, but when you try to automatize stuff, always having a list is better. That is why we provide both at a few places. Can you confirm this do what you want? Fred On Mon, Jan 16, 2017 at 9:59 AM, Peter O'Connor <peter.ed.ocon...@gmail.com> wrote: > Hi all. > > There's some really unintuitive/inconsistent behaviour with theano's scan > and I'm wondering how I should work around it. > > Take the following test, which I would expect to pass: > > import theano > import theano.tensor as tt > > > def test_scan_tuple_output(): > > x = tt.matrix() > > def mul_by_2_and_3(data): > return (data*2, data*3) > > y, updates = theano.scan(mul_by_2_and_3, sequences=[x]) > > assert len(y)==2 > assert len(updates)==0 > > def mul_by_2(data): > return (data*2, ) > > y, updates = theano.scan(mul_by_2, sequences = [x]) > > assert len(y)==1 > assert len(updates) == 0 > > > if __name__ == '__main__': > test_scan_tuple_output() > > It fails on > It > It fails on > > assert len(y)==1 > > with "TypeError: object of type 'TensorVariable' has no len()" because if > scan detects a tuple of length-1, it just returns the data inside this > tuple. > > This becomes annoying when trying to make a scannable function with > variable return length, (one of which can be one). > > Is there a way I can make scan not totally change its behaviour when the > tuple of returned arguments happens to have length 1? > > -- > > --- > 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. > -- --- 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.