当前位置: 首页>>代码示例>>Python>>正文


Python theano.gof方法代码示例

本文整理汇总了Python中theano.gof方法的典型用法代码示例。如果您正苦于以下问题:Python theano.gof方法的具体用法?Python theano.gof怎么用?Python theano.gof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano的用法示例。


在下文中一共展示了theano.gof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wrap_in

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def wrap_in(input):
        if isinstance(input, (SymbolicInput, SymbolicInputKit)):
            return input
        elif isinstance(input, gof.Variable):
            # r -> SymbolicInput(variable=r)
            return SymbolicInput(input)
        elif isinstance(input, (list, tuple)):
            # (r, u) -> SymbolicInput(variable=r, update=u)
            if len(input) == 2:
                return SymbolicInput(input[0], update=input[1])
            else:
                raise TypeError("Expected two elements in the list or tuple.",
                                input)
        else:
            raise TypeError("Unknown input type: %s (%s), expected Variable "
                            "instance", type(input), input) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:18,代码来源:function_module.py

示例2: test_free

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def test_free(self):
        """
        Make test on free() function
        """
        x = T.vector('x')
        func = function([x], x + 1)
        func.fn.allow_gc = False
        func([1])

        check_list = []
        for key, val in iteritems(func.fn.storage_map):
            if not isinstance(key, theano.gof.Constant):
                check_list.append(val)
        assert any([val[0] for val in check_list])

        func.free()

        for key, val in iteritems(func.fn.storage_map):
            if not isinstance(key, theano.gof.Constant):
                assert (val[0] is None) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:22,代码来源:test_function_module.py

示例3: validate

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def validate(self, fgraph):
        if not hasattr(fgraph, 'destroyers'):
            return True

        outputs_to_validate = list(fgraph.outputs)[self.first_idx:
                                                   self.last_idx]

        for out in outputs_to_validate:

            if out.owner is None:
                continue

            # Validate that the node that produces the output does not produce
            # it by modifying something else inplace.
            node = out.owner
            op = node.op
            out_idx = node.outputs.index(out)
            if hasattr(op, 'destroy_map') and out_idx in op.destroy_map:
                raise theano.gof.InconsistencyError(
                    "A function graph Feature has requested (probably for ",
                    "efficiency reasons for scan) that outputs of the graph",
                    "be prevented from being the result of inplace ",
                    "operations. This has prevented output ", out, " from ",
                    "being computed by modifying another variable ",
                    "inplace.") 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:27,代码来源:toolbox.py

示例4: test_sort_schedule_fn

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def test_sort_schedule_fn():
    import theano
    from theano.gof.sched import sort_schedule_fn, make_depends
    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x[:5] * 2, x.T + 1).T

    def str_cmp(a, b):
        return cmp(str(a), str(b))  # lexicographical sort

    linker = theano.OpWiseCLinker(schedule=sort_schedule_fn(str_cmp))
    mode = theano.Mode(linker=linker)
    f = theano.function((x,), (y,), mode=mode)

    nodes = f.maker.linker.make_all()[-1]
    depends = make_depends()
    for a, b in zip(nodes[:-1], nodes[1:]):
        if not depends((b, a)):
            assert str(a) < str(b) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:20,代码来源:test_link.py

示例5: test_vm_gc

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def test_vm_gc():
    """This already caused a bug in the trunk of Theano.

    The bug was introduced in the trunk on July 5th, 2012 and fixed on
    July 30th.

    """
    x = theano.tensor.vector()
    p = RunOnce()(x)
    mode = theano.Mode(linker=theano.gof.vm.VM_Linker(lazy=True))
    f = theano.function([theano.In(x, mutable=True)], [p + 1, p + 2],
                        mode=mode)
    f([1, 2, 3])

    p = RunOnce()(x)
    pp = p + p
    f = theano.function([x], [pp + pp],
                        mode=mode)
    f([1, 2, 3]) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:test_vm.py

示例6: test_composite_printing

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def test_composite_printing(self):
        x, y, z = floats('xyz')
        e0 = x + y + z
        e1 = x + y * z
        e2 = x / y
        e3 = x // 5
        e4 = -x
        e5 = x - y
        e6 = x ** y + (-z)
        e7 = x % 3
        C = Composite([x, y, z], [e0, e1, e2, e3, e4, e5, e6, e7])
        c = C.make_node(x, y, z)
        g = FunctionGraph([x, y, z], c.outputs)
        fn = gof.DualLinker().accept(g).make_function()

        assert str(g) == ('[*1 -> Composite{((i0 + i1) + i2),'
                          ' (i0 + (i1 * i2)), (i0 / i1), '
                          '(i0 // Constant{5}), '
                          '(-i0), (i0 - i1), ((i0 ** i1) + (-i2)),'
                          ' (i0 % Constant{3})}(x, y, z), '
                          '*1::1, *1::2, *1::3, *1::4, *1::5, *1::6, *1::7]') 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:test_basic.py

