Concisely describe the proposed feature
x = ti.Vector(2, ti.f32)
The user will get a confusing error since ti.f32 is applied to m which should only be used for matrices. They have to use:
x = ti.Vector(2, dt=ti.f32)
to make positional arguments happy.
So I would like to separate the usage of ti.Vector from ti.Matrix.
Describe the solution you'd like (if any)
Don't alias Vector = Matrix, let Vector be a child class of Matrix, or more stright-forwardly:
def Vector(n, *args, **kwargs):
return Matrix(n, 1, *args, **kwargs)
Additional comments
Also note that the confusing argument of v.to_numpy(as_vector=True) can be saved.
And this is one of the TBD in #833.
more stright-forwardly:
def Vector(n, *args, **kwargs): return Matrix(n, 1, *args, **kwargs)
This sounds better. Distinguishing vectors from matrices might lead to more irregularity as vectors are essentially matrices with only one column.
I prefer to make it a child class. So that the as_vector=True can be saved, and the vector-only arguments like cross can be saved.
As I know isinstance(x, A) works correctly for child classes of A.
One thing to consider: how about 1x1 matrices? Should we use a different class for 1x1 matrices, if vectors are a different class from matrices?
I actually prefer regularity and consistency over convenience here.
1x1
Either Vector and Matrix can hold 1x1 matrices.
regularity and consistency
https://github.com/taichi-dev/taichi/blob/6c02c401a60625f730aedd3c675974fc8efae1cd/python/taichi/lang/matrix.py#L486
https://github.com/taichi-dev/taichi/blob/6c02c401a60625f730aedd3c675974fc8efae1cd/python/taichi/lang/matrix.py#L367-L368
https://github.com/taichi-dev/taichi/blob/6c02c401a60625f730aedd3c675974fc8efae1cd/python/taichi/lang/matrix.py#L543-L548
Regularity and consistency? It's nice to know we didn't use Expr as 1x1 matrices for regularity and consistency.
IMO this is a perfect usage for derived-classes, what on earth does assert self.m == 1 improve regularity and consistency?
Again, I don't think as_vector is a good design for
regularity and consistency;WDYT guys? @k-ye @xumingkuan, welcome discussion!
Closed by #1046.