taichi.lang.field
¶
Module Contents¶
Classes¶
Taichi field with SNode implementation. |
|
Taichi scalar field with SNode implementation. |
|
- 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.
- property snode(self)¶
Gets representative SNode for info purposes.
- Returns
Representative SNode (SNode of first field member).
- Return type
- property shape(self)¶
Gets field shape.
- Returns
Field shape.
- Return type
Tuple[Int]
- property dtype(self)¶
Gets data type of each individual value.
- Returns
Data type of each individual value.
- Return type
DataType
- property name(self)¶
Gets field name.
- Returns
Field name.
- Return type
str
- 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
- loop_range(self)¶
Gets representative field member for loop range info.
- Returns
Representative (first) field member.
- Return type
taichi_core.Expr
- set_grad(self, grad)¶
Sets corresponding gradient field.
- Parameters
grad (Field) – Corresponding gradient field.
- abstract fill(self, val)¶
Fills self with a specific value.
- Parameters
val (Union[int, float]) – Value to fill.
- 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_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
- 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_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.
- 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.
- pad_key(self, key)¶
- initialize_host_accessors(self)¶
- host_access(self, key)¶
- class taichi.lang.field.ScalarField(var)¶
Bases:
Field
Taichi scalar field with SNode implementation.
- Parameters
var (Expr) – Field member.
- fill(self, val)¶
Fills self with a specific value.
- Parameters
val (Union[int, float]) – Value to fill.
- 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
- 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
- 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.
- class taichi.lang.field.SNodeHostAccessor(snode)¶
- class taichi.lang.field.SNodeHostAccess(accessor, key)¶