Mercurial > pylearn
annotate test_dataset.py @ 162:45427d4d64b3
bugfix in test
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Mon, 12 May 2008 17:37:36 -0400 |
parents | 60e00cce3492 |
children | 3518710e16ec |
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 | |
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 | 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 | 17 global a,ds |
18 a = numpy.random.rand(10,4) | |
19 print a | |
20 ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]}) | |
21 print "len(ds)=",len(ds) | |
54 | 22 assert(len(ds)==10) |
45 | 23 print "example 0 = ",ds[0] |
54 | 24 # assert |
45 | 25 print "x=",ds["x"] |
26 print "x|y" | |
27 for x,y in ds("x","y"): | |
28 print x,y | |
29 minibatch_iterator = ds.minibatches(fieldnames=['z','y'],n_batches=1,minibatch_size=3,offset=4) | |
30 minibatch = minibatch_iterator.__iter__().next() | |
31 print "minibatch=",minibatch | |
32 for var in minibatch: | |
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 | 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: |
161
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 if type(ds)==ArrayDataSet: |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
128 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
|
129 else: |
162
45427d4d64b3
bugfix in test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
161
diff
changeset
|
130 for j in xrange(len(minibatch[0])): |
45427d4d64b3
bugfix in test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
161
diff
changeset
|
131 (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
|
132 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
138 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
139 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
146 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
|
147 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
|
148 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
153 # - 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
|
154 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
155 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
168 mi=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 mi+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
174 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
|
175 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
|
176 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
181 #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
|
182 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
191 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
|
192 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
|
193 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
194 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
203 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
|
204 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
|
205 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
206 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
215 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
|
216 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
|
217 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
218 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
219 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
|
220 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
|
221 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
227 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
|
228 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
233 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
|
234 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
241 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
|
242 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
243 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
|
244 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
|
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 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
255 del i |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
256 ds[0] |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
257 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
|
258 ds[:1] |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 pass |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
265 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
266 #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
|
267 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
|
268 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
|
269 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
|
270 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
271 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
272 #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
|
273 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
|
274 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
|
275 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
|
276 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
277 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
278 #ds[i] |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 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
|
283 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
284 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
285 #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
|
286 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
|
287 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
|
288 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
|
289 del ds2 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
290 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
291 #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
|
292 #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
|
293 #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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
303 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
|
304 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
|
305 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
306 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
307 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
|
308 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
|
309 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
310 i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
311 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
|
312 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
|
313 i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
314 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
|
315 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
316 #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
|
317 #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
|
318 # - '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
|
319 # - '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
|
320 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
321 #* 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
|
322 #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
|
323 #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
|
324 #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
|
325 #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
|
326 #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
|
327 #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
|
328 # i=0 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
329 # 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
|
330 # 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
|
331 # i+=1 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
332 # 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
|
333 #* 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
|
334 |
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
335 |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
336 def test_ArrayDataSet(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
337 #don't test stream |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
338 #tested only with float value |
106 | 339 #don't always test with y |
340 #don't test missing value | |
341 #don't test with tuple | |
342 #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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 assert len(ds)==10 |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
348 #assert ds==a? should this work? |
100
574f4db76022
restructuring and added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
96
diff
changeset
|
349 |
145
933db7ece663
make some function global to reuse them to test other dataset
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
139
diff
changeset
|
350 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
|
351 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
|
352 |
eee739fefdff
corrected test from discution about the syntax with Yoshua
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
89
diff
changeset
|
353 # - 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
|
354 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
|
355 |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
356 |
63 | 357 assert len(ds.fields())==3 |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
358 for field in ds.fields(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
359 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
|
360 pass |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
361 for field in ds('x','z').fields(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
362 pass |
60 | 363 for field in ds.fields('x','y'): |
58
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
364 pass |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
365 for field_examples in ds.fields(): |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
366 for example_value in field_examples: |
17729d7104fa
added function test_ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
54
diff
changeset
|
367 pass |
63 | 368 |
369 assert ds == ds.fields().examples() | |
100
574f4db76022
restructuring and added test
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
96
diff
changeset
|
370 # 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
|
371 # assert numpy.append(x,y)==z |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
372 |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
373 def test_LookupList(): |
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
374 #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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 |
158 | 391 def test_CachedDataSet(): |
148
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
392 print "test_CacheDataSet" |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
393 a2 = numpy.random.rand(10,4) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
394 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
|
395 ds2 = CachedDataSet(ds1) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
396 ds3 = CachedDataSet(ds1,cache_all_upon_construction=True) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
397 assert len(ds2)==10 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
398 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
399 test_iterate_over_examples(a2, ds2) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
400 test_getitem(a2, ds2) |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
401 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
402 # - for val1,val2,val3 in dataset(field1, field2,field3): |
149 | 403 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
|
404 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
405 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
406 assert len(ds2.fields())==3 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
407 for field in ds2.fields(): |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
408 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
|
409 pass |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
410 for field in ds2('x','z').fields(): |
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 for field in ds2.fields('x','y'): |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
413 pass |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
414 for field_examples in ds2.fields(): |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
415 for example_value in field_examples: |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
416 pass |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
417 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
418 assert ds2 == ds2.fields().examples() |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
419 # 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
|
420 # assert numpy.append(x,y)==z |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
421 |
a5329e719229
added test for CachedDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
145
diff
changeset
|
422 |
161
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
423 def test_DataSetFields(): |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
424 print "test_DataSetFields" |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
425 raise NotImplementedError() |
60e00cce3492
bugfix test in case it is not an ArrayDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
158
diff
changeset
|
426 |
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_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
|
428 print "test_ApplyFunctionDataSet" |
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_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
|
431 print "test_FieldsSubsetDataSet" |
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_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
|
434 print "test_MinibatchDataSet" |
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_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
|
437 print "test_HStackedDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
438 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
|
439 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
|
440 print "test_VStackedDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
441 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
|
442 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
|
443 print "test_ArrayFieldsDataSet" |
81
4b0859606d05
Added test for ArrayDataSet and LookUpList
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
66
diff
changeset
|
444 raise NotImplementedError() |
157
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
445 if __name__=='__main__': |
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
446 test1() |
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
447 test_LookupList() |
e8c8022582f4
only exec the test if we are the main
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
149
diff
changeset
|
448 test_ArrayDataSet() |
158 | 449 test_CachedDataSet() |
122
d3c72e412065
removed datat that should not be commited
Frederic Bastien <bastienf@iro.umontreal.ca>
parents:
116
diff
changeset
|
450 #test pmat.py |