Skip to content

Instantly share code, notes, and snippets.

@benanne
Created January 4, 2015 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benanne/348c77b112c79f0ce864 to your computer and use it in GitHub Desktop.
Save benanne/348c77b112c79f0ce864 to your computer and use it in GitHub Desktop.
Theano flipping wtf
In [1]: import theano
Using gpu device 0: GeForce GT 540M
In [2]: import theano.tensor as T
In [3]: y = T.tensor4('y')
In [4]: f = theano.function([y], y)
In [5]: theano.printing.debugprint(y)
y [@A]
In [6]: theano.printing.debugprint(f)
DeepCopyOp [@A] 'y' 0
|y [@B]
In [7]: f = theano.function([y], y[::-1])
In [8]: theano.printing.debugprint(f)
HostFromGpu [@A] '' 2
|GpuSubtensor{::int64} [@B] '' 1
|GpuFromHost [@C] '' 0
| |y [@D]
|Constant{-1} [@E]
In [9]: f = theano.function([y], y[::-1][::-1])
In [10]: theano.printing.debugprint(f)
HostFromGpu [@A] '' 12
|GpuSubtensor{int64:int64:int64} [@B] '' 11
|GpuFromHost [@C] '' 1
| |y [@D]
|ScalarFromTensor [@E] '' 9
| |Elemwise{Composite{[Switch(i0, i1, maximum(i2, sub(i3, i4)))]}}[(0, 4)] [@F] '' 7
| |Elemwise{Composite{[LE(sub(i0, i1), i2)]}} [@G] '' 6
| | |Elemwise{Composite{[Switch(LT(*1 -> sub(i0, i1), i2), i2, *1)]}} [@H] '' 4
| | | |Elemwise{Composite{[Switch(LT(i0, i1), i1, i0)]}} [@I] '' 2
| | | | |Shape_i{0} [@J] '' 0
| | | | | |y [@D]
| | | | |TensorConstant{0} [@K]
| | | |Elemwise{Composite{[Switch(LT(*2 -> Composite{[Switch(LT(i0, i1), i1, i0)]}(Composite{[Switch(LT(i0, i1), i2, i0)]}(Composite{[sub(i0, Switch(LT(i1, i2), i2, i1))]}(i0, Composite{[add(i0, int_div(i1, i0))]}(i1, *1 -> add(i2, i0)), i3), i3, *1), i3), i4), *2, i4)]}}[(0, 0)] [@L] '' 3
| | | | |Shape_i{0} [@J] '' 0
| | | | |TensorConstant{1} [@M]
| | | | |TensorConstant{-1} [@N]
| | | | |TensorConstant{0} [@K]
| | | | |Elemwise{Composite{[Switch(LT(i0, i1), i1, i0)]}} [@I] '' 2
| | | |TensorConstant{0} [@K]
| | |Elemwise{Composite{[Switch(LT(*1 -> Composite{[Switch(LT(i0, i1), i1, i0)]}(Composite{[Switch(LT(i0, i1), i2, i0)]}(Composite{[sub(i0, add(i1, Switch(LT(i2, i3), i3, i2)))]}(i0, i1, Composite{[add(i0, int_div(i1, i0))]}(i2, *2 -> Composite{[sub(add(i0, i1), i2)]}(i3, i0, i1)), i4), i4, *2), i4), i5), *1, i5)]}} [@O] '' 5
| | | |Elemwise{Composite{[Switch(LT(i0, i1), i1, i0)]}} [@I] '' 2
| | | |Elemwise{Composite{[Switch(LT(*2 -> Composite{[Switch(LT(i0, i1), i1, i0)]}(Composite{[Switch(LT(i0, i1), i2, i0)]}(Composite{[sub(i0, Switch(LT(i1, i2), i2, i1))]}(i0, Composite{[add(i0, int_div(i1, i0))]}(i1, *1 -> add(i2, i0)), i3), i3, *1), i3), i4), *2, i4)]}}[(0, 0)] [@L] '' 3
| | | |TensorConstant{1} [@M]
| | | |TensorConstant{-1} [@N]
| | | |TensorConstant{0} [@K]
| | | |Elemwise{Composite{[Switch(LT(*1 -> sub(i0, i1), i2), i2, *1)]}} [@H] '' 4
| | |TensorConstant{0} [@K]
| |TensorConstant{0} [@K]
| |Elemwise{Composite{[Switch(LT(*2 -> Composite{[Switch(LT(i0, i1), i1, i0)]}(Composite{[Switch(LT(i0, i1), i2, i0)]}(Composite{[sub(i0, Switch(LT(i1, i2), i2, i1))]}(i0, Composite{[add(i0, int_div(i1, i0))]}(i1, *1 -> add(i2, i0)), i3), i3, *1), i3), i4), *2, i4)]}}[(0, 0)] [@L] '' 3
| |Elemwise{Composite{[Switch(LT(i0, i1), i1, i0)]}} [@I] '' 2
| |Elemwise{Composite{[Switch(LT(*1 -> sub(i0, i1), i2), i2, *1)]}} [@H] '' 4
|ScalarFromTensor [@P] '' 10
| |Elemwise{Composite{[Switch(i0, i1, maximum(i2, sub(i3, i4)))]}}[(0, 2)] [@Q] '' 8
| |Elemwise{Composite{[LE(sub(i0, i1), i2)]}} [@G] '' 6
| |TensorConstant{0} [@K]
| |Elemwise{Composite{[Switch(LT(*2 -> Composite{[Switch(LT(i0, i1), i1, i0)]}(Composite{[Switch(LT(i0, i1), i2, i0)]}(Composite{[sub(i0, Switch(LT(i1, i2), i2, i1))]}(i0, Composite{[add(i0, int_div(i1, i0))]}(i1, *1 -> add(i2, i0)), i3), i3, *1), i3), i4), *2, i4)]}}[(0, 0)] [@L] '' 3
| |Elemwise{Composite{[Switch(LT(i0, i1), i1, i0)]}} [@I] '' 2
| |Elemwise{Composite{[Switch(LT(*1 -> Composite{[Switch(LT(i0, i1), i1, i0)]}(Composite{[Switch(LT(i0, i1), i2, i0)]}(Composite{[sub(i0, add(i1, Switch(LT(i2, i3), i3, i2)))]}(i0, i1, Composite{[add(i0, int_div(i1, i0))]}(i2, *2 -> Composite{[sub(add(i0, i1), i2)]}(i3, i0, i1)), i4), i4, *2), i4), i5), *1, i5)]}} [@O] '' 5
|Constant{1} [@R]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment