annotate test_dataset.py @ 84:aa9e786ee849

added function have_raised that evaluate the string in parameter and return true if the function have raised an exception code cleanup and renaming added a few test
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 05 May 2008 11:49:40 -0400
parents 158653a9bc7c
children fdf72ea4f2bc
rev   line source
51
59757365a057 the script can be autorun
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 45
diff changeset
1 #!/bin/env python
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
2 from dataset import *
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
3 from math import *
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
4 import numpy
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
5
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
6 def have_raised(to_eval):
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
7 have_thrown = False
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
8 try:
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
9 eval(to_eval)
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
10 except :
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
11 have_thrown = True
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
12 return have_thrown
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
13
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
14 def test1():
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
15 print "test1"
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
16 global a,ds
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
17 a = numpy.random.rand(10,4)
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
18 print a
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
19 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
20 print "len(ds)=",len(ds)
54
70147d00615a added assert
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 52
diff changeset
21 assert(len(ds)==10)
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
22 print "example 0 = ",ds[0]
54
70147d00615a added assert
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 52
diff changeset
23 # assert
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
24 print "x=",ds["x"]
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
25 print "x|y"
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
26 for x,y in ds("x","y"):
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
27 print x,y
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
28 minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4)
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
29 minibatch = minibatch_iterator.__iter__().next()
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
30 print "minibatch=",minibatch
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
31 for var in minibatch:
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
32 print "var=",var
48
b6730f9a336d Fixing MinibatchDataSet getitem
bengioy@grenat.iro.umontreal.ca
parents: 45
diff changeset
33 print "take a slice and look at field y",ds[1:6:2]["y"]
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
34
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
35 def test_ArrayDataSet():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
36 #don't test stream
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
37 #tested only with float value
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
38 #test with y too
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
39 #test missing value
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
40
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
41 print "test_ArrayDataSet"
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
42 a = numpy.random.rand(10,4)
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
43 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
44 assert len(ds)==10
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
45 #assert ds==a? should this work?
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
46 for i in range(len(ds)):
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
47 assert ds[i]['x'].all()==a[i][:2].all()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
48 assert ds[i]['y']==a[i][3]
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
49 assert ds[i]['z'].all()==a[i][0:3:2].all()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
50 i=0
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
51 for x in ds('x','y'):
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
52 assert numpy.append(x['x'],x['y']).all()==a[i].all()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
53 i+=1
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
54
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
55 i=0
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
56 for x,y in ds('x','y'):
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
57 assert numpy.append(x,y).all()==a[i].all()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
58 i+=1
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
59 for minibatch in ds.minibatches(['x','z'], minibatch_size=3):
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
60 assert minibatch[0][:,0:3:2].all()==minibatch[1].all()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
61 for x,z in ds.minibatches(['x','z'], minibatch_size=3):
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
62 assert x[:,0:3:2].all()==z.all()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
63
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
64 # for minibatch in ds.minibatches(['z','y'], minibatch_size=3):
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
65 # print minibatch
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
66 # minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4)
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
67 # minibatch = minibatch_iterator.__iter__().next()
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
68 # print "minibatch=",minibatch
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
69 # for var in minibatch:
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
70 # print "var=",var
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
71 # print "take a slice and look at field y",ds[1:6:2]["y"]
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
72 assert have_raised("ds['h']") # h is not defined...
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
73 assert have_raised("ds[['h']]") # h is not defined...
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
74
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
75 assert len(ds.fields())==3
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
76 for field in ds.fields():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
77 for field_value in field: # iterate over the values associated to that field for all the ds examples
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
78 pass
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
79 for field in ds('x','z').fields():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
80 pass
60
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 58
diff changeset
81 for field in ds.fields('x','y'):
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
82 pass
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
83 for field_examples in ds.fields():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
84 for example_value in field_examples:
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
85 pass
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
86
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
87 assert ds == ds.fields().examples()
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
88
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
89
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
90 #ds[:n] returns a dataset with the n first examples.
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
91 assert len(ds[:3])==3
66
dde1fb1b63ba fixed test and removed print
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 65
diff changeset
92 i=0
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
93 for x,z,y in ds[:3]('x','z','y'):
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
94 assert ds[i]['x'].all()==a[i][:3].all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
95 assert ds[i]['x'].all()==x.all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
96 assert ds[i]['y']==a[i][3]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
97 assert ds[i]['y']==y
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
98 assert ds[i]['z'].all()==a[i][0:3:2].all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
99 assert ds[i]['z'].all()==z.all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
100 i+=1
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
101 i=0
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
102 for x,z in ds[:3]('x','z'):
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
103 assert ds[i]['z'].all()==a[i][0:3:2].all()
66
dde1fb1b63ba fixed test and removed print
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 65
diff changeset
104 i+=1
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
105
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
106 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s.
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
107 ds[1:7:2][1]
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
108 assert len(ds[1:7:2])==3 # should be number example 1,3 and 5
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
109 i=0
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
110 index=[1,3,5]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
111 for z,y,x in ds[1:7:2]('z','y','x'):
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
112 assert ds[index[i]]['x'].all()==a[index[i]][:3].all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
113 assert ds[index[i]]['x'].all()==x.all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
114 assert ds[index[i]]['y']==a[index[i]][3]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
115 assert ds[index[i]]['y']==y
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
116 assert ds[index[i]]['z'].all()==a[index[i]][0:3:2].all()
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
117 assert ds[index[i]]['z'].all()==z.all()
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
118 i+=1
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
119
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
120 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in.
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
121 i=0
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
122 for x in ds[[1,2]]:
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
123 assert numpy.append(x['x'],x['y']).all()==a[i].all()
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
124 i+=1
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
125 #ds[i1,i2,...]# should we accept????
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
126 #ds[fieldname]# an iterable over the values of the field fieldname across
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
127 #the ds (the iterable is obtained by default by calling valuesVStack
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
128 #over the values for individual examples).
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
129
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
130 #ds.<property># returns the value of a property associated with
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
131 #the name <property>. The following properties should be supported:
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
132 # - 'description': a textual description or name for the ds
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
133 # - 'fieldtypes': a list of types (one per field)
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
134 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
135 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
136
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
137 # for (x,y) in (ds('x','y'),a): #don't work # haven't found a variant that work.
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
138 # assert numpy.append(x,y)==z
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
139
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
140 def test_LookupList():
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
141 #test only the example in the doc???
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
142 print "test_LookupList"
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
143 example = LookupList(['x','y','z'],[1,2,3])
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
144 example['x'] = [1, 2, 3] # set or change a field
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
145 x, y, z = example
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
146 x = example[0]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
147 x = example["x"]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
148 assert example.keys()==['x','y','z']
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
149 assert example.values()==[[1,2,3],2,3]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
150 assert example.items()==[('x',[1,2,3]),('y',2),('z',3)]
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
151 example.append_keyval('u',0) # adds item with name 'u' and value 0
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
152 assert len(example)==4 # number of items = 4 here
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
153 example2 = LookupList(['v','w'], ['a','b'])
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
154 example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b'])
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
155 assert example+example2==example3
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
156 assert have_raised("example+example")
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
157
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
158 def test_ApplyFunctionDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
159 print "test_ApplyFunctionDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
160 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
161 def test_CacheDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
162 print "test_CacheDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
163 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
164 def test_FieldsSubsetDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
165 print "test_FieldsSubsetDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
166 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
167 def test_DataSetFields():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
168 print "test_DataSetFields"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
169 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
170 def test_MinibatchDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
171 print "test_MinibatchDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
172 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
173 def test_HStackedDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
174 print "test_HStackedDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
175 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
176 def test_VStackedDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
177 print "test_VStackedDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
178 raise NotImplementedError()
84
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
179 def test_ArrayFieldsDataSet():
aa9e786ee849 added function have_raised that evaluate the string in parameter and return true if the function have raised an exception
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 82
diff changeset
180 print "test_ArrayFieldsDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
181 raise NotImplementedError()
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
182
74
b4159cbdc06b Fixed errors raised by test_dataset
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 66
diff changeset
183 test1()
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
184 test_LookupList()
65
d48eba49a2f4 fixed the infinite loop
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 64
diff changeset
185 test_ArrayDataSet()
64
863da25a60f1 trying to fix infinite loop
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 63
diff changeset
186
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
187
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
188