Beispiel #1
0
    def forward(self, *args, **kwargs):
        assert len(args) == 1
        assert isinstance(args[0], Tensor)
        assert isinstance(args[0].data, np.ndarray)

        self.A = args[0]

        self.shape = self.A.data.shape

        C_data = self.A.data.reshape(self.target_shape)

        C = Tensor()
        C.data = C_data

        C.left_child = self.A
        # C.right_child = self.B

        C.grad_fn = self

        self.A.parent = C
        #self.B.parent = C

        if self.A.requires_grad:
            C.requires_grad = True

        return C
Beispiel #2
0
    def forward(self, *args):
        assert len(args) == 1
        assert isinstance(args[0], Tensor)

        self.A = args[0]

        C_data = get_sub_ndarray(self.A.data, self.coordinate_tuple)

        C = Tensor()
        C.data = C_data

        C.left_child = self.A
        # C.right_child = self.B

        C.grad_fn = self

        self.A.parent = C
        #self.B.parent = C

        if self.A.requires_grad:
            C.requires_grad = True

        return C