| 94 | |
| 95 | |
| 96 | def test_casting_decoding(): |
| 97 | num_samples = 8 |
| 98 | data = [ |
| 99 | np.random.normal(loc=0, scale=255, size=(2, s)).astype(np.int32) for s in range(num_samples) |
| 100 | ] |
| 101 | |
| 102 | @pipeline_def(batch_size=1, num_threads=1) |
| 103 | def pipe(): |
| 104 | encoded_npy = fn.external_source( |
| 105 | source=box_source(data), num_outputs=1, batch=False, ndim=1, dtype=DALIDataType.UINT8 |
| 106 | ) |
| 107 | decoded = fn.decoders.numpy(encoded_npy, dtype=DALIDataType.FLOAT) |
| 108 | return decoded |
| 109 | |
| 110 | p = pipe() |
| 111 | p.build() |
| 112 | |
| 113 | for i in range(num_samples): |
| 114 | output = p.run() |
| 115 | test = np.asarray(output[0][0]) |
| 116 | assert np.array_equal(test, data[i].astype(np.float32)) |
| 117 | |
| 118 | |
| 119 | @raises(RuntimeError, "All samples in the dataset must have the same number of dimensions") |