Exemplo n.º 1
0
    def __call__(self, ops):

        # boxing inputs if needed
        ops = box(ops)

        # graph computation or eager?
        if self.debug:
            input_types = [type(op) for op in ops]
            self.print_debug('inputs type:%s' % (input_types))

        if issubclass(type(ops[0]), OP):
            # graph mode
            self.print_debug('graph mode')

            input_shapes = []
            for op in ops:
                assert issubclass(type(op), OP)
                self.input_ops.append(op)
                input_shapes.append(op.get_output_shapes())

            self.compute_output_shape(input_shapes)

            return self
        else:
            # eager mode
            self.print_debug('eager mode')

            # check inputs are valis
            for op in ops:
                if not B.is_tensor(op):
                    raise ValueError("Expecting list(tensors) or a tensor")

            # input shapes
            input_shapes = []
            for op in ops:
                input_shapes.append(op.shape)
            self.compute_output_shape(input_shapes)

            # compute concrete results - dispatch iterate through populations.
            return unbox(self.dispatch(ops, self.EAGER))
Exemplo n.º 2
0
 def _call_from_graph(self, populations):
     "Function called during graph executions"
     populations = box(populations)
     # dispatch take care of iterating through populations
     return unbox(self.dispatch(populations, self.GRAPH))
Exemplo n.º 3
0
 def get_output_shapes(self):
     "return the shape of tensor returned by the op"
     return unbox(self.output_shapes)
Exemplo n.º 4
0
 def get_populations(self):
     return unbox(self._populations)
Exemplo n.º 5
0
def test_box_unbox_tensor():
    val = tensor([1, 2, 3])

    assert tensor_equal(unbox(box(val)), val)
Exemplo n.º 6
0
def test_box_unbox():
    vals = ['a', [1, 2, 3]]

    for val in vals:
        assert unbox(box(val)) == val