-
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
Save element_dim parameter for taichi.types.ndarray. #7231
Comments
Or somehow make ti.template work with NDarrays (perhaps move element dim to templates as a type matching system, and if this can be compatible with fields this will be super extra helpful) because otherwise we would lose all the metaprogramming options with NDArrays. |
@lin-hitonami @k-ye for visibility |
I like this path. My nit on this is that instead of using I prefer not to add |
The use of template allow metaprogramming compatibility with fields. In terms of current CHI IR design this wouldn't work cleanly, but in terms of language design both NDarrays and Fields support indexed subscript interface and should be able to run the same templated code. |
Sure, |
Yes, I think we would need something along the lines of interface/traits |
Hey @bobcao3 @mushroomfire @k-ye @strongoier , @jim19930609 and I had a quick discussion offline after the triage meeting, and we agree this is a pretty valid use case - no matter it's external array or not ;D But the
|
Looks good. We can make all type annotations templates. |
+1 for the annotation syntax. I think it's a lot more clear to specify |
Dose ti.types.matrix() work with a 3-D array? if we only want to treat the last dim as a vector. @ailzhang, @k-ye. element_dim can handle it. Nf=100 # number of frames
N=1000 # number of particles
dim = 3 # dimension
trajec = np.random.random((Nf, N, dim)) BTW, I do think the element_dim is not clear, but if we want to drop out it, we should make sure the new parameters can entirely replace it with a more concise way. |
Hey @mushroomfire currently |
Hey @ailzhang, I like ti.types.tensor(), but again, what should I do for a 4-D array, use ndim=4? can we ignore the ndim. |
@mushroomfire yep you can ignore ndim, so sth like |
@ailzhang Yes, that is what I mean! |
@mushroomfire @ailzhang It seems that you are discussing |
…#7234) Part of taichi-dev#7218 Related (ndarray meta-programming): taichi-dev#7231 I would certainly like to share this code between the field vesion and NDArray version Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Concisely describe the proposed feature
I would like to suggest saving element_dim parameter in taichi.types.ndarray data structure.
Describe the solution you'd like (if any)
Considering one want to interact with a 2-D numpy array and treat each row as a vector, and sometimes the length of row is variable. element_dim is suitable in such case while ndim and dtype maybe not a good choice. For example:
Generate a numpy array to inteprete the position in 2-D and 3-D.
One can handle pos_2 and pos_3 with the following kernel:
If only use ndim and dtype parameters, the code maybe like this:
I have to transform numpy array to ti.ndarray first, and thus I think combination of ndim and dtype can not entirely replace the function of element_dim, which should be saved.
The text was updated successfully, but these errors were encountered: