Example #1
0
    def test_partial_infer2(self):
        graph = build_graph(nodes_attributes2, edges2, inputs2)

        unique_node = Node(graph, 'unique_node')
        Unique.infer(unique_node)

        # prepare reference results
        ref_output_uniques_shape = int64_array([20])
        ref_output_indices_shape = int64_array([20])
        ref_output_counts_shape = int64_array([20])

        # get resulted shapes
        res_output_uniques_shape = graph.node['output_uniques']['shape']
        res_output_indices_shape = graph.node['output_indices']['shape']
        res_output_counts_shape = graph.node['output_counts']['shape']

        self.assertTrue(
            np.array_equal(ref_output_uniques_shape, res_output_uniques_shape),
            'shapes do not match expected: {} and given: {}'.format(
                ref_output_uniques_shape, res_output_uniques_shape))

        self.assertTrue(
            np.array_equal(ref_output_indices_shape, res_output_indices_shape),
            'shapes do not match expected: {} and given: {}'.format(
                ref_output_indices_shape, res_output_indices_shape))

        self.assertTrue(
            np.array_equal(ref_output_counts_shape, res_output_counts_shape),
            'shapes do not match expected: {} and given: {}'.format(
                ref_output_counts_shape, res_output_counts_shape))
Example #2
0
    def test_constant_input(self):
        nodes_attributes_ = {'input': {'shape': None, 'value': None, 'kind': 'data'},
                            'unique_node': {'op': 'Unique', 'kind': 'op'},
                            'output_uniques': {'shape': None, 'value': None, 'kind': 'data'},
                            'output_indices': {'shape': None, 'value': None, 'kind': 'data'},
                            'output_counts': {'shape': None, 'value': None, 'kind': 'data'}
                            }
        edges_ = [('input', 'unique_node', {'in': 0}),
                  ('unique_node', 'output_uniques', {'out': 0}),
                  ('unique_node', 'output_indices', {'out': 1}),
                  ('unique_node', 'output_counts', {'out': 2})]
        inputs_ = {'input': {'shape': int64_array([10]),
                             'value': np.array([8.0, 1.0, 2.0, 1.0, 8.0, 5.0, 1.0, 5.0, 0.0, 0.0], dtype=np.float)},
                   'unique_node': {
                       'sorted': 'true',
                       'return_inverse': 'true',
                       'return_counts': 'true'
                       }
                   }
        graph = build_graph(nodes_attributes_, edges_, inputs_)
        unique_node = Node(graph, 'unique_node')
        Unique.infer(unique_node)

        # prepare reference results
        ref_output_uniques_shape = int64_array([5])
        ref_output_uniques_value = np.array([0.0, 1.0, 2.0, 5.0, 8.0], dtype=np.float)
        ref_output_indices_shape = int64_array([10])
        ref_output_indices_value = np.array([4.0, 1.0, 2.0, 1.0, 4.0, 3.0, 1.0, 3.0, 0.0, 0.0], dtype=np.float)
        ref_output_counts_shape = int64_array([5])
        ref_output_counts_value = np.array([2.0, 3.0, 1.0, 2.0, 2.0], dtype=np.float)

        # get resulted shapes
        res_output_uniques_shape = graph.node['output_uniques']['shape']
        res_output_uniques_value = graph.node['output_uniques']['value']
        res_output_indices_shape = graph.node['output_indices']['shape']
        res_output_indices_value = graph.node['output_indices']['value']
        res_output_counts_shape = graph.node['output_counts']['shape']
        res_output_counts_value = graph.node['output_counts']['value']

        # verify the results
        self.assertTrue(np.array_equal(ref_output_uniques_shape, res_output_uniques_shape),
                        'shapes do not match expected: {} and given: {}'.format(ref_output_uniques_shape, res_output_uniques_shape))
        self.assertTrue(np.array_equal(ref_output_uniques_value, res_output_uniques_value),
                        'values do not match expected: {} and given: {}'.format(ref_output_uniques_value, res_output_uniques_value))
        self.assertTrue(np.array_equal(ref_output_indices_shape, res_output_indices_shape),
                        'shapes do not match expected: {} and given: {}'.format(ref_output_indices_shape, res_output_indices_shape))
        self.assertTrue(np.array_equal(ref_output_indices_value, res_output_indices_value),
                        'values do not match expected: {} and given: {}'.format(ref_output_indices_value, res_output_indices_value))
        self.assertTrue(np.array_equal(ref_output_counts_shape, res_output_counts_shape),
                        'shapes do not match expected: {} and given: {}'.format(ref_output_counts_shape, res_output_counts_shape))
        self.assertTrue(np.array_equal(ref_output_counts_value, res_output_counts_value),
                        'values do not match expected: {} and given: {}'.format(ref_output_counts_value, res_output_counts_value))
Example #3
0
    def test_partial_infer_just_unique(self):
        edges = [('input', 'unique_node', {'in': 0}),
                 ('unique_node', 'output_uniques', {'out': 0})]
        graph = build_graph(nodes_attributes, edges, inputs1)

        unique_node = Node(graph, 'unique_node')
        Unique.infer(unique_node)

        # prepare reference results
        ref_output_uniques_shape = int64_array([20])

        # get resulted shapes
        res_output_uniques_shape = graph.node['output_uniques']['shape']

        self.assertTrue(np.array_equal(ref_output_uniques_shape, res_output_uniques_shape),
                        'shapes do not match expected: {} and given: {}'.format(ref_output_uniques_shape, res_output_uniques_shape))