Beispiel #1
0
    def test_not_lazy_if_inplace(self):
        # Tests that if the outputs are scalars and the graph is big,
        # we disable the inplace opt to speed up optimization
        x = tensor.vector('x', dtype=self.dtype)
        y = tensor.vector('y', dtype=self.dtype)
        c = tensor.iscalar('c')
        mode = theano.compile.get_mode(self.mode).excluding(
            # Disable many opt to keep the graph big enough to disable
            # the opt.
            'fusion',
            'local_add_canonizer',
            'inplace',
            'constant_folding',
            'constant_folding')
        y2 = reduce(lambda x, y: x + y, [y] + list(range(200)))
        f = theano.function([c, x, y], ifelse(c, x, y2), mode=mode)
        # For not inplace ifelse
        self.assertFunctionContains1(f, IfElse(1))
        rng = numpy.random.RandomState(utt.fetch_seed())

        xlen = rng.randint(200)
        ylen = rng.randint(200)

        vx = numpy.asarray(rng.uniform(size=(xlen, )), self.dtype)
        vy = numpy.asarray(rng.uniform(size=(ylen, )), self.dtype)

        assert numpy.allclose(vx, f(1, vx, vy))
        assert numpy.allclose(vy + sum(range(200)), f(0, vx, vy))
Beispiel #2
0
def local_gpua_lazy_ifelse(node, context_name):
    if node.op.gpu:
        return
    c = node.inputs[0]
    inps = []
    for v in node.inputs[1:]:
        if isinstance(v.type, (tensor.TensorType, GpuArrayType)):
            inps.append(as_gpuarray_variable(v, context_name))
        else:
            inps.append(v)
    return IfElse(node.op.n_outs, gpu=True)(c, *inps, return_list=True)
Beispiel #3
0
 def get_ifelse(self, n):
     if theano.config.mode == "FAST_COMPILE":
         return IfElse(n)
     else:
         return IfElse(n, as_view=True)
Beispiel #4
0
def local_gpua_lazy_ifelse(node, context_name):
    if node.op.gpu:
        return
    c = node.inputs[0]
    inps = [as_gpuarray_variable(v, context_name) for v in node.inputs[1:]]
    return IfElse(node.op.n_outs, gpu=True)(c, *inps, return_list=True)