quadrants.lang.field#

Classes#

Field

Quadrants field class.

ScalarField

Quadrants scalar field with SNode implementation.

BitpackedFields

Quadrants bitpacked fields, where fields with quantized types are packed together.

Module Contents#

class quadrants.lang.field.Field(_vars)[source]#

Quadrants field class.

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++ FieldExpression.

Parameters:

vars (List[Expr]) – Field members.

vars[source]#
host_accessors = None[source]#
grad = None[source]#
dual = None[source]#
property snode[source]#

Gets representative SNode for info purposes.

Returns:

Representative SNode (SNode of first field member).

Return type:

SNode

property shape: tuple[int, Ellipsis][source]#
property dtype: quadrants._lib.core.quadrants_python.DataTypeCxx[source]#
parent(n=1)[source]#

n (int): the number of levels going up from the representative SNode.

abstract fill(val: int | float) None[source]#
abstract to_numpy(dtype: quadrants._lib.core.quadrants_python.DataTypeCxx | None = None)[source]#

Converts self to a numpy array.

Returns:

The result numpy array.

Return type:

numpy.ndarray

abstract to_torch(device=None)[source]#

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(arr)[source]#

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(arr)[source]#

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(other: Field) None[source]#

Copies all elements from another field.

The shape of the other field needs to be the same as self.

class quadrants.lang.field.ScalarField(var)[source]#

Bases: Field

Quadrants scalar field with SNode implementation.

Parameters:

var (Expr) – Field member.

to_dlpack()[source]#

Note: caller is responsible for calling ti.sync() between modifying the field, and reading it.

fill(val)[source]#

Fills this scalar field with a specified value.

to_numpy(dtype=None)[source]#

Converts this field to a numpy.ndarray.

to_torch(device=None)[source]#

Converts this field to a torch.tensor.

from_numpy(arr)[source]#

Copies the data from a numpy.ndarray into this field.

class quadrants.lang.field.BitpackedFields(max_num_bits)[source]#

Quadrants 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.

fields = [][source]#
bit_struct_type_builder[source]#
place(*args, shared_exponent=False)[source]#

Places a list of fields with quantized types inside.

Parameters:
  • *args (List[Field]) – A list of fields with quantized types to place.

  • shared_exponent (bool) – Whether the fields have a shared exponent.