예제 #1
0
 def from_numpy(self, ndarray):
     if len(ndarray.shape) == len(self.loop_range().shape) + 1:
         as_vector = True
         assert self.m == 1, "This matrix is not a vector"
     else:
         as_vector = False
         assert len(ndarray.shape) == len(self.loop_range().shape) + 2
     dim_ext = 1 if as_vector else 2
     assert len(ndarray.shape) == len(self.loop_range().shape) + dim_ext
     from taichi.lang.meta import ext_arr_to_matrix
     ext_arr_to_matrix(ndarray, self, as_vector)
     ti.sync()
예제 #2
0
파일: matrix.py 프로젝트: quadpixels/taichi
 def from_numpy(self, arr):
     if len(arr.shape) == len(self.shape) + 1:
         as_vector = True
         assert self.m == 1, "This is not a vector field"
     else:
         as_vector = False
         assert len(arr.shape) == len(self.shape) + 2
     dim_ext = 1 if as_vector else 2
     assert len(arr.shape) == len(self.shape) + dim_ext
     from taichi.lang.meta import ext_arr_to_matrix
     ext_arr_to_matrix(arr, self, as_vector)
     ti.sync()
예제 #3
0
    def from_numpy(self, ndarray):
        """Copy the values of a numpy ndarray to the Matrix.

        Args:
            ndarray (numpy.ndarray): The numpy array to copy.

        """
        if len(ndarray.shape) == len(self.loop_range().shape) + 1:
            as_vector = True
            assert self.m == 1, "This matrix is not a vector"
        else:
            as_vector = False
            assert len(ndarray.shape) == len(self.loop_range().shape) + 2
        dim_ext = 1 if as_vector else 2
        assert len(ndarray.shape) == len(self.loop_range().shape) + dim_ext
        from taichi.lang.meta import ext_arr_to_matrix
        ext_arr_to_matrix(ndarray, self, as_vector)
        ti.sync()