提交 beb28c64 authored 作者: Nicolas Bouchard's avatar Nicolas Bouchard

Change directories

上级 ef088251
from extra_ops import (DiffOp, diff,
BinCountOp, bincount)
import theano import theano
import numpy as np import numpy as np
from theano import tensor as T import basic
class DiffOp(theano.Op): class DiffOp(theano.Op):
...@@ -31,7 +31,7 @@ class DiffOp(theano.Op): ...@@ -31,7 +31,7 @@ class DiffOp(theano.Op):
return hash(type(self)) ^ hash(self.n) ^ hash(self.axis) return hash(type(self)) ^ hash(self.n) ^ hash(self.axis)
def make_node(self, x): def make_node(self, x):
x = T.as_tensor_variable(x) x = basic.as_tensor_variable(x)
return theano.Apply(self, [x], [x.type()]) return theano.Apply(self, [x], [x.type()])
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
...@@ -49,8 +49,8 @@ class DiffOp(theano.Op): ...@@ -49,8 +49,8 @@ class DiffOp(theano.Op):
z = outputs_gradients[0] z = outputs_gradients[0]
def _grad_helper(z): def _grad_helper(z):
pre = T.concatenate([[0.], z]) pre = basic.concatenate([[0.], z])
app = T.concatenate([z, [0.]]) app = basic.concatenate([z, [0.]])
return pre - app return pre - app
for k in range(self.n): for k in range(self.n):
...@@ -120,7 +120,7 @@ class BinCountOp(theano.Op): ...@@ -120,7 +120,7 @@ class BinCountOp(theano.Op):
return hash(type(self)) ^ hash(self.minlength) return hash(type(self)) ^ hash(self.minlength)
def make_node(self, x, weights): def make_node(self, x, weights):
x = T.as_tensor_variable(x) x = basic.as_tensor_variable(x)
if x.dtype not in BinCountOp.compatible_type: if x.dtype not in BinCountOp.compatible_type:
raise TypeError("Inputs dtype must be an integer.") raise TypeError("Inputs dtype must be an integer.")
...@@ -131,7 +131,7 @@ class BinCountOp(theano.Op): ...@@ -131,7 +131,7 @@ class BinCountOp(theano.Op):
weights = theano.gof.Constant(theano.gof.Generic(), None) weights = theano.gof.Constant(theano.gof.Generic(), None)
out_type = x.type() out_type = x.type()
else: else:
weights = T.as_tensor_variable(weights) weights = basic.as_tensor_variable(weights)
out_type = weights.type() out_type = weights.type()
if weights.ndim != 1: if weights.ndim != 1:
raise TypeError("Weights cannot have a number of" raise TypeError("Weights cannot have a number of"
...@@ -154,9 +154,9 @@ class BinCountOp(theano.Op): ...@@ -154,9 +154,9 @@ class BinCountOp(theano.Op):
def infer_shape(self, node, ins_shapes): def infer_shape(self, node, ins_shapes):
x = node.inputs[0] x = node.inputs[0]
m = T.max(x) + 1 m = basic.max(x) + 1
if self.minlength != None: if self.minlength != None:
m = T.maximum(m, self.minlength) m = basic.maximum(m, self.minlength)
return [[m]] return [[m]]
def __str__(self): def __str__(self):
......
...@@ -3,7 +3,7 @@ import numpy as np ...@@ -3,7 +3,7 @@ import numpy as np
from theano import tensor as T from theano import tensor as T
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.extra_ops import * from theano.tensor.extra_ops import *
class TestBinCountOp(utt.InferShapeTester): class TestBinCountOp(utt.InferShapeTester):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论