提交 3cd25b78 authored 作者: ChienliMa's avatar ChienliMa

1.fix typo\n2.move import to the top\n3.replace (1-pos_offset_flag) with…

1.fix typo\n2.move import to the top\n3.replace (1-pos_offset_flag) with neg_offset_flag\n4.replace grad.shape[1] with a.shape[1]\n5.remove axis_grad\n Waited to be done rewrite test_extro_ops]
上级 de18576d
......@@ -2,7 +2,10 @@ import numpy as np
import numpy
import theano
import theano.tensor as T
from theano.tensor import basic
from theano import gof, scalar
tensor = basic
from theano.gradient import DisconnectedType
......@@ -813,27 +816,27 @@ class FillDiagonalOffset(gof.Op):
# only valid for matrices
wr_a = fill_diagonal_offset(grad, 0, offset)
import theano.tensor as T
offset_abs = T.abs_( offset )
pos_offset_flag = T.ge( offset, 0 )
neg_offset_flag = T.lt( offset, 0 )
min_wh = T.minimum(width,height)
start = offset * pos_offset_flag + offset_abs * width \
* (1-pos_offset_flag)
min_wh = T.minimum(width,height)
* neg_offset_flag
num_of_step = T.minimum( min_wh, width * pos_offset_flag
+ height * ( 1 - pos_offset_flag ) - offset_abs )
+ height * neg_offset_flag - offset_abs )
step = grad.shape[1] + 1
step = a.shape[1] + 1
end = start + step * num_of_step
# input of slide should be integer
# input of slice should be integer
start = T.cast(start,'int32')
step = T.cast(step,'int32')
end = T.cast(end,'int32')
wr_val = grad.flatten()[start:end:step].sum()
wr_offset = axis_grad = theano.gradient.grad_undefined(
wr_offset = theano.gradient.grad_undefined(
self, 2, offset,
"offset is not defined for non-integer offset so"
" fill_diagonal_offset(a,val,offset+eps) is undefined")
......
......@@ -408,6 +408,7 @@ class TestBartlett(utt.InferShapeTester):
self._compile_and_check([x], [self.op(x)], [0], self.op_class)
self._compile_and_check([x], [self.op(x)], [1], self.op_class)
class TestFillDiagonal(utt.InferShapeTester):
rng = numpy.random.RandomState(43)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论