Mercurial > pylearn
comparison test_dataset.py @ 106:cf9bdb1d9656
added test
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Tue, 06 May 2008 16:41:45 -0400 |
parents | e1a004b21daa |
children | 5bfcb7e5df4a |
comparison
equal
deleted
inserted
replaced
105:8c0a1b11b007 | 106:cf9bdb1d9656 |
---|---|
33 print "take a slice and look at field y",ds[1:6:2]["y"] | 33 print "take a slice and look at field y",ds[1:6:2]["y"] |
34 | 34 |
35 def test_ArrayDataSet(): | 35 def test_ArrayDataSet(): |
36 #don't test stream | 36 #don't test stream |
37 #tested only with float value | 37 #tested only with float value |
38 #test with y too | 38 #don't always test with y |
39 #test missing value | 39 #don't test missing value |
40 | 40 #don't test with tuple |
41 #don't test proterties | |
41 def test_iterate_over_examples(array,ds): | 42 def test_iterate_over_examples(array,ds): |
42 #not in doc!!! | 43 #not in doc!!! |
43 i=0 | 44 i=0 |
44 for example in range(len(ds)): | 45 for example in range(len(ds)): |
45 assert (ds[example]['x']==a[example][:3]).all() | 46 assert (ds[example]['x']==a[example][:3]).all() |
261 if len(ds)>5: | 262 if len(ds)>5: |
262 ds[[1,2,3]] | 263 ds[[1,2,3]] |
263 for x in ds: | 264 for x in ds: |
264 pass | 265 pass |
265 | 266 |
266 assert have_raised("ds['h']") # h is not defined... | |
267 assert have_raised("ds[['x']]") # h is not defined... | |
268 assert not have_raised("ds['x']") | |
269 assert have_raised("ds["+str(len(ds))+"]") # index not defined | |
270 assert not have_raised("ds["+str(len(ds)-1)+"]") | |
271 | |
272 #ds[:n] returns a dataset with the n first examples. | 267 #ds[:n] returns a dataset with the n first examples. |
273 ds2=ds[:3] | 268 ds2=ds[:3] |
274 assert isinstance(ds2,DataSet) | 269 assert isinstance(ds2,DataSet) |
275 test_ds(ds,ds2,index=[0,1,2]) | 270 test_ds(ds,ds2,index=[0,1,2]) |
271 del ds2 | |
276 | 272 |
277 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. | 273 #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. |
278 ds2=ds[1:7:2] | 274 ds2=ds[1:7:2] |
279 assert isinstance(ds2,DataSet) | 275 assert isinstance(ds2,DataSet) |
280 test_ds(ds,ds2,[1,3,5]) | 276 test_ds(ds,ds2,[1,3,5]) |
277 del ds2 | |
281 | 278 |
282 #ds[i] | 279 #ds[i] |
283 ds2=ds[5] | 280 ds2=ds[5] |
284 assert isinstance(ds2,Example) | 281 assert isinstance(ds2,Example) |
282 assert have_raised("ds["+str(len(ds))+"]") # index not defined | |
283 assert not have_raised("ds["+str(len(ds)-1)+"]") | |
284 del ds2 | |
285 | 285 |
286 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. | 286 #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. |
287 ds2=ds[[4,7,2,8]] | 287 ds2=ds[[4,7,2,8]] |
288 assert isinstance(ds2,DataSet) | 288 assert isinstance(ds2,DataSet) |
289 test_ds(ds,ds2,[4,7,2,8]) | 289 test_ds(ds,ds2,[4,7,2,8]) |
290 del ds2 | |
290 | 291 |
291 #ds[fieldname]# an iterable over the values of the field fieldname across | 292 #ds[fieldname]# an iterable over the values of the field fieldname across |
292 #the ds (the iterable is obtained by default by calling valuesVStack | 293 #the ds (the iterable is obtained by default by calling valuesVStack |
293 #over the values for individual examples). | 294 #over the values for individual examples). |
295 assert have_raised("ds['h']") # h is not defined... | |
296 assert have_raised("ds[['x']]") # bad syntax | |
297 assert not have_raised("ds['x']") | |
298 isinstance(ds['x'],DataSetFields) | |
299 ds2=ds['x'] | |
300 assert len(ds['x'])==10 | |
301 assert len(ds['y'])==10 | |
302 assert len(ds['z'])==10 | |
303 i=0 | |
304 for example in ds['x']: | |
305 assert (example==a[i][:3]).all() | |
306 i+=1 | |
307 i=0 | |
308 for example in ds['y']: | |
309 assert (example==a[i][3]).all() | |
310 i+=1 | |
311 i=0 | |
312 for example in ds['z']: | |
313 assert (example==a[i,0:3:2]).all() | |
314 i+=1 | |
315 del ds2,i | |
294 | 316 |
295 #ds.<property># returns the value of a property associated with | 317 #ds.<property># returns the value of a property associated with |
296 #the name <property>. The following properties should be supported: | 318 #the name <property>. The following properties should be supported: |
297 # - 'description': a textual description or name for the ds | 319 # - 'description': a textual description or name for the ds |
298 # - 'fieldtypes': a list of types (one per field) | 320 # - 'fieldtypes': a list of types (one per field) |
321 | |
299 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#???? | 322 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#???? |
300 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#???? | 323 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#???? |
301 | 324 |
302 | 325 |
303 print "test_ArrayDataSet" | 326 print "test_ArrayDataSet" |