跳转至主要内容

taichi.sparse#

taichi.sparse.grid(field_dict, shape)#

Creates a 2D/3D sparse grid with each element is a struct. The struct is placed on a bitmasked snode.

Parameters:
  • field_dict (dict) – a dict, each item is like name: type.

  • shape (Tuple[int]) – shape of the field.

Returns:

the created sparse grid, which is a bitmasked ti.Struct.field.

Return type:

x

Examples::

# create a 2D sparse grid >>> grid = ti.sparse.grid({‘pos’: ti.math.vec2, ‘mass’: ti.f32, ‘grid2particles’: ti.types.vector(20, ti.i32)}, shape=(10, 10))

# access >>> grid[0, 0].pos = ti.math.vec2(1.0, 2.0) >>> grid[0, 0].mass = 1.0 >>> grid[0, 0].grid2particles[2] = 123

# print the usage of the sparse grid, which is in [0,1] >>> print(ti.sparse.usage(grid)) # 0.009999999776482582

taichi.sparse.usage(x: template()) taichi.types.primitive_types.f32#

Get the usage of the sparse grid, which is in [0,1]

Parameters:

x (struct field) – the sparse grid to be checked.

Returns:

the usage of the sparse grid, which is in [0,1]

Return type:

usage(f32)

Examples::
>>> grid = ti.sparse.grid({'pos': ti.math.vec2, 'mass': ti.f32, 'grid2particles': ti.types.vector(20, ti.i32)}, shape=(10, 10))
>>> grid[0, 0].mass = 1.0
>>> print(ti.sparse.usage(grid))
# 0.009999999776482582
本文有帮助吗?