annotate test_dataset.py @ 158:90104343c665

typo
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Mon, 12 May 2008 16:24:59 -0400
parents e8c8022582f4
children 60e00cce3492
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
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
6 def have_raised(to_eval, **var):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
7
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
8 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
9 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
10 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
11 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
12 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
13 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
14
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
15 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
16 print "test1"
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
17 global a,ds
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
18 a = numpy.random.rand(10,4)
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
19 print a
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
20 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
21 print "len(ds)=",len(ds)
54
70147d00615a added assert
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 52
diff changeset
22 assert(len(ds)==10)
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
23 print "example 0 = ",ds[0]
54
70147d00615a added assert
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 52
diff changeset
24 # assert
45
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
25 print "x=",ds["x"]
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
26 print "x|y"
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
27 for x,y in ds("x","y"):
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
28 print x,y
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
29 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
30 minibatch = minibatch_iterator.__iter__().next()
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
31 print "minibatch=",minibatch
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
32 for var in minibatch:
a5c70dc42972 Test functions for dataset.py
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
33 print "var=",var
48
b6730f9a336d Fixing MinibatchDataSet getitem
bengioy@grenat.iro.umontreal.ca
parents: 45
diff changeset
34 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
35
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
36 def test_iterate_over_examples(array,ds):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
37 #not in doc!!!
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
38 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
39 for example in range(len(ds)):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
40 assert (ds[example]['x']==array[example][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
41 assert ds[example]['y']==array[example][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
42 assert (ds[example]['z']==array[example][[0,2]]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
43 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
44 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
45 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
46
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
47 # - for example in dataset:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
48 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
49 for example in ds:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
50 assert len(example)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
51 assert (example['x']==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
52 assert example['y']==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
53 assert (example['z']==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
54 assert (numpy.append(example['x'],example['y'])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
55 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
56 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
57 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
58
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
59 # - for val1,val2,... in dataset:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
60 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
61 for x,y,z in ds:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
62 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
63 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
64 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
65 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
66 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
67 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
68 del x,y,z,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
69
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
70 # - for example in dataset(field1, field2,field3, ...):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
71 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
72 for example in ds('x','y','z'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
73 assert len(example)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
74 assert (example['x']==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
75 assert example['y']==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
76 assert (example['z']==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
77 assert (numpy.append(example['x'],example['y'])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
78 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
79 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
80 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
81 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
82 for example in ds('y','x'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
83 assert len(example)==2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
84 assert (example['x']==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
85 assert example['y']==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
86 assert (numpy.append(example['x'],example['y'])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
87 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
88 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
89 del example,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
90
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
91 # - for val1,val2,val3 in dataset(field1, field2,field3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
92 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
93 for x,y,z in ds('x','y','z'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
94 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
95 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
96 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
97 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
98 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
99 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
100 del x,y,z,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
101 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
102 for y,x in ds('y','x',):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
103 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
104 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
105 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
106 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
107 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
108 del x,y,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
109
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
110 def test_minibatch_size(minibatch,minibatch_size,len_ds,nb_field,nb_iter_finished):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
111 ##full minibatch or the last minibatch
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
112 for idx in range(nb_field):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
113 test_minibatch_field_size(minibatch[idx],minibatch_size,len_ds,nb_iter_finished)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
114 del idx
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
115 def test_minibatch_field_size(minibatch_field,minibatch_size,len_ds,nb_iter_finished):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
116 assert len(minibatch_field)==minibatch_size or ((nb_iter_finished*minibatch_size+len(minibatch_field))==len_ds and len(minibatch_field)<minibatch_size)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
117
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
118 # - for minibatch in dataset.minibatches([field1, field2, ...],minibatch_size=N):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
119 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
120 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
121 m=ds.minibatches(['x','z'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
122 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
123 for minibatch in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
124 assert len(minibatch)==2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
125 test_minibatch_size(minibatch,m.minibatch_size,len(ds),2,mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
126 assert (minibatch[0][:,0:3:2]==minibatch[1]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
127 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
128 i+=len(minibatch[0])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
129 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
130 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
131 del minibatch,i,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
132
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
133 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
134 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
135 m=ds.minibatches(['x','y'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
136 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
137 for minibatch in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
138 assert len(minibatch)==2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
139 test_minibatch_size(minibatch,m.minibatch_size,len(ds),2,mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
140 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
141 for id in range(len(minibatch[0])):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
142 assert (numpy.append(minibatch[0][id],minibatch[1][id])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
143 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
144 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
145 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
146 del minibatch,i,id,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
147
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
148 # - for mini1,mini2,mini3 in dataset.minibatches([field1, field2, field3], minibatch_size=N):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
149 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
150 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
151 m=ds.minibatches(['x','z'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
152 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
153 for x,z in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
154 test_minibatch_field_size(x,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
155 test_minibatch_field_size(z,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
156 assert (x[:,0:3:2]==z).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
157 i+=len(x)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
158 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
159 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
160 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
161 del x,z,i,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
162 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
163 mi=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
164 m=ds.minibatches(['x','y'], minibatch_size=3)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
165 for x,y in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
166 test_minibatch_field_size(x,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
167 test_minibatch_field_size(y,m.minibatch_size,len(ds),mi)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
168 mi+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
169 for id in range(len(x)):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
170 assert (numpy.append(x[id],y[id])==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
171 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
172 assert i==len(ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
173 assert mi==4
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
174 del x,y,i,id,m,mi
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
175
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
176 #not in doc
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
177 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
178 m=ds.minibatches(['x','y'],n_batches=1,minibatch_size=3,offset=4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
179 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
180 for x,y in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
181 assert len(x)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
182 assert len(y)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
183 for id in range(3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
184 assert (numpy.append(x[id],y[id])==array[i+4]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
185 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
186 assert i==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
187 del x,y,i,id,m
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
188
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
189 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
190 m=ds.minibatches(['x','y'],n_batches=2,minibatch_size=3,offset=4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
191 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
192 for x,y in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
193 assert len(x)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
194 assert len(y)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
195 for id in range(3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
196 assert (numpy.append(x[id],y[id])==array[i+4]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
197 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
198 assert i==6
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
199 del x,y,i,id,m
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
200
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
201 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
202 m=ds.minibatches(['x','y'],n_batches=20,minibatch_size=3,offset=4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
203 assert isinstance(m,DataSet.MinibatchWrapAroundIterator)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
204 for x,y in m:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
205 assert len(x)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
206 assert len(y)==3
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
207 for id in range(3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
208 assert (numpy.append(x[id],y[id])==array[(i+4)%array.shape[0]]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
209 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
210 assert i==m.n_batches*m.minibatch_size
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
211 del x,y,i,id
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
212
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
213
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
214 def test_ds_iterator(array,iterator1,iterator2,iterator3):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
215 l=len(iterator1)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
216 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
217 for x,y in iterator1:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
218 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
219 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
220 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
221 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
222 assert i==l
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
223 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
224 for y,z in iterator2:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
225 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
226 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
227 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
228 assert i==l
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
229 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
230 for x,y,z in iterator3:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
231 assert (x==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
232 assert y==array[i][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
233 assert (z==array[i][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
234 assert (numpy.append(x,y)==array[i]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
235 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
236 assert i==l
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
237
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
238 def test_getitem(array,ds):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
239 def test_ds(orig,ds,index):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
240 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
241 assert len(ds)==len(index)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
242 for x,z,y in ds('x','z','y'):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
243 assert (orig[index[i]]['x']==array[index[i]][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
244 assert (orig[index[i]]['x']==x).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
245 assert orig[index[i]]['y']==array[index[i]][3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
246 assert orig[index[i]]['y']==y
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
247 assert (orig[index[i]]['z']==array[index[i]][0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
248 assert (orig[index[i]]['z']==z).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
249 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
250 del i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
251 ds[0]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
252 if len(ds)>2:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
253 ds[:1]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
254 ds[1:1]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
255 ds[1:1:1]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
256 if len(ds)>5:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
257 ds[[1,2,3]]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
258 for x in ds:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
259 pass
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
260
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
261 #ds[:n] returns a dataset with the n first examples.
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
262 ds2=ds[:3]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
263 assert isinstance(ds2,DataSet)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
264 test_ds(ds,ds2,index=[0,1,2])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
265 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
266
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
267 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s.
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
268 ds2=ds[1:7:2]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
269 assert isinstance(ds2,DataSet)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
270 test_ds(ds,ds2,[1,3,5])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
271 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
272
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
273 #ds[i]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
274 ds2=ds[5]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
275 assert isinstance(ds2,Example)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
276 assert have_raised("var['ds']["+str(len(ds))+"]",ds=ds) # index not defined
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
277 assert not have_raised("var['ds']["+str(len(ds)-1)+"]",ds=ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
278 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
279
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
280 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in.
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
281 ds2=ds[[4,7,2,8]]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
282 assert isinstance(ds2,DataSet)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
283 test_ds(ds,ds2,[4,7,2,8])
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
284 del ds2
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
285
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
286 #ds[fieldname]# an iterable over the values of the field fieldname across
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
287 #the ds (the iterable is obtained by default by calling valuesVStack
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
288 #over the values for individual examples).
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
289 assert have_raised("ds['h']") # h is not defined...
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
290 assert have_raised("ds[['x']]") # bad syntax
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
291 assert not have_raised("var['ds']['x']",ds=ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
292 isinstance(ds['x'],DataSetFields)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
293 ds2=ds['x']
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
294 assert len(ds['x'])==10
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
295 assert len(ds['y'])==10
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
296 assert len(ds['z'])==10
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
297 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
298 for example in ds['x']:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
299 assert (example==array[i][:3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
300 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
301 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
302 for example in ds['y']:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
303 assert (example==array[i][3]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
304 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
305 i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
306 for example in ds['z']:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
307 assert (example==array[i,0:3:2]).all()
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
308 i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
309 del ds2,i
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
310
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
311 #ds.<property># returns the value of a property associated with
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
312 #the name <property>. The following properties should be supported:
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
313 # - 'description': a textual description or name for the ds
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
314 # - 'fieldtypes': a list of types (one per field)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
315
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
316 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#????
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
317 #hstack([ds('x','y'),ds('z')]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
318 #hstack([ds('z','y'),ds('x')]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
319 #assert have_thrown("hstack([ds('x'),ds('x')]")
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
320 #assert not have_thrown("hstack([ds('x'),ds('x')]")
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
321 #accept_nonunique_names
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
322 #assert have_thrown("hstack([ds('y','x'),ds('x')]")
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
323 # i=0
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
324 # for example in hstack([ds('x'),ds('y'),ds('z')]):
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
325 # example==ds[i]
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
326 # i+=1
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
327 # del i,example
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
328 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#????
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
329
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
330
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
331 def test_ArrayDataSet():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
332 #don't test stream
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
333 #tested only with float value
106
cf9bdb1d9656 added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 104
diff changeset
334 #don't always test with y
cf9bdb1d9656 added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 104
diff changeset
335 #don't test missing value
cf9bdb1d9656 added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 104
diff changeset
336 #don't test with tuple
cf9bdb1d9656 added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 104
diff changeset
337 #don't test proterties
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
338 print "test_ArrayDataSet"
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
339 a2 = numpy.random.rand(10,4)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
340 ds = ArrayDataSet(a2,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
341 ds = ArrayDataSet(a2,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
342 assert len(ds)==10
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
343 #assert ds==a? should this work?
100
574f4db76022 restructuring and added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 96
diff changeset
344
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
345 test_iterate_over_examples(a2, ds)
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
346 test_getitem(a2, ds)
91
eee739fefdff corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 89
diff changeset
347
eee739fefdff corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 89
diff changeset
348 # - for val1,val2,val3 in dataset(field1, field2,field3):
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
349 test_ds_iterator(a2,ds('x','y'),ds('y','z'),ds('x','y','z'))
89
05dc4804357b more test and refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 87
diff changeset
350
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
351
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
352 assert len(ds.fields())==3
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
353 for field in ds.fields():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
354 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
355 pass
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
356 for field in ds('x','z').fields():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
357 pass
60
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 58
diff changeset
358 for field in ds.fields('x','y'):
58
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
359 pass
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
360 for field_examples in ds.fields():
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
361 for example_value in field_examples:
17729d7104fa added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 54
diff changeset
362 pass
63
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
363
14589f02a372 more test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 60
diff changeset
364 assert ds == ds.fields().examples()
100
574f4db76022 restructuring and added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 96
diff changeset
365 # for ((x,y),a_v) in (ds('x','y'),a): #???don't work # haven't found a variant that work.# will not work
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
366 # assert numpy.append(x,y)==z
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
367
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
368 def test_LookupList():
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
369 #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
370 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
371 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
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383 assert example+example2==example3
145
933db7ece663 make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 139
diff changeset
384 assert have_raised("var['x']+var['x']",x=example)
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
385
158
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 157
diff changeset
386 def test_CachedDataSet():
148
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
387 print "test_CacheDataSet"
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
388 a2 = numpy.random.rand(10,4)
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
389 ds1 = ArrayDataSet(a2,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
390 ds2 = CachedDataSet(ds1)
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
391 ds3 = CachedDataSet(ds1,cache_all_upon_construction=True)
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
392 assert len(ds2)==10
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
393
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
394 test_iterate_over_examples(a2, ds2)
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
395 test_getitem(a2, ds2)
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
396
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
397 # - for val1,val2,val3 in dataset(field1, field2,field3):
149
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 148
diff changeset
398 test_ds_iterator(a2,ds2('x','y'),ds2('y','z'),ds2('x','y','z'))
148
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
399
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
400
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
401 assert len(ds2.fields())==3
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
402 for field in ds2.fields():
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
403 for field_value in field: # iterate over the values associated to that field for all the ds examples
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
404 pass
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
405 for field in ds2('x','z').fields():
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
406 pass
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
407 for field in ds2.fields('x','y'):
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
408 pass
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
409 for field_examples in ds2.fields():
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
410 for example_value in field_examples:
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
411 pass
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
412
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
413 assert ds2 == ds2.fields().examples()
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
414 # for ((x,y),a_v) in (ds('x','y'),a): #???don't work # haven't found a variant that work.# will not work
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
415 # assert numpy.append(x,y)==z
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
416
a5329e719229 added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 145
diff changeset
417
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
418 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
419 print "test_ApplyFunctionDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
420 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
421 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
422 print "test_FieldsSubsetDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
423 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
424 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
425 print "test_DataSetFields"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
426 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
427 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
428 print "test_MinibatchDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
429 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
430 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
431 print "test_HStackedDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
432 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
433 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
434 print "test_VStackedDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
435 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
436 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
437 print "test_ArrayFieldsDataSet"
81
4b0859606d05 Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 66
diff changeset
438 raise NotImplementedError()
157
e8c8022582f4 only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 149
diff changeset
439 if __name__=='__main__':
e8c8022582f4 only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 149
diff changeset
440 test1()
e8c8022582f4 only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 149
diff changeset
441 test_LookupList()
e8c8022582f4 only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 149
diff changeset
442 test_ArrayDataSet()
158
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 157
diff changeset
443 test_CachedDataSet()
122
d3c72e412065 removed datat that should not be commited
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 116
diff changeset
444 #test pmat.py