vec4d = ti.types.vector(4, ti.f64) # a 64-bit floating-point 4D vector type
# vec4d = ti.math.vec4 # a 64-bit floating-point 4D vector type
mat4x3i = ti.types.matrix(4, 3, int) # a 4x3 integer matrix type
"""You can use these customized types to instantiate vectors and matrices"""
v = vec4d(1,2,3,4) # Create a vector instance, here v = [1.0 2.0 3.0 4.0]
@ti.func
def length(w): # vec4d as type hint
return w.norm()
@ti.kernel
def test(w: vec4d): # type must be hinted
print(length(w))
test(v)
(今天开始看documentation, 不太理解为什么同样是vector of 4 floating-point, 把ti.types.vector(4, ti.f32) 改成ti.math.vec4 就会报错:
“Matrix dtype f64 is not integer type or real type.”)
import taichi as ti
ti.init()
vec4d = ti.math.vec4 # a 64-bit floating-point 4D vector type
v = vec4d(1,2,3,4) # Create a vector instance, here v = [1.0 2.0 3.0 4.0]
@ti.func
def length(w): # vec4d as type hint
return w.norm()
@ti.kernel
def test(w: vec4d): # type must be hinted
print(length(w))
test(v)