def forward_cpu(self, inputs): gy, = inputs gx1 = utils.force_array(numpy.where(self.cond, gy, gy.dtype.type(0))) gx2 = utils.force_array(numpy.where(self.cond, gy.dtype.type(0), gy)) return ( utils.sum_to(gx1, self.x1_shape), utils.sum_to(gx2, self.x2_shape))
def forward_gpu(self, inputs): gy, = inputs gx1, gx2 = cuda.elementwise( 'S cond, T gy', 'T gx1, T gx2', ''' gx1 = cond ? gy : (T)0.0; gx2 = cond ? (T)0.0 : gy; ''', 'maximum_bwd1')(self.cond, gy) return (utils.sum_to(gx1, self.x1_shape), utils.sum_to(gx2, self.x2_shape))
def forward_gpu(self, inputs): self.retain_inputs((0, 1, 2)) x0, x1, gy = inputs gx0, gx1 = cuda.elementwise( 'T x0, T x1, T gy', 'T gx0, T gx1', ''' gx0 = gy / x1; gx1 = -gx0 * x0 / x1; ''', 'div_bwd')(x0, x1, gy) return utils.sum_to(gx0, x0.shape), utils.sum_to(gx1, x1.shape)
def forward_cpu(self, inputs): self.retain_inputs((0, 1, 2)) x0, x1, gy = inputs one = x1.dtype.type(1) gx0 = utils.sum_to(utils.force_array(x1 * (x0**(x1 - one)) * gy), x0.shape) gx1 = utils.sum_to(utils.force_array(numpy.log(x0) * self.y * gy), x1.shape) return gx0, gx1
def forward_cpu(self, inputs): self.retain_inputs((0, 1, 2)) x0, x1, gy = inputs one = x1.dtype.type(1) gx0 = utils.sum_to( utils.force_array(x1 * (x0 ** (x1 - one)) * gy), x0.shape) gx1 = utils.sum_to( utils.force_array(numpy.log(x0) * self.y * gy), x1.shape) return gx0, gx1
def forward_gpu(self, inputs): gy, = inputs x1, x2 = self.x1, self.x2 gx1 = cuda.elementwise('T x1, T x2, T gy', 'T gx1', 'gx1 = (x1 <= x2) ? gy : (T)0.0', 'minimum_bwd1')(x1, x2, gy) gx2 = cuda.elementwise('T x1, T x2, T gy', 'T gx1', 'gx1 = (x1 > x2) ? gy : (T)0.0', 'minimum_bwd2')(x1, x2, gy) return utils.sum_to(gx1, x1.shape), utils.sum_to(gx2, x2.shape)
def forward_gpu(self, inputs): gy, = inputs x1, x2 = self.x1, self.x2 gx1 = cuda.elementwise( 'T x1, T x2, T gy', 'T gx1', 'gx1 = (x1 <= x2) ? gy : (T)0.0', 'minimum_bwd1')(x1, x2, gy) gx2 = cuda.elementwise( 'T x1, T x2, T gy', 'T gx1', 'gx1 = (x1 > x2) ? gy : (T)0.0', 'minimum_bwd2')(x1, x2, gy) return utils.sum_to(gx1, x1.shape), utils.sum_to(gx2, x2.shape)
def forward_gpu(self, inputs): gy, = inputs gx1, gx2 = cuda.elementwise( 'S cond, T gy', 'T gx1, T gx2', ''' gx1 = cond ? gy : (T)0.0; gx2 = cond ? (T)0.0 : gy; ''', 'maximum_bwd1')(self.cond, gy) return ( utils.sum_to(gx1, self.x1_shape), utils.sum_to(gx2, self.x2_shape))
def forward_gpu(self, inputs): self.retain_inputs((0, 1, 2)) x0, x1, gy = inputs gx0, gx1 = cuda.elementwise( 'T x0, T x1, T gy, T y', 'T gx0, T gx1', ''' gx0 = x1 * pow(x0, x1 - 1) * gy; gx1 = log(x0) * y * gy; ''', 'pow_var_var_bwd')(x0, x1, gy, self.y) gx0 = utils.sum_to(gx0, x0.shape) gx1 = utils.sum_to(gx1, x1.shape) return gx0, gx1
def forward_cpu(self, inputs): self.retain_inputs((0, 1, 2)) x0, x1, gy = inputs gx0 = utils.force_array(gy / x1) gx1 = utils.force_array(-gx0 * x0 / x1) return utils.sum_to(gx0, x0.shape), utils.sum_to(gx1, x1.shape)
def forward(self, inputs): x, = inputs return utils.sum_to(x, self._shape),
def forward_cpu(self, inputs): gy, = inputs x1, x2 = self.x1, self.x2 gx1 = utils.force_array(gy * (x1 <= x2)) gx2 = utils.force_array(gy * (x1 > x2)) return utils.sum_to(gx1, x1.shape), utils.sum_to(gx2, x2.shape)