示例7: test_not

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def test_not(self):
        x, y, z = ints('xyz')
        fn = gof.DualLinker().accept(FunctionGraph([x, y], [invert(x)])).make_function()
        for a, b in ((0, 1), (0, 0), (1, 0), (1, 1)):
            self.assertTrue(fn(a, b) == ~a, (a,))

        x, y, z = ints('xyz')
        fn = gof.DualLinker().accept(FunctionGraph([x, y], [~x])).make_function()
        for a, b in ((0, 1), (0, 0), (1, 0), (1, 1)):
            self.assertTrue(fn(a, b) == ~a, (a,))


# This class does not inherit from unittest.TestCase, because it would
# interfere with the "yield" mechanism that automatically generates test, see
# http://stackoverflow.com/questions/6689537/nose-test-generators-inside-class
# Therefore, it needs to be named "test_..." or "Test_...", so nose can pick
# it up by name, otherwise the tests would not be executed. 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:19,代码来源:test_basic.py

示例8: as_scalar

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def as_scalar(x, name=None):
    from ..tensor import TensorType, scalar_from_tensor
    if isinstance(x, gof.Apply):
        if len(x.outputs) != 1:
            raise ValueError("It is ambiguous which output of a multi-output"
                             " Op has to be fetched.", x)
        else:
            x = x.outputs[0]
    if isinstance(x, Variable):
        if isinstance(x.type, Scalar):
            return x
        elif isinstance(x.type, TensorType) and x.ndim == 0:
            return scalar_from_tensor(x)
        else:
            raise TypeError("Variable type field must be a Scalar.", x, x.type)
    try:
        return constant(x)
    except TypeError:
        raise TypeError("Cannot convert %s to Scalar" % x, type(x)) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:basic.py

示例9: c_code_contiguous

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def c_code_contiguous(self, node, name, inputs, outputs, sub):
        (x,) = inputs
        (z,) = outputs
        if (not theano.config.lib.amdlibm or
                # We compare the dtype AND the broadcast flag
                # as this function do not broadcast
                node.inputs[0].type != node.outputs[0].type):
            raise theano.gof.utils.MethodNotDefined()

        dtype = node.inputs[0].type.dtype_specs()[1]
        fct_call = self.c_code_contiguous_raw(dtype, 'n', 'x', 'z')
        return """
{
        npy_intp n = PyArray_SIZE(%(z)s);
        %(dtype)s * x = (%(dtype)s*) PyArray_DATA(%(x)s);
        %(dtype)s * z = (%(dtype)s*) PyArray_DATA(%(z)s);
        %(fct_call)s;
}
        """ % locals() 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:basic.py

示例10: c_support_code_apply

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def c_support_code_apply(self, node, name):
        rval = []
        for subnode, subnodename in zip(self.fgraph.toposort(), self.nodenames):
            try:
                subnode_support_code = subnode.op.c_support_code_apply(
                    subnode,
                    subnodename % dict(nodename=name))
                if subnode_support_code:
                    rval.append(subnode_support_code)
            except gof.utils.MethodNotDefined:
                pass
        # there should be no need to remove duplicate code blocks because
        # each block should have been specialized for the given nodename.
        # Any block that isn't specialized should be returned via
        # c_support_code instead of c_support_code_apply.
        return "\n".join(rval) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:18,代码来源:basic.py

示例11: test_value

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def test_value(x):
    if isinstance(x, np.ndarray):
        return x
    return theano.gof.op.get_test_value(x) 
开发者ID:hjimce,项目名称:Depth-Map-Prediction,代码行数:6,代码来源:thutil.py

示例12: c_no_compile_args

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def c_no_compile_args(self):
        # when the ksph==(1,1) gcc 4.3.0 segfault during the
        # compilation with -O3.  This don't happen at -O2
        if (theano.gof.cmodule.gcc_version() in ['4.3.0'] and
                self.kshp == (1, 1)):
            return ['-O3']
        else:
            return [] 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:10,代码来源:conv.py

示例13: c_compile_args

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def c_compile_args(self):
        ret = []

        if self.use_blas():
            ret = blas.ldflags(libs=False, flags=True)
        if (theano.gof.cmodule.gcc_version() in ['4.3.0'] and
                self.kshp == (1, 1)):
            ret += ['-O2']
        # Add the -fopenmp flags
        ret += super(ConvOp, self).c_compile_args()

        return ret 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:14,代码来源:conv.py

示例14: __init__

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def __init__(self, **kwargs):
        gof.Op.__init__(self, **kwargs) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:4,代码来源:nnet.py

示例15: make_node

# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def make_node(self, path):
        if isinstance(path, str):
            path = Constant(Generic(), path)
        return gof.Apply(self, [path], [tensor(self.dtype,
                                        broadcastable=self.broadcastable)]) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:7,代码来源:io.py


注:本文中的theano.gof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。