comparison _test_dataset.py @ 347:3aa9e5a5802a

Automated merge with ssh://projects@lgcm.iro.umontreal.ca/hg/pylearn
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Tue, 17 Jun 2008 14:46:15 -0400
parents 9de4274ad5ba 394b4e849c1b
children 952129cd55cb
comparison
equal deleted inserted replaced
346:9de4274ad5ba 347:3aa9e5a5802a
341 # for example in hstack([ds('x'),ds('y'),ds('z')]): 341 # for example in hstack([ds('x'),ds('y'),ds('z')]):
342 # example==ds[i] 342 # example==ds[i]
343 # i+=1 343 # i+=1
344 # del i,example 344 # del i,example
345 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#???? 345 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#????
346
347 def test_subset(array,ds):
348 def test_ds(orig,ds,index):
349 i=0
350 assert isinstance(ds2,DataSet)
351 assert len(ds)==len(index)
352 for x,z,y in ds('x','z','y'):
353 assert (orig[index[i]]['x']==array[index[i]][:3]).all()
354 assert (orig[index[i]]['x']==x).all()
355 assert orig[index[i]]['y']==array[index[i]][3]
356 assert orig[index[i]]['y']==y
357 assert (orig[index[i]]['z']==array[index[i]][0:3:2]).all()
358 assert (orig[index[i]]['z']==z).all()
359 i+=1
360 del i
361 ds[0]
362 if len(ds)>2:
363 ds[:1]
364 ds[1:1]
365 ds[1:1:1]
366 if len(ds)>5:
367 ds[[1,2,3]]
368 for x in ds:
369 pass
370
371 #ds[:n] returns a dataset with the n first examples.
372 ds2=ds.subset[:3]
373 test_ds(ds,ds2,index=[0,1,2])
374 # del ds2
375
376 # #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s.
377 # ds2=ds.subset[1:7:2]
378 # test_ds(ds,ds2,[1,3,5])
379 # del ds2
380
381 # #ds[i]
382 # ds2=ds.subset[5]
383 # assert isinstance(ds2,Example)
384 # assert have_raised("var['ds']["+str(len(ds))+"]",ds=ds) # index not defined
385 # assert not have_raised("var['ds']["+str(len(ds)-1)+"]",ds=ds)
386 # del ds2
387
388 # #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in.
389 # ds2=ds.subset[[4,7,2,8]]
390 # test_ds(ds,ds2,[4,7,2,8])
391 # del ds2
392
393 # #ds.<property># returns the value of a property associated with
394 # #the name <property>. The following properties should be supported:
395 # # - 'description': a textual description or name for the ds
396 # # - 'fieldtypes': a list of types (one per field)
397
398 # #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#????
399 # #assert hstack([ds('x','y'),ds('z')])==ds
400 # #hstack([ds('z','y'),ds('x')])==ds
401 # assert have_raised2(hstack,[ds('x'),ds('x')])
402 # assert have_raised2(hstack,[ds('y','x'),ds('x')])
403 # assert not have_raised2(hstack,[ds('x'),ds('y')])
404
405 # # i=0
406 # # for example in hstack([ds('x'),ds('y'),ds('z')]):
407 # # example==ds[i]
408 # # i+=1
409 # # del i,example
410 # #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#????
346 411
347 def test_fields_fct(ds): 412 def test_fields_fct(ds):
348 #@todo, fill correctly 413 #@todo, fill correctly
349 assert len(ds.fields())==3 414 assert len(ds.fields())==3
350 i=0 415 i=0
471 def test_all(array,ds): 536 def test_all(array,ds):
472 assert len(ds)==10 537 assert len(ds)==10
473 test_iterate_over_examples(array, ds) 538 test_iterate_over_examples(array, ds)
474 test_overrides(ds) 539 test_overrides(ds)
475 test_getitem(array, ds) 540 test_getitem(array, ds)
541 test_subset(array, ds)
476 test_ds_iterator(array,ds('x','y'),ds('y','z'),ds('x','y','z')) 542 test_ds_iterator(array,ds('x','y'),ds('y','z'),ds('x','y','z'))
477 test_fields_fct(ds) 543 test_fields_fct(ds)
478 544
479 545
480 class T_DataSet(unittest.TestCase): 546 class T_DataSet(unittest.TestCase):