(self, in_obj)
return self
Configure the output shape based on input shape and reshape shape.
        The function replaces 0 and -1 and add the batch size dimension.
Configure the output shape based on input shape and reshape shape.
        The function replaces 0 and -1 and add the batch size dimension.
Configure the output shape based on input shape and reshape shape . The function replaces 0 and - 1 and add the batch size dimension .
def configure(self, in_obj):
        """
        Configure the output shape based on input shape and reshape shape.
        The function replaces 0 and -1 and add the batch size dimension.
        """
        super(Reshape, self).configure(in_obj)
        if isinstance(self.in_shape, tuple):
            if len(self.in_shape) == 2:
                self.in_shape_t = (
                    self.in_shape[0], self.in_shape[1] * self.be.bsz)
            else:
                self.in_shape_t = (int(np.prod(self.in_shape)), self.be.bsz)
        else:
            self.in_shape_t = (self.in_shape, self.be.bsz)

        self.out_shape = list(self.reshape)

        if 0 in self.reshape:
            dim_to_keep = np.where(np.array(self.reshape) == 0)[0][0]
            self.out_shape[dim_to_keep] = list(self.in_shape)[dim_to_keep]

        if -1 in self.reshape:
            missing_dim = -int(np.prod(self.in_shape)) // int(np.prod(self.out_shape))
            self.out_shape = [missing_dim if x == -1 else x for x in self.out_shape]

        self.out_shape = tuple(self.out_shape)

        if len(self.out_shape) == 2:
            self.out_shape_t = (
                self.out_shape[0], self.out_shape[1] * self.be.bsz)
        else:
            self.out_shape_t = (int(np.prod(self.out_shape)), self.be.bsz)

        assert np.prod(self.out_shape) == np.prod(self.in_shape)
        return self
def configure ( self , in_obj ) : super ( Reshape , self ) . configure ( in_obj ) if isinstance ( self . in_shape , tuple ) : if len ( self . in_shape ) == 2 : self . in_shape_t = ( self . in_shape [ 0 ] , self . in_shape [ 1 ] * self . be . bsz ) else : self . in_shape_t = ( int ( np . prod ( self . in_shape ) ) , self . be . bsz ) else : self . in_shape_t = ( self . in_shape , self . be . bsz ) self . out_shape = list ( self . reshape ) if 0 in self . reshape : dim_to_keep = np . where ( np . array ( self . reshape ) == 0 ) [ 0 ] [ 0 ] self . out_shape [ dim_to_keep ] = list ( self . in_shape ) [ dim_to_keep ] if - 1 in self . reshape : missing_dim = - int ( np . prod ( self . in_shape ) ) // int ( np . prod ( self . out_shape ) ) self . out_shape = [ missing_dim if x == - 1 else x for x in self . out_shape ] self . out_shape = tuple ( self . out_shape ) if len ( self . out_shape ) == 2 : self . out_shape_t = ( self . out_shape [ 0 ] , self . out_shape [ 1 ] * self . be . bsz ) else : self . out_shape_t = ( int ( np . prod ( self . out_shape ) ) , self . be . bsz ) assert np . prod ( self . out_shape ) == np . prod ( self . in_shape ) return self