-
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
[Lang] [refactor] Deprecate "as_vector=True" in Matrix.to_numpy/to_torch #1046
Conversation
Hello? Please feel free to say |
I actually like your idea of having multiple initializers! Whether we should separate vectors from matrices still needs discussions. I personally prefer not to do it:
Generally speaking, for regularity, I prefer not to do the separation. |
They don't want to use Matrix as vector, since My worry is, will Another issue is, |
Good points.
Maybe we can solve this by moving
|
Not this point. My point is |
Also note that we will have to use print('u =', u, as_vector=True) for that? See? |
Thanks for the inputs. If you really hate
By changing the default
I really like your idea of having more constructors, but I still don't think So, does removing |
@FantasyVR please feel free to share your inputs given you are interested in this topic :-) |
Yes, we need more discussion on this, to determine this ultra-critical design by just you-and-me can be biased.
So we also print as |
I just come up with an perfect idea to keep both def Vector(n):
return Matrix(n, 1, is_vector=True)
...
def dot(u, v):
assert u.is_vector |
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.
Thank you so much! Most changes look great. Just two minor places to fix.
else: | ||
dim_ext = (self.n, self.m) | ||
as_vector = self.m == 1 and not keep_dims | ||
dim_ext = (self.n, ) if as_vector else (self.n, self.m) |
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.
Let's skip self.m
as well if it value is 1
. len(dim_ext)=
0
for1x1
matrices1
fornx1
or1xn
matrices (n != 1
)2
fornxm
matrices (n, m != 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.
Then I should change matrix_to_ext_arr to treat the useless 1x1
matrices?
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.
Yes, it seems that we need a keep_dims
parameter in matrix_to_ext_arr
as well.
Thanks!
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.
Special treating 1x1 mats sounds unreasonable to me..
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.
Few people would use 1x1 matrices anyway. Let's just make the behavior consistent: dimensionality of size 1
should be skipped.
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.
Wdym? Do we consider 1x1 mat as 1D vector?
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.
I mean, if the matrix is 1x1
, then the numpy array, when keep_dims=False
, should have the same shape as the matrix shape, instead of the matrix shape extended by (1, 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.
Thanks! Let's make keep_dims
behave as what most people would expect.
tests/python/test_mpm88.py
Outdated
@@ -61,7 +61,7 @@ def substep(): | |||
w = [ | |||
0.5 * (1.5 - fx)**2, 0.75 - (fx - 1.0)**2, 0.5 * (fx - 0.5)**2 | |||
] | |||
new_v = ti.Vector.zero(ti.f32, 2) | |||
new_v = ti.Matrix.zero(ti.f32, 2) |
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.
new_v = ti.Matrix.zero(ti.f32, 2) | |
new_v = ti.Vector.zero(ti.f32, 2) |
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.
> new_v = ti.Vector.zero(ti.f32, 2)
E AttributeError: 'function' object has no attribute 'zero'
Thanks to the fact that Vector is not a subclass of Matrix, but a initializer wrapper function.
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.
Now, I use Vector.zero = Matrix.zero
solved the problem for now before we finally come to ti.linalg.zero
.
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.
Sounds good. We should not use the subclass approach. Let's use add different initializers later.
Hello? We should mt asap, 2pvcw/ #1051, & mk GAMES201 happy. |
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.
I think we can merge this for now, given the changeset is getting large, but we should fully implement keep_dims
later. Thank you!
taichi/python/taichi/misc/image.py Line 7 in 6751bd5
@archibate This line raises an error now... |
Related issue = #940 #833 #1016
This PR also makes the stage 3 of #923 easier to implement.
[Click here for the format server]
I strongly argue about the ultra-massive-centralized-multiplexer in
ti.Matrix.__init__
:... said the Linux Kernel Coding Style, and I believe the 80x24 rule also works in python too.
Not to say lobal variables, just the arguments alone, there are 11.
Also note that the API initializing a
ti.Matrix
is highly centralized, GAMES201 students can easily get confused by error messages when they're not using the correct argument specification:Don't you think a better design could be:
to give
ti.Matrix.__init__
less duty just like currentlyti.Matrix.ones
andti.Matrix.zeros
does?Or at least we can make
ti.Matrix.__init__
serve as a router just redirecting to the actual functions liketi.Matrix.init_as_local
andti.Matrix.init_as_var
, instead of putting those implementations inside ofti.Matrix.__init__
if-else-if's?Note that we should always try our best to make a well-polished matrix/vector API before Taichi v1.0.0 comes.
I'm putting a lot of lines of text just to convey you trust my refactor decision, so please take a good look and
tl;dr
's are unwanted.