# HG changeset patch # User Frederic Bastien # Date 1244597878 14400 # Node ID 0ff7ac3253b351a3d8701834fd2e7b85f6edb7ab # Parent bd95e8ea99d8caefdbb3a16262de709fa5bd95f4 added test for FillMissing op. diff -r bd95e8ea99d8 -r 0ff7ac3253b3 pylearn/sandbox/test_scan_inputs_groups.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylearn/sandbox/test_scan_inputs_groups.py Tue Jun 09 21:37:58 2009 -0400 @@ -0,0 +1,44 @@ +import sys, time, unittest + +import numpy +import numpy as N + +from theano.tests import unittest_tools as utt + +from theano import function, Mode +import theano.tensor as T +from pylearn.sandbox.scan_inputs_groups import FillMissing + + +if __name__ == '__main__': + t = TestConvOp("test_convolution") + t.test_convolution() + t.test_multilayer_conv() + from theano.tests import main + main("test_sp") + +class TestFillMissing(unittest.TestCase): + def setUp(self): + utt.seed_rng() + + def test_base(self): + v=T.dvector() + op=FillMissing()(v) + fct=function([v],op) + + prob=N.random.random(1000) + val=N.random.random(len(prob)) + nb_missing=0 + for i in range(len(val)): + if prob[i]<0.1: + nb_missing+=1 + val[i]=N.nan + + out=fct(val) + for i in range(len(prob)): + if N.isnan(val[i]): + assert out[0][i]==0 + assert out[1][i]==0 + else: + assert out[1][i]==1 +