Esempio n. 1
0
 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))
Esempio n. 2
0
 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))
Esempio n. 3
0
 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)
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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))
Esempio n. 10
0
    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
Esempio n. 11
0
    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
Esempio n. 12
0
 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)
Esempio n. 13
0
 def forward(self, inputs):
     x, = inputs
     return utils.sum_to(x, self._shape),
Esempio n. 14
0
 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)
Esempio n. 15
0
 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)
Esempio n. 16
0
 def forward(self, inputs):
     x, = inputs
     return utils.sum_to(x, self._shape),