Exemple #1
0
 def to_numpy(self):
     import numpy as np
     from taichi.lang.meta import tensor_to_ext_arr
     arr = np.zeros(shape=self.shape, dtype=to_numpy_type(self.dtype))
     tensor_to_ext_arr(self, arr)
     ti.sync()
     return arr
Exemple #2
0
 def to_torch(self, device=None):
     import torch
     from taichi.lang.meta import tensor_to_ext_arr
     arr = torch.zeros(size=self.shape,
                       dtype=to_pytorch_type(self.dtype),
                       device=device)
     tensor_to_ext_arr(self, arr)
     ti.sync()
     return arr
Exemple #3
0
 def to_numpy(self, dtype=None):
     if dtype is None:
         dtype = to_numpy_type(self.dtype)
     import numpy as np
     arr = np.zeros(shape=self.shape, dtype=dtype)
     from taichi.lang.meta import tensor_to_ext_arr
     tensor_to_ext_arr(self, arr)
     ti.sync()
     return arr
Exemple #4
0
    def to_numpy(self):
        """Create a numpy array containing the same elements when the class itself represents GlobalVariableExpression (field) or ExternalTensorExpression internally.

        This is an unified interface to match :func:`taichi.lang.Matrix.to_numpy`.

        Returns:
            The numpy array containing the same elements when the class itself represents GlobalVariableExpression (field) or ExternalTensorExpression internally.
        """
        import numpy as np
        from taichi.lang.meta import tensor_to_ext_arr
        arr = np.zeros(shape=self.shape, dtype=to_numpy_type(self.dtype))
        tensor_to_ext_arr(self, arr)
        ti.sync()
        return arr
Exemple #5
0
    def to_torch(self, device=None):
        """Create a torch array containing the same elements when the class itself represents GlobalVariableExpression (field) or ExternalTensorExpression internally.

        This is an unified interface to match :func:`taichi.lang.Matrix.to_torch`.

        Args:
            device (DeviceType): The device type as a parameter passed into torch.zeros().

        Returns:
            The torch array containing the same elements when the class itself represents GlobalVariableExpression (field) or ExternalTensorExpression internally.
        """
        import torch
        from taichi.lang.meta import tensor_to_ext_arr
        arr = torch.zeros(size=self.shape,
                          dtype=to_pytorch_type(self.dtype),
                          device=device)
        tensor_to_ext_arr(self, arr)
        ti.sync()
        return arr