跳到主要内容

taichi.types#

This module defines data types in Taichi:

taichi.types.argpack(**kwargs)#

Creates an argument pack type with given members.

Parameters:

kwargs (dict) – a dictionary contains the names and types of the argument pack members.

Returns:

A argument pack type.

Example:

>>> vec3 = ti.types.vector(3, ti.f32)
>>> sphere = ti.types.argpack(center=vec3, radius=float)
>>> s = sphere(center=vec3([0., 0., 0.]), radius=1.0)
taichi.types.f16#

Alias for float16

taichi.types.f32#

Alias for float32

taichi.types.f64#

Alias for float64

taichi.types.float16#

16-bit precision floating point data type.

taichi.types.float32#

32-bit single precision floating point data type.

taichi.types.float64#

64-bit double precision floating point data type.

taichi.types.i16#

Alias for int16

taichi.types.i32#

Alias for int32

taichi.types.i64#

Alias for int64

taichi.types.i8#

Alias for int8

taichi.types.int16#

16-bit signed integer data type.

taichi.types.int32#

32-bit signed integer data type.

taichi.types.int64#

64-bit signed integer data type.

taichi.types.int8#

8-bit signed integer data type.

taichi.types.is_integral#
taichi.types.is_real#
taichi.types.is_signed#
taichi.types.is_tensor#
taichi.types.matrix(n=None, m=None, dtype=None)#

Creates a matrix type with given shape and data type.

Parameters:
  • n (int) – number of rows of the matrix.

  • m (int) – number of columns of the matrix.

  • dtype (primitive_types) – matrix data type.

Returns:

A matrix type.

Example:

>>> mat2x2 = ti.types.matrix(2, 2, ti.f32)  # 2x2 matrix type
>>> M = mat2x2([[1., 2.], [3., 4.]])  # an instance of this type
taichi.types.ndarray#

Alias for NdarrayType.

Example:

>>> @ti.kernel
>>> def to_numpy(x: ti.types.ndarray(), y: ti.types.ndarray()):
>>>     for i in range(n):
>>>         x[i] = y[i]
>>>
>>> y = ti.ndarray(ti.f64, shape=n)
>>> ... # calculate y
>>> x = numpy.zeros(n)
>>> to_numpy(x, y)  # `x` will be filled with `y`'s data.
taichi.types.ref(tp)#
taichi.types.rw_texture#

Alias for TextureType.

class taichi.types.sparse_matrix_builder#
taichi.types.struct(**kwargs)#

Creates a struct type with given members.

Parameters:

kwargs (dict) – a dictionary contains the names and types of the struct members.

Returns:

A struct type.

Example:

>>> vec3 = ti.types.vector(3, ti.f32)
>>> sphere = ti.types.struct(center=vec3, radius=float)
>>> s = sphere(center=vec3([0., 0., 0.]), radius=1.0)
taichi.types.template#

Alias for Template.

taichi.types.texture#
taichi.types.u1#

Alias for uint1

taichi.types.u16#

Alias for uint16

taichi.types.u32#

Alias for uint32

taichi.types.u64#

Alias for uint64

taichi.types.u8#

Alias for uint8

taichi.types.uint1#

1-bit unsigned integer data type. Same as booleans.

taichi.types.uint16#

16-bit unsigned integer data type.

taichi.types.uint32#

32-bit unsigned integer data type.

taichi.types.uint64#

64-bit unsigned integer data type.

taichi.types.uint8#

8-bit unsigned integer data type.

taichi.types.vector(n=None, dtype=None)#

Creates a vector type with given shape and data type.

Parameters:
  • n (int) – dimension of the vector.

  • dtype (primitive_types) – vector data type.

Returns:

A vector type.

Example:

>>> vec3 = ti.types.vector(3, ti.f32)  # 3d vector type
>>> v = vec3([1., 2., 3.])  # an instance of this type