提交 4eafb197 authored 作者: notoraptor's avatar notoraptor

Wrap Op params for theano.compile.ops.Shape_i:

- i (scalar, int64)
上级 5c9d3118
...@@ -346,6 +346,18 @@ class Shape_i(gof.Op): ...@@ -346,6 +346,18 @@ class Shape_i(gof.Op):
i = int(i) i = int(i)
self.i = i self.i = i
# NB:
# 1) params_type is defined as a property to avoid
# loop in Python import caused by importing theano.scalar below
# when params_type is defined directly in class code.
# 2) We wrap scalar into ParamsType (instead of directly using scalar as op param)
# to avoid Theano converting scalar param to constant that would be later
# hardcoded as litteral in C code, making us loose all the advantages of
# using params.
@property
def params_type(self):
return gof.ParamsType(i=theano.scalar.basic.int64)
def __str__(self): def __str__(self):
return '%s{%i}' % (self.__class__.__name__, self.i) return '%s{%i}' % (self.__class__.__name__, self.i)
...@@ -360,7 +372,7 @@ class Shape_i(gof.Op): ...@@ -360,7 +372,7 @@ class Shape_i(gof.Op):
(x, self.i)) (x, self.i))
return theano.Apply(self, [x], [theano.tensor.lscalar()]) return theano.Apply(self, [x], [theano.tensor.lscalar()])
def perform(self, node, inp, out_): def perform(self, node, inp, out_, params):
x, = inp x, = inp
out, = out_ out, = out_
if out[0] is None: if out[0] is None:
...@@ -383,7 +395,7 @@ class Shape_i(gof.Op): ...@@ -383,7 +395,7 @@ class Shape_i(gof.Op):
version.append((str(t), v)) version.append((str(t), v))
if version: if version:
version.append(1) version.append(2)
return tuple(version) return tuple(version)
...@@ -391,7 +403,8 @@ class Shape_i(gof.Op): ...@@ -391,7 +403,8 @@ class Shape_i(gof.Op):
iname, = inames iname, = inames
oname, = onames oname, = onames
fail = sub['fail'] fail = sub['fail']
i = self.i # i is then 'params->i', not just 'params'.
i = sub['params'] + '->i'
itype = node.inputs[0].type.__class__ itype = node.inputs[0].type.__class__
if itype in self.c_code_and_version: if itype in self.c_code_and_version:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论