本文整理汇总了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)
示例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)
示例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.")
示例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)
示例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])
示例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]')
示例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.
示例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))
示例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()
示例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)
示例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)
示例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 []
示例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
示例14: __init__
# 需要导入模块: import theano [as 别名]
# 或者: from theano import gof [as 别名]
def __init__(self, **kwargs):
gof.Op.__init__(self, **kwargs)
示例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)])