def test_scalar_constant(): pipe = Pipeline(batch_size = 1, num_threads = 1, device_id = 0) image1 = np.array([ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=np.uint8)[:,:,np.newaxis] image2 = np.array([ [10, 20], [30, 40], [50, 60]], dtype=np.uint8)[:,:,np.newaxis] batches = [[image1], [image2]] inputs = fn.external_source(lambda: batches, 2, layout = "HWC") rotated = fn.rotate(inputs, angle = types.ScalarConstant(90)) pipe.set_outputs(*rotated, types.ScalarConstant(90)) pipe.build() outs = pipe.run() arr1 = outs[0].at(0) arr2 = outs[1].at(0) arr3 = outs[2].at(0) ref1 = np.array([ [4, 8, 12], [3, 7, 11], [2, 6, 10], [1, 5, 9]])[:,:,np.newaxis] ref2 = np.array([ [20, 40, 60], [10, 30, 50]], dtype=np.uint8)[:,:,np.newaxis] ref3 = np.array(90) assert(np.array_equal(arr1, ref1)) assert(np.array_equal(arr2, ref2)) assert(np.array_equal(arr3, ref3))
def test_pipe(): data = fn.external_source(source=get_data) shape = types.ScalarConstant(10) anchor = types.ScalarConstant(5) if device != 'cpu': data = data.gpu() sliced = fn.slice(data, start = anchor, shape = shape, axes=[0], device=device) return data, sliced, shape, anchor