예제 #1
0
def TileGrad(op, grad):
    return [
        xdl.tile_grad(op.inputs[0],
                      op.inputs[1],
                      op.inputs[2],
                      op.inputs[3],
                      op.inputs[4],
                      grad[0],
                      length=op.attrs['length'],
                      reverse=op.attrs['reverse'])
    ]
예제 #2
0
 def test_cpu_tile(self):
     res = xdl.tile_grad(embeds,
                         idx,
                         values,
                         segs,
                         grps,
                         grads,
                         length=length,
                         reverse=False)
     res = xdl.execute(res)
     res_grad = np.array([[10.7], [3.9], [0.1], [12.1], [4.8], [13.5]],
                         dtype=np.float)
     self.assertTrue(np.allclose(res, res_grad))
예제 #3
0
 def test_cpu_tile_reverse(self):
     res = xdl.tile_grad(embeds,
                         idx,
                         values,
                         segs,
                         grps,
                         grads,
                         length=length,
                         reverse=True)
     res = xdl.execute(res)
     res_grad = np.array([[1.6], [4.4], [13.3], [12.3], [4.2], [12.6]],
                         dtype=np.float)
     self.assertTrue(np.allclose(res, res_grad))
예제 #4
0
 def test_cpu_tile_empty_value_reverse(self):
     empty_values = np.array([], dtype=np.float)
     res = xdl.tile_grad(embeds,
                         idx,
                         empty_values,
                         segs,
                         grps,
                         grads,
                         length=length,
                         reverse=True)
     res = xdl.execute(res)
     res_grad = np.array([[0.4], [1.0], [1.6], [1.6], [0.7], [1.4]],
                         dtype=np.float)
     self.assertTrue(np.allclose(res, res_grad))
예제 #5
0
 def test_gpu_tile_empty_value(self):
     with xdl.device("GPU"):
         empty_values = np.array([], dtype=np.float)
         res = xdl.tile_grad(embeds,
                             idx,
                             empty_values,
                             segs,
                             grps,
                             grads,
                             length=length,
                             reverse=False)
         res = xdl.execute(res)
         res_grad = np.array([[1.7], [0.9], [0.1], [1.7], [0.8], [1.5]],
                             dtype=np.float)
         self.assertTrue(np.allclose(res, res_grad))