示例#1
0
 def forward(self, x):
     self.x_shape = x.shape
     y = utils.sum_to(x, self.shape)
     return y
示例#2
0
 def backward(self, gy):
     gx = utils.sum_to(gy, self.x_shape)
     return gx
示例#3
0
    def test_sum_to(self):
        y = np.ones((3, 4, 5, 6))

        self.assertEqual(sum_to(y, (5, 6)).shape, (5, 6))
        self.assertEqual(sum_to(y, (5, 1)).shape, (5, 1))
示例#4
0
 def forward(self, x):
     y = utils.sum_to(x, self.shape)
     return y
示例#5
0
 def forward(self, *xs: np.ndarray) -> tuple[np.ndarray, ...]:
     x, = xs
     self.x_shape = x.shape
     y = utils.sum_to(x, self.shape)
     return y,
示例#6
0
if '__file__' in globals():
    import os
    import sys
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    import numpy as np
    from dezero.utils import sum_to


x = np.array([[1, 2, 3], [4, 5, 6]])
y = sum_to(x, (1, 3))

print(y)

y = sum_to(x, (2, 1))
print(y)