joschu / cgt

Computation Graph Toolkit
Other
628 stars 87 forks source link

Random number generation and modules (and simplification again) #58

Open sbos opened 8 years ago

sbos commented 8 years ago

It seems that there are still problems with simplification of random number generation operation if they are encapsulated into modules.

The following code prints two last lines equal when simplification is turned on:

import cgt
import cgt.nn as nn

z1 = cgt.randn()
z2 = cgt.randn()

m = nn.Module([cgt.scalar()], [z1, z2])
f = cgt.function([], m([0.]))

print 'A', f()
print 'A', f()

z = cgt.randn(2)
m = nn.Module([cgt.scalar()], [z])

f = cgt.function([], m([0.]) + m([0.]))

print 'B', f()
print 'B', f()