def test_tile_infer_all_ones(self): graph = build_graph(nodes_attributes, edges, {'tile_values': { 'value': np.array([1, 1, 1, 1]) }}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue( np.all( np.array([10, 20, 30, 40]) == graph.node['tile_out']['shape']))
def test_tile_infer_three_non_one(self): graph = build_graph(nodes_attributes, edges, {'tile_values': { 'value': np.array([2, 1, 5, 2]) }}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue( np.all( np.array([20, 20, 150, 80]) == graph.node['tile_out'] ['shape']))
def test_tile_infer_shapes_alignment(self): graph = build_graph(nodes_attributes, edges, { 'tile_values': { 'value': np.array([1, 2, 3]), 'shape': np.array([3]) } }) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue( np.all( np.array([10, 20, 60, 120]) == graph.node['tile_out'] ['shape']))
def test_tile_infer_correct_2d_tensor(self): graph = build_graph( nodes_attributes, edges, { 'data': { 'shape': np.array([3, 7]) }, 'tile_values': { 'value': np.array([5, 1]) } }) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue( np.all(np.array([15, 7]) == graph.node['tile_out']['shape']))
def test_tile_infer_values_test(self): input_data = np.arange(-30, 60, 0.25).reshape([2, 4, 3, -1]) tile_values = np.array([3, 1, 1, 1]) graph = build_graph( nodes_attributes, edges, { 'data': { 'shape': np.array(input_data.shape), 'value': input_data }, 'tile_values': { 'value': tile_values } }) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue( np.all( np.tile(input_data, tile_values) == graph.node['tile_out'] ['value']))
def test_tile_infer_values_const_propagation(self): """ Test for constant propagation even if tile with multiple tile indices is not supported """ input_data = np.arange(-30, 60, 0.25).reshape([2, 4, 3, -1]) tile_values = np.array([4, 3, 2, 5]) graph = build_graph( nodes_attributes, edges, { 'data': { 'shape': np.array(input_data.shape), 'value': input_data }, 'tile_values': { 'value': tile_values } }) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue( np.all( np.tile(input_data, tile_values) == graph.node['tile_out'] ['value']))