-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] Update kernel_function #6794
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for docsite-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
for more information, see https://pre-commit.ci
Co-authored-by: Zhao Liang <[email protected]>
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
#### Matrix Fields | ||
We can use the ti.Matrix() function to declare our own [Matrix Field](https://docs.taichi-lang.org/docs/master/field#matrix-fields) and pass it into the kernel. This also works for [Vector Fields](https://docs.taichi-lang.org/docs/master/field#vector-fields) | ||
|
||
In the following example, we declare a Matrix Field, generate its values, and pass it into `myKernel()`: | ||
|
||
```python | ||
import taichi as ti | ||
ti.init() | ||
|
||
|
||
@ti.kernel | ||
def myKernel(a: ti.Matrix.field): | ||
for i in ti.grouped(a): | ||
a[i] = [[1,1,1], [1,1,1]] | ||
|
||
a = ti.Matrix.field(n=2, m=3, dtype=ti.f32, shape=(2, 2)) #Declares a 2x2 matrix field, with each of its elements being a 3x2 matrix | ||
myKernel(a) | ||
print(a[0][0,0]) #prints 1 | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### Matrix Fields | |
We can use the ti.Matrix() function to declare our own [Matrix Field](https://docs.taichi-lang.org/docs/master/field#matrix-fields) and pass it into the kernel. This also works for [Vector Fields](https://docs.taichi-lang.org/docs/master/field#vector-fields) | |
In the following example, we declare a Matrix Field, generate its values, and pass it into `myKernel()`: | |
```python | |
import taichi as ti | |
ti.init() | |
@ti.kernel | |
def myKernel(a: ti.Matrix.field): | |
for i in ti.grouped(a): | |
a[i] = [[1,1,1], [1,1,1]] | |
a = ti.Matrix.field(n=2, m=3, dtype=ti.f32, shape=(2, 2)) #Declares a 2x2 matrix field, with each of its elements being a 3x2 matrix | |
myKernel(a) | |
print(a[0][0,0]) #prints 1 | |
``` |
I'm sorry, Matrix.Field
is a function call, not a valid type hint. We should better not mention it here.
@@ -262,7 +342,7 @@ All Taichi functions are force-inlined. Therefore, no runtime recursion is allow | |||
|
|||
### Arguments | |||
|
|||
A Taichi function can have multiple arguments, supporting scalar, `ti.Matrix`, `ti.Vector`, `ti.types.ndarray()`, `ti.template()`, `ti.field`, and `ti.Struct` as argument types. Note that some of the restrictions on a kernel's arguments do not apply here: | |||
A Taichi function can have multiple arguments, supporting [Scalar](https://docs.taichi-lang.org/docs/master/field#scalar-fields), [ti.Matrix](https://docs.taichi-lang.org/docs/master/field#matrix-fields), [ti.Vector](https://docs.taichi-lang.org/docs/master/field#vector-fields), `ti.types.ndarray()`, `ti.template()`, and [ti.Struct](https://docs.taichi-lang.org/docs/master/field#struct-fields) as argument types. Note that some of the restrictions on a kernel's arguments do not apply here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Taichi function can have multiple arguments, supporting [Scalar](https://docs.taichi-lang.org/docs/master/field#scalar-fields), [ti.Matrix](https://docs.taichi-lang.org/docs/master/field#matrix-fields), [ti.Vector](https://docs.taichi-lang.org/docs/master/field#vector-fields), `ti.types.ndarray()`, `ti.template()`, and [ti.Struct](https://docs.taichi-lang.org/docs/master/field#struct-fields) as argument types. Note that some of the restrictions on a kernel's arguments do not apply here: | |
A Taichi function can have multiple arguments, supporting [Scalar](https://docs.taichi-lang.org/docs/master/field#scalar-fields), [ti.Matrix](https://docs.taichi-lang.org/docs/master/field#matrix-fields), [ti.Vector](https://docs.taichi-lang.org/docs/master/field#vector-fields), `ti.types.ndarray()`, `ti.template()`, and [ti.Struct](https://docs.taichi-lang.org/docs/master/field#struct-fields) as argument types. Note that some of the restrictions on a kernel's arguments do not apply here: |
I'm afraid that Vector and Matrix are not Vector/Matrix fields; the ref links are not leading to the exact places. Can we remove them for now?
Co-authored-by: Zhao Liang <[email protected]>
Co-authored-by: Zhao Liang <[email protected]>
Co-authored-by: Zhao Liang <[email protected]>
Co-authored-by: Zhao Liang <[email protected]>
Cleaned up wording and Format, added some extra informative code examples the user can interact with to get a better feeling for the concepts, added extra links to core concepts in previous Taichi documentation.