Beispiel #1
0
 def backward(self, x, gy):
     # Unpack 1-length tuples
     gy, = gy
     # Gradient is - x^-T (dx) x^-T
     ret = matmul._matmul(-self.invx, gy, transa=True)
     ret2 = matmul._matmul(ret, self.invx, transb=True)
     return ret2,
Beispiel #2
0
 def backward(self, x, gy):
     # Unpack 1-length tuples
     gy, = gy
     # Gradient is - x^-T (dx) x^-T
     ret = matmul._matmul(-self.invx, gy, transa=True)
     ret2 = matmul._matmul(ret, self.invx, transb=True)
     return ret2,
Beispiel #3
0
 def backward(self, x, gy):
     a, = x
     ga = _matmul(gy[0],
                  self.b,
                  transb=not self.transb,
                  transout=self.transa).reshape(a.shape)
     return ga,
Beispiel #4
0
 def backward(self, x, gy):
     if gy[0].ndim == 0:
         gx1 = gy[0] * self.value
     else:
         gx1 = _matmul._matmul(
             self.value, gy[0], transa=True, transout=False
         ).reshape(self._x_shape)
     return gx1,
Beispiel #5
0
 def backward(self, x, gy):
     if gy[0].ndim == 0:
         gx1 = gy[0] * self.value
     else:
         gx1 = _matmul._matmul(
             self.value, gy[0], transa=True, transout=False
         ).reshape(self._x_shape)
     return gx1,
Beispiel #6
0
 def backward_cpu(self, x, gy):
     a, = x
     b = self.b
     ga = numpy.empty_like(a)
     a0shape = a[0].shape
     for i in six.moves.range(len(a)):
         ga[i] = _matmul(
             gy[0][i], b[i], transb=not self.transb,
             transout=self.transa).reshape(a0shape)
     return ga,
Beispiel #7
0
 def forward_cpu(self, x):
     a, = x
     b = self.b
     batch_size = a.shape[0]
     shape = self._output_shape(a, b)
     ret_dtype = numpy.find_common_type([a.dtype, b.dtype], [])
     ret = numpy.empty(shape, dtype=ret_dtype)
     for i in six.moves.range(batch_size):
         ret[i] = _matmul(
             a[i], b[i], transa=self.transa, transb=self.transb)
     return ret,
Beispiel #8
0
 def forward(self, x):
     return _matmul._matmul(x[0], self.value),
Beispiel #9
0
 def forward(self, x):
     self.retain_inputs(())
     self._x_shape = x[0].shape
     return utils.force_array(_matmul._matmul(self.value, x[0])),
Beispiel #10
0
 def forward(self, x):
     self.retain_inputs(())
     self._x_shape = x[0].shape
     return utils.force_array(_matmul._matmul(self.value, x[0])),
Beispiel #11
0
 def forward(self, x):
     self.retain_inputs(())
     self._x_shape = x[0].shape
     return _matmul._matmul(self.value, x[0]),
Beispiel #12
0
 def forward(self, x):
     a, = x
     return _matmul(a, self.b, transa=self.transa, transb=self.transb),
Beispiel #13
0
 def backward(self, x, gy):
     gx0 = _matmul._matmul(gy[0], self.value, transb=True, transout=False).reshape(x[0].shape)
     return (gx0,)
Beispiel #14
0
 def backward(self, x, gy):
     gx1 = _matmul._matmul(
         self.value, gy[0], transa=True, transout=False
     ).reshape(x[0].shape)
     return gx1,
Beispiel #15
0
 def forward(self, x):
     return _matmul._matmul(self.value, x[0]),
Beispiel #16
0
 def backward(self, x, gy):
     gx0 = _matmul._matmul(gy[0], self.value, transb=True,
                           transout=False).reshape(self._x_shape)
     return gx0,
Beispiel #17
0
 def forward(self, x):
     self.retain_inputs((0, ))
     return utils.force_array(_matmul._matmul(self.value, x[0])),
Beispiel #18
0
 def forward(self, x):
     self.retain_inputs((0,))
     return utils.force_array(_matmul._matmul(self.value, x[0])),
Beispiel #19
0
 def backward(self, x, gy):
     gx0 = _matmul(
         gy[0], self.b, transb=not self.transb, transout=self.transa
     ).reshape(x[0].shape)
     return gx0,