taichi.lang.field
#
- class taichi.lang.field.BitpackedFields(max_num_bits)#
Taichi bitpacked fields, where fields with quantized types are packed together.
- Parameters:
max_num_bits (int) – Maximum number of bits all fields inside can occupy in total. Only 32 or 64 is allowed.
- class taichi.lang.field.Field(_vars)#
Taichi field with SNode implementation.
A field is constructed by a list of field members. For example, a scalar field has 1 field member, while a 3x3 matrix field has 9 field members. A field member is a Python Expr wrapping a C++ GlobalVariableExpression. A C++ GlobalVariableExpression wraps the corresponding SNode.
- Parameters:
vars (List[Expr]) – Field members.
- copy_from(self, other)#
Copies all elements from another field.
The shape of the other field needs to be the same as self.
- Parameters:
other (Field) – The source field.
- property dtype(self)#
Gets data type of each individual value.
- Returns:
Data type of each individual value.
- Return type:
DataType
- abstract fill(self, val)#
Fills self with a specific value.
- Parameters:
val (Union[int, float]) – Value to fill.
- abstract from_numpy(self, arr)#
Loads all elements from a numpy array.
The shape of the numpy array needs to be the same as self.
- Parameters:
arr (numpy.ndarray) – The source numpy array.
- from_paddle(self, arr)#
Loads all elements from a paddle tensor.
The shape of the paddle tensor needs to be the same as self.
- Parameters:
arr (paddle.Tensor) – The source paddle tensor.
- from_torch(self, arr)#
Loads all elements from a torch tensor.
The shape of the torch tensor needs to be the same as self.
- Parameters:
arr (torch.tensor) – The source torch tensor.
- parent(self, n=1)#
Gets an ancestor of the representative SNode in the SNode tree.
- Parameters:
n (int) – the number of levels going up from the representative SNode.
- Returns:
The n-th parent of the representative SNode.
- Return type:
- property shape(self)#
Gets field shape.
- Returns:
Field shape.
- Return type:
Tuple[Int]
- property snode(self)#
Gets representative SNode for info purposes.
- Returns:
Representative SNode (SNode of first field member).
- Return type:
- abstract to_numpy(self, dtype=None)#
Converts self to a numpy array.
- Parameters:
dtype (DataType, optional) – The desired data type of returned numpy array.
- Returns:
The result numpy array.
- Return type:
numpy.ndarray
- abstract to_paddle(self, place=None)#
Converts self to a paddle tensor.
- Parameters:
place (paddle.CPUPlace()/CUDAPlace(n), optional) – The desired place of returned tensor.
- Returns:
The result paddle tensor.
- Return type:
paddle.Tensor
- abstract to_torch(self, device=None)#
Converts self to a torch tensor.
- Parameters:
device (torch.device, optional) – The desired device of returned tensor.
- Returns:
The result torch tensor.
- Return type:
torch.tensor
- class taichi.lang.field.ScalarField(var)#
Bases:
Field
Taichi scalar field with SNode implementation.
- Parameters:
var (Expr) – Field member.
- copy_from(self, other)#
Copies all elements from another field.
The shape of the other field needs to be the same as self.
- Parameters:
other (Field) – The source field.
- property dtype(self)#
Gets data type of each individual value.
- Returns:
Data type of each individual value.
- Return type:
DataType
- fill(self, val)#
Fills this scalar field with a specified value.
- from_numpy(self, arr)#
Copies the data from a numpy.ndarray into this field.
- from_paddle(self, arr)#
Loads all elements from a paddle tensor.
The shape of the paddle tensor needs to be the same as self.
- Parameters:
arr (paddle.Tensor) – The source paddle tensor.
- from_torch(self, arr)#
Loads all elements from a torch tensor.
The shape of the torch tensor needs to be the same as self.
- Parameters:
arr (torch.tensor) – The source torch tensor.
- parent(self, n=1)#
Gets an ancestor of the representative SNode in the SNode tree.
- Parameters:
n (int) – the number of levels going up from the representative SNode.
- Returns:
The n-th parent of the representative SNode.
- Return type:
- property shape(self)#
Gets field shape.
- Returns:
Field shape.
- Return type:
Tuple[Int]
- property snode(self)#
Gets representative SNode for info purposes.
- Returns:
Representative SNode (SNode of first field member).
- Return type:
- to_numpy(self, dtype=None)#
Converts this field to a numpy.ndarray.
- to_paddle(self, place=None)#
Converts this field to a paddle.Tensor.
- to_torch(self, device=None)#
Converts this field to a torch.tensor.