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
[Lang] Python-scope matrix/vector operations #1008
Comments
FWIW, when I created #1006 , I didn't intend to do the computation via
I do agree with this. The current code looks messy for doing this conversion: taichi/examples/cornell_box.py Lines 65 to 67 in a1b397a
|
If we still want to do this after the discussion above, I'd like to take a look |
I agree with this to some extend and I hate reinventing the wheels. However, a couple of users did complain about something like why can't we just do Taichi matrix inversion in Python scope? I feel like supporting these in native Taichi (instead of conversion to Therefore I think it still makes sense to support Taichi matrix operations in Python scope, but we should start small: @rexwangcc if you are interested in this, how about just implementing matrix |
Thanks! This sounds great to me, I personally also feel convenient to be able to do matrix operations in Python scope, and starting with |
Hi! I have some questions as I start to look into this. It seems the instantiation of m1 = ti.Matrix(np.eye(n) * 2)
print(m1.to_numpy())
# File "taichi/python/taichi/lang/matrix.py", line 534, in to_numpy
# ret = np.empty(self.loop_range().shape() + dim_ext,
# TypeError: 'tuple' object is not callable
m1 = ti.Matrix([[1, 2], [3, 4]])
print(m1.to_numpy())
# File "/home/rex/Code/GithubProjects/taichi-dev/taichi/python/taichi/lang/matrix.py", line 534, in to_numpy
# ret = np.empty(self.loop_range().shape() + dim_ext,
# AttributeError: 'int' object has no attribute 'shape'
m1 = ti.Matrix(n, n, ti.f32, shape=(1, 1))
print(m1.to_numpy())
# worked as expected It seems the underlying |
My feeling is that |
Thanks, that makes sense to me. I guess at this point I may either implement that in order to use it for Actually let me go back and read the doc about external array again... |
Concisely describe the proposed feature
Currently, the
Matrix
class operations (e.g. matrix add/multiply/scale) can happen only in Taichi kernels. In some cases having these work in Python-scope is necessary. For example,https://github.com/taichi-dev/taichi/pull/1006/files#diff-9ce279666131a93e7f2be366688b2fa1R52-R67
Without Python-scope matrix operation supports users have to fall back on numpy and the conversion between Taichi and numpy can be troublesome.
Describe the solution you'd like (if any)
Dispatch matrix operations according to the scope. Keep the old behavior if the operation happens in Taichi-scope, but evaluate the results immediately in Python-scope.
To decide the scope, use
ti.get_runtime().inside_kernel
. E.g.,taichi/python/taichi/lang/expr.py
Line 143 in 6dce0c4
The text was updated successfully, but these errors were encountered: