Open kurt-rhee opened 1 year ago
@bobcao3 Thank you for the help!
I also want to note that just not type hinting the @ti.func function allows this program to run.
Same issue with: https://github.com/taichi-dev/taichi/issues/8042. It's actually a regression with ti.func
taking in Python-scope ti.Matrix/ti.Vector objects.
While I'm investigating the issue, a quick work-around is to put Python-scope variables point
and sun_vector
inside the kernel:
mport taichi as ti
from taichi.math import vec4
ti.init()
@ti.kernel
def project_system_kernel() -> vec4:
point = vec4([1, 0, 0, 0])
sun_vector = vec4([1, 1, 1, 1])
# --- Project each point onto the plane ---
new_point = project_point(point=point, sun_vector=sun_vector)
return new_point
@ti.func
def project_point(
point: vec4,
sun_vector: vec4
) -> vec4:
# --- Project point onto the normal vector ---
projection = ti.math.dot(point, sun_vector) / ti.math.length(sun_vector)
point_along_projection = sun_vector * projection
new_point = point - point_along_projection
return new_point
new_point = project_system_kernel()
print(new_point)
that should give you:
[Taichi] version 1.7.0, llvm 15.0.4, commit 41117f58, linux, python 3.10.6
[Taichi] Starting on arch=x64
[ 0.5 -0.5 -0.5 -0.5]
Describe the bug When specifying a vec4 in a function decorated with @ti.func, the function gives an error which states that a matrix is expected instead.
To Reproduce Please post a minimal sample code to reproduce the bug. The developer team will put a higher priority on bugs that can be reproduced within 20 lines of code. If you want a prompt reply, please keep the sample code short and representative.
Log/Screenshots Please post the full log of the program (instead of just a few lines around the error message, unless the log is > 1000 lines). This will help us diagnose what's happening. For example:
Additional comments If possible, please also consider attaching the output of command
ti diagnose
. This produces the detailed environment information and hopefully helps us diagnose faster.If you have local commits (e.g. compile fixes before you reproduce the bug), please make sure you first make a PR to fix the build errors and then report the bug.