Mercurial > pylearn
annotate test_dataset.py @ 231:38beb81f4e8b
Automated merge with ssh://projects@lgcm.iro.umontreal.ca/hg/pylearn
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Tue, 27 May 2008 13:46:03 -0400 |
parents | df3fae88ab46 4d1bd2513e06 |
children | 6aff510792dd |
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 | 2 from dataset import * |
3 from math import * | |
4 import numpy | |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
5 from misc import * |
45 | 6 |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
7 def have_raised(to_eval, **var): |
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 |
173 | 15 def have_raised2(f, *args, **kwargs): |
16 have_thrown = False | |
17 try: | |
18 f(*args, **kwargs) | |
19 except : | |
20 have_thrown = True | |
21 return have_thrown | |
22 | |
45 | 23 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
|
24 print "test1" |
45 | 25 global a,ds |
26 a = numpy.random.rand(10,4) | |
27 print a | |
28 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]}) | |
29 print "len(ds)=",len(ds) | |
54 | 30 assert(len(ds)==10) |
45 | 31 print "example 0 = ",ds[0] |
54 | 32 # assert |
45 | 33 print "x=",ds["x"] |
34 print "x|y" | |
35 for x,y in ds("x","y"): | |
36 print x,y | |
37 minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4) | |
38 minibatch = minibatch_iterator.__iter__().next() | |
39 print "minibatch=",minibatch | |
40 for var in minibatch: | |
41 print "var=",var | |
48
b6730f9a336d
Fixing MinibatchDataSet getitem
bengioy@grenat.iro.umontreal.ca
parents:
45
diff
changeset
|
42 print "take a slice and look at field y",ds[1:6:2]["y"] |
45 | 43 |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
44 del a,ds,x,y,minibatch_iterator,minibatch,var |
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
45 |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
46 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
|
47 #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
|
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 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
|
50 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
|
51 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
|
52 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
|
53 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
54 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
|
55 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
|
56 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
57 # - 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
|
58 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
66 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
|
67 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
|
68 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
69 # - 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
|
70 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
77 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
|
78 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
|
79 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
80 # - 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
|
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('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
|
83 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
|
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 (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
|
87 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
|
88 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
89 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
|
90 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
|
91 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
98 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
|
99 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
|
100 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
101 # - 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
|
102 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
109 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
|
110 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
|
111 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
117 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
|
118 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
|
119 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
120 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
|
121 ##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
|
122 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
|
123 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
|
124 del idx |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
125 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
|
126 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
|
127 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
128 # - 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
|
129 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
130 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
131 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
|
132 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
|
133 for minibatch in m: |
161
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
134 assert isinstance(minibatch,DataSetFields) |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
135 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
|
136 test_minibatch_size(minibatch,m.minibatch_size,len(ds),2,mi) |
161
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
137 if type(ds)==ArrayDataSet: |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
138 assert (minibatch[0][:,::2]==minibatch[1]).all() |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
139 else: |
162
45427d4d64b3
bugfix in test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
161
diff
changeset
|
140 for j in xrange(len(minibatch[0])): |
45427d4d64b3
bugfix in test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
161
diff
changeset
|
141 (minibatch[0][j][::2]==minibatch[1][j]).all() |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
142 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
143 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
|
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,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 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
149 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
156 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
|
157 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
|
158 i+=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 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
|
162 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
163 # - 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
|
164 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
165 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 test_minibatch_field_size(z,m.minibatch_size,len(ds),mi) |
164
3518710e16ec
don't assume we have an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
162
diff
changeset
|
171 for id in range(len(x)): |
3518710e16ec
don't assume we have an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
162
diff
changeset
|
172 assert (x[id][::2]==z[id]).all() |
3518710e16ec
don't assume we have an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
162
diff
changeset
|
173 i+=1 |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
174 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
179 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
185 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
|
186 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
|
187 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
192 #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
|
193 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
202 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
|
203 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
|
204 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
205 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
214 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
|
215 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
|
216 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
217 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
226 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
|
227 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
|
228 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
229 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
230 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
|
231 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
|
232 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 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
|
237 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
238 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
|
239 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
240 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
|
241 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
|
242 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
|
243 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
244 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
|
245 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
252 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
|
253 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
254 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
|
255 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
|
256 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
266 del i |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
267 ds[0] |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
268 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
|
269 ds[:1] |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 pass |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
276 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
277 #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
|
278 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
|
279 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
|
280 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
|
281 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
282 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
283 #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
|
284 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
|
285 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
|
286 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
|
287 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
288 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
289 #ds[i] |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
290 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
|
291 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
|
292 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
|
293 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
|
294 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
295 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
296 #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
|
297 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
|
298 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
|
299 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
|
300 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
301 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
302 #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
|
303 #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
|
304 #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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
314 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
|
315 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
|
316 i+=1 |
168 | 317 assert i==len(ds) |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
318 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
319 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
|
320 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
|
321 i+=1 |
168 | 322 assert i==len(ds) |
145
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 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 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
|
326 i+=1 |
168 | 327 assert i==len(ds) |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
328 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
|
329 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
330 #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
|
331 #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
|
332 # - '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
|
333 # - '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
|
334 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
335 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#???? |
173 | 336 #assert hstack([ds('x','y'),ds('z')])==ds |
337 #hstack([ds('z','y'),ds('x')])==ds | |
338 assert have_raised2(hstack,[ds('x'),ds('x')]) | |
339 assert have_raised2(hstack,[ds('y','x'),ds('x')]) | |
340 assert not have_raised2(hstack,[ds('x'),ds('y')]) | |
341 | |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
342 # i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
343 # 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
|
344 # 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
|
345 # i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
346 # 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
|
347 #* 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
|
348 |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
349 def test_fields_fct(ds): |
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
350 #@todo, fill correctly |
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
351 assert len(ds.fields())==3 |
168 | 352 i=0 |
353 v=0 | |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
354 for field in ds.fields(): |
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
355 for field_value in field: # iterate over the values associated to that field for all the ds examples |
168 | 356 v+=1 |
357 i+=1 | |
358 assert i==3 | |
359 assert v==3*10 | |
360 del i,v | |
361 | |
362 i=0 | |
363 v=0 | |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
364 for field in ds('x','z').fields(): |
168 | 365 i+=1 |
366 for val in field: | |
367 v+=1 | |
368 assert i==2 | |
369 assert v==2*10 | |
370 del i,v | |
371 | |
372 i=0 | |
373 v=0 | |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
374 for field in ds.fields('x','y'): |
168 | 375 i+=1 |
376 for val in field: | |
377 v+=1 | |
378 assert i==2 | |
379 assert v==2*10 | |
380 del i,v | |
381 | |
382 i=0 | |
383 v=0 | |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
384 for field_examples in ds.fields(): |
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
385 for example_value in field_examples: |
168 | 386 v+=1 |
387 i+=1 | |
388 assert i==3 | |
389 assert v==3*10 | |
390 del i,v | |
391 | |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
392 assert ds == ds.fields().examples() |
168 | 393 assert len(ds('x','y').fields()) == 2 |
394 assert len(ds('x','z').fields()) == 2 | |
395 assert len(ds('y').fields()) == 1 | |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
396 |
168 | 397 del field |
194
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
398 def test_all(array,ds): |
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
399 assert len(ds)==10 |
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
400 |
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
401 test_iterate_over_examples(array, ds) |
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
402 test_getitem(array, ds) |
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
403 test_ds_iterator(array,ds('x','y'),ds('y','z'),ds('x','y','z')) |
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
404 test_fields_fct(ds) |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
405 |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
406 def test_ArrayDataSet(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
407 #don't test stream |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
408 #tested only with float value |
106 | 409 #don't always test with y |
410 #don't test missing value | |
411 #don't test with tuple | |
412 #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
|
413 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
|
414 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
|
415 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
|
416 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
|
417 #assert ds==a? should this work? |
100
574f4db76022
restructuring and added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
96
diff
changeset
|
418 |
194
0040ba0f0666
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
173
diff
changeset
|
419 test_all(a2,ds) |
169
051e07807554
added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
168
diff
changeset
|
420 |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
421 del a2, ds |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
422 |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
423 def test_LookupList(): |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
424 #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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 |
165
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
441 del example, example2, example3, x, y ,z |
2a12e7437c56
small refactoring
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
164
diff
changeset
|
442 |
158 | 443 def test_CachedDataSet(): |
148
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
444 print "test_CacheDataSet" |
169
051e07807554
added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
168
diff
changeset
|
445 a = numpy.random.rand(10,4) |
051e07807554
added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
168
diff
changeset
|
446 ds1 = ArrayDataSet(a,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested |
148
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
447 ds2 = CachedDataSet(ds1) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
448 ds3 = CachedDataSet(ds1,cache_all_upon_construction=True) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
449 |
195 | 450 test_all(a,ds2) |
451 test_all(a,ds3) | |
169
051e07807554
added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
168
diff
changeset
|
452 |
051e07807554
added test for CachedDataSet(ds,cache_all_upon_construction=True)
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
168
diff
changeset
|
453 del a,ds1,ds2,ds3 |
148
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
454 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
455 |
161
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
456 def test_DataSetFields(): |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
457 print "test_DataSetFields" |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
458 raise NotImplementedError() |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
459 |
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
|
460 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
|
461 print "test_ApplyFunctionDataSet" |
202
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
462 a = numpy.random.rand(10,4) |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
463 a2 = a+1 |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
464 ds1 = ArrayDataSet(a,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
465 |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
466 ds2 = ApplyFunctionDataSet(ds1,lambda x,y,z: (x+1,y+1,z+1), ['x','y','z'],minibatch_mode=False) |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
467 ds3 = ApplyFunctionDataSet(ds1,lambda x,y,z: (numpy.array(x)+1,numpy.array(y)+1,numpy.array(z)+1), |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
468 ['x','y','z'], |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
469 minibatch_mode=True) |
202
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
470 |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
471 test_all(a2,ds2) |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
472 test_all(a2,ds3) |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
473 |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
474 del a,ds1,ds2,ds3 |
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
475 |
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
|
476 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
|
477 print "test_FieldsSubsetDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
478 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
|
479 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
|
480 print "test_MinibatchDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
481 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
|
482 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
|
483 print "test_HStackedDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
484 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
|
485 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
|
486 print "test_VStackedDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
487 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
|
488 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
|
489 print "test_ArrayFieldsDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
490 raise NotImplementedError() |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
491 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
492 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
493 def test_speed(): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
494 print "test_speed" |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
495 import time |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
496 a2 = numpy.random.rand(100000,400) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
497 ds = ArrayDataSet(a2,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
498 ds = ArrayDataSet(a2,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested |
230
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
499 ds = ArrayDataSet(a2,{'all':slice(0,a2.shape[1],1)}) |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
500 #assert ds==a? should this work? |
230
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
501 mat = numpy.random.rand(400,100) |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
502 @print_timing |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
503 def f_array1(a): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
504 a+1 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
505 @print_timing |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
506 def f_array2(a): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
507 for id in range(a.shape[0]): |
230
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
508 # pass |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
509 a[id]+1 |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
510 # a[id]*mat |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
511 @print_timing |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
512 def f_ds(ds): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
513 for ex in ds: |
230
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
514 # pass |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
515 ex[0]+1 |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
516 # a[id]*mat |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
517 @print_timing |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
518 def f_ds_mb1(ds,mb_size): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
519 for exs in ds.minibatches(minibatch_size = mb_size): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
520 for ex in exs: |
230
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
521 # pass |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
522 ex[0]+1 |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
523 # ex[id]*mat |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
524 @print_timing |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
525 def f_ds_mb2(ds,mb_size): |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
526 for exs in ds.minibatches(minibatch_size = mb_size): |
230
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
527 # pass |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
528 exs[0]+1 |
4d1bd2513e06
more test speed
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
229
diff
changeset
|
529 # ex[id]*mat |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
530 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
531 f_array1(a2) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
532 f_array2(a2) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
533 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
534 f_ds(ds) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
535 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
536 f_ds_mb1(ds,10) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
537 f_ds_mb1(ds,100) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
538 f_ds_mb1(ds,1000) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
539 f_ds_mb1(ds,10000) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
540 f_ds_mb2(ds,10) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
541 f_ds_mb2(ds,100) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
542 f_ds_mb2(ds,1000) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
543 f_ds_mb2(ds,10000) |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
544 |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
545 del a2, ds |
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
546 |
157
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
547 if __name__=='__main__': |
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
548 test1() |
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
549 test_LookupList() |
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
550 test_ArrayDataSet() |
158 | 551 test_CachedDataSet() |
202
b9950ae5e54b
Added test for ApplyFunctionDataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
195
diff
changeset
|
552 test_ApplyFunctionDataSet() |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
553 #test_speed() |
122
d3c72e412065
removed datat that should not be commited
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
116
diff
changeset
|
554 #test pmat.py |
229
d7250ee86f72
Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
202
diff
changeset
|
555 |