@@ -492,11 +492,9 @@ def test_getattr(self):
492
492
)
493
493
self .assertEqual (feature .names , ['left' , 'right' ])
494
494
495
- feature = feature_lib .Dataset (
496
- {
497
- 'label' : feature_lib .ClassLabel (names = ['left' , 'right' ]),
498
- }
499
- )
495
+ feature = feature_lib .Dataset ({
496
+ 'label' : feature_lib .ClassLabel (names = ['left' , 'right' ]),
497
+ })
500
498
self .assertEqual (feature ['label' ].names , ['left' , 'right' ])
501
499
502
500
def test_metadata (self ):
@@ -512,24 +510,52 @@ def test_metadata(self):
512
510
513
511
class DecodeExampleNpTest (testing .SubTestCase ):
514
512
515
- def test_top_level_feature (self ):
516
- feature = feature_lib .Dataset (
517
- {'feature_name' : feature_lib .Tensor (dtype = np .uint8 , shape = (4 , 2 ))}
518
- )
519
- example = {'feature_name' : np .ones (shape = (24 ,), dtype = np .int32 )}
520
- expected = [{'feature_name' : np .ones (shape = (4 , 2 ), dtype = np .int32 )}] * 3
521
- self .assertAllEqualNested (feature .decode_example_np (example ), expected )
522
-
523
- def test_tensor_feature (self ):
524
- feature = feature_lib .Dataset (
525
- feature_lib .Tensor (dtype = np .uint8 , shape = (4 , 2 ))
526
- )
527
- example = np .ones (shape = (24 ,), dtype = np .uint8 )
528
- expected = [np .ones (shape = (4 , 2 ), dtype = np .int32 )] * 3
529
- self .assertAllEqualNested (feature .decode_example_np (example ), expected )
513
+ def test_representative_example (self ):
514
+ feature = feature_lib .FeaturesDict ({
515
+ 'step_number' : feature_lib .Tensor (dtype = np .int32 , shape = ()),
516
+ 'steps' : feature_lib .Dataset ({
517
+ 'tensor' : feature_lib .Tensor (dtype = np .uint8 , shape = (7 , 8 )),
518
+ 'strings' : feature_lib .Tensor (dtype = np .str_ , shape = (3 ,)),
519
+ 'bool' : feature_lib .Tensor (dtype = np .bool_ , shape = ()),
520
+ 'obj' : feature_lib .FeaturesDict ({
521
+ 'a' : feature_lib .Tensor (
522
+ dtype = np .float32 ,
523
+ shape = (5 ,),
524
+ encoding = feature_lib .Encoding .ZLIB ,
525
+ ),
526
+ 'b' : feature_lib .Tensor (dtype = np .int32 , shape = (6 ,)),
527
+ }),
528
+ 'reward' : feature_lib .Tensor (dtype = np .float32 , shape = ()),
529
+ }),
530
+ 'timestamp' : feature_lib .Tensor (dtype = np .int64 , shape = ()),
531
+ })
532
+ subdataset_size = 42
533
+ example = {
534
+ 'step_number' : 7 ,
535
+ 'steps' : [
536
+ {
537
+ 'tensor' : np .ones (shape = (7 , 8 ), dtype = np .uint8 ),
538
+ 'strings' : ['foo' , 'bar' , 'baz' ],
539
+ 'bool' : True ,
540
+ 'obj' : {
541
+ 'a' : np .zeros (shape = (5 ,), dtype = np .float32 ),
542
+ 'b' : np .zeros (shape = (6 ,), dtype = np .int32 ),
543
+ },
544
+ 'reward' : np .float32 (42.42 ),
545
+ }
546
+ for _ in range (subdataset_size )
547
+ ],
548
+ 'timestamp' : 1234567890 ,
549
+ }
550
+ encoded_example = feature .encode_example (example )
551
+ decoded_encoded_example = feature .decode_example_np (encoded_example )
552
+ self .assertAllEqualNested (decoded_encoded_example , example )
530
553
531
554
def test_nested_dict (self ):
532
- feature = feature_lib .Dataset ({'a' : {'b' : np .int32 }, 'b' : np .str_ })
555
+ feature = feature_lib .Dataset ({
556
+ 'a' : {'b' : np .int32 },
557
+ 'b' : np .str_ ,
558
+ })
533
559
example = {'a' : {'b' : [1 , 2 , 3 ]}, 'b' : ['a' , 'b' , 'c' ]}
534
560
expected = [
535
561
{'a' : {'b' : 1 }, 'b' : 'a' },
0 commit comments