Fix test for backprop d_pad

This commit is contained in:
Matthew Honnibal 2017-11-03 14:04:16 +01:00
parent 33bd2428db
commit 0a534ae96a
1 changed files with 12 additions and 2 deletions

View File

@ -69,10 +69,20 @@ def test_PrecomputableAffine(nO=4, nI=5, nF=3, nP=2):
Y, get_dX = model.begin_update(tensor)
assert Y.shape == (tensor.shape[0]+1, nF, nO, nP)
assert model.d_pad.shape == (1, nF, nO, nP)
dY = model.ops.allocate((15, nF, nO, nP))
dY = model.ops.allocate((15, nO, nP))
ids = model.ops.allocate((15, nF))
ids[1,2] = -1
dY[1,2] = 1
dY[1] = 1
assert model.d_pad[0, 2, 0, 0] == 0.
model._backprop_padding(dY, ids)
assert model.d_pad[0, 2, 0, 0] == 1.
model.d_pad.fill(0.)
ids.fill(0.)
dY.fill(0.)
ids[1,2] = -1
ids[1,1] = -1
ids[1,0] = -1
dY[1] = 1
assert model.d_pad[0, 2, 0, 0] == 0.
model._backprop_padding(dY, ids)
assert model.d_pad[0, 2, 0, 0] == 3.