Mercurial > pylearn
diff test_dataset.py @ 100:574f4db76022
restructuring and added test
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Tue, 06 May 2008 14:01:22 -0400 |
parents | 352910e0dbf5 |
children | 4537ac630348 |
line wrap: on
line diff
--- a/test_dataset.py Tue May 06 13:57:36 2008 -0400 +++ b/test_dataset.py Tue May 06 14:01:22 2008 -0400 @@ -121,7 +121,7 @@ assert len(minibatch[1])==3 assert (minibatch[0][:,0:3:2]==minibatch[1]).all() i+=1 - #assert i==#??? What shoud be the value? + #assert i==#??? What shoud be the value? #option for the rest. print i del minibatch,i i=0 @@ -179,13 +179,14 @@ del x,y,i,id i=0 - for x,y in ds.minibatches(['x','y'],n_batches=10,minibatch_size=3,offset=4): + m=ds.minibatches(['x','y'],n_batches=10,minibatch_size=3,offset=4) # bugged??? + for x,y in m: assert len(x)==3 assert len(y)==3 for id in range(3): - assert (numpy.append(x[id],y[id])==a[i+4]).all() + assert (numpy.append(x[id],y[id])==a[(i+4)%a.shape[0]]).all() i+=1 - assert i==6 + assert i==m.n_batches*m.minibatch_size del x,y,i,id @@ -212,21 +213,80 @@ i+=1 assert i==len(ds) + def test_getitem(array,ds): + + def test_ds(orig,ds,index): + i=0 + assert len(ds)==len(index) + for x,z,y in ds('x','z','y'): + assert (orig[index[i]]['x']==array[index[i]][:3]).all() + assert (orig[index[i]]['x']==x).all() + assert orig[index[i]]['y']==array[index[i]][3] + assert orig[index[i]]['y']==y + assert (orig[index[i]]['z']==array[index[i]][0:3:2]).all() + assert (orig[index[i]]['z']==z).all() + i+=1 + del i + ds[0] + if len(ds)>2: + ds[:1] + ds[1:1] + ds[1:1:1] + if len(ds)>5: + ds[[1,2,3]] + for x in ds: + pass + + assert have_raised("ds['h']") # h is not defined... + assert have_raised("ds["+str(len(ds))+"]") # h is not defined... + assert have_raised("ds["+str(len(ds))+"]") # h is not defined... + assert have_raised("ds[['h']]") # h is not defined... + + #ds[:n] returns a dataset with the n first examples. + ds2=ds[:3] + assert isinstance(ds2,DataSet) + test_ds(ds,ds2,index=[0,1,2]) + + #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. + ds2=ds[1:7:2] + assert isinstance(ds2,DataSet) + test_ds(ds,ds2,[1,3,5]) + + #ds[i] + ds2=ds[5] + assert isinstance(ds2,Example) + + #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. + ds2=ds[[4,7,2,8]] + assert isinstance(ds2,DataSet) + test_ds(ds,ds2,[4,7,2,8]) + #ds[i1,i2,...]# should we accept????no syntax of numpy.array + + #ds[fieldname]# an iterable over the values of the field fieldname across + #the ds (the iterable is obtained by default by calling valuesVStack + #over the values for individual examples). + + #ds.<property># returns the value of a property associated with + #the name <property>. The following properties should be supported: + # - 'description': a textual description or name for the ds + # - 'fieldtypes': a list of types (one per field) + #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#???? + #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#???? + + print "test_ArrayDataSet" a = numpy.random.rand(10,4) ds = ArrayDataSet(a,{'x':slice(3),'y':3,'z':[0,2]})###???tuple not tested ds = ArrayDataSet(a,LookupList(['x','y','z'],[slice(3),3,[0,2]]))###???tuple not tested assert len(ds)==10 #assert ds==a? should this work? - + test_iterate_over_examples(a, ds) - + test_getitem(a, ds) # - for val1,val2,val3 in dataset(field1, field2,field3): test_ds_iterator(a,ds('x','y'),ds('y','z'),ds('x','y','z')) - assert have_raised("ds['h']") # h is not defined... - assert have_raised("ds[['h']]") # h is not defined... assert len(ds.fields())==3 for field in ds.fields(): @@ -241,54 +301,7 @@ pass assert ds == ds.fields().examples() - - def test_ds(orig,ds,index): - i=0 - assert len(ds)==len(index) - for x,z,y in ds('x','z','y'): - assert (orig[index[i]]['x']==a[index[i]][:3]).all() - assert (orig[index[i]]['x']==x).all() - assert orig[index[i]]['y']==a[index[i]][3] - assert orig[index[i]]['y']==y - assert (orig[index[i]]['z']==a[index[i]][0:3:2]).all() - assert (orig[index[i]]['z']==z).all() - i+=1 - del i - ds[0] - if len(ds)>2: - ds[:1] - ds[1:1] - ds[1:1:1] - if len(ds)>5: - ds[[1,2,3]] - for x in ds: - pass - - #ds[:n] returns a dataset with the n first examples. - ds2=ds[:3] - test_ds(ds,ds2,index=[0,1,2]) - - #ds[i1:i2:s]# returns a ds with the examples i1,i1+s,...i2-s. - ds2=ds[1:7:2] - test_ds(ds,ds2,[1,3,5]) - - #ds[[i1,i2,...in]]# returns a ds with examples i1,i2,...in. - ds2=ds[[4,7,2,8]] - test_ds(ds,ds2,[4,7,2,8]) - #ds[i1,i2,...]# should we accept???? - - #ds[fieldname]# an iterable over the values of the field fieldname across - #the ds (the iterable is obtained by default by calling valuesVStack - #over the values for individual examples). - - #ds.<property># returns the value of a property associated with - #the name <property>. The following properties should be supported: - # - 'description': a textual description or name for the ds - # - 'fieldtypes': a list of types (one per field) - #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3]) - #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3]) - -# for (x,y) in (ds('x','y'),a): #???don't work # haven't found a variant that work. +# for ((x,y),a_v) in (ds('x','y'),a): #???don't work # haven't found a variant that work.# will not work # assert numpy.append(x,y)==z def test_LookupList():