-
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] [test] Improve code coverage in SNode #1214
Conversation
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.
👍 for ⬆️ code coverage! I left my 2 cents.
Codecov Report
@@ Coverage Diff @@
## master #1214 +/- ##
==========================================
- Coverage 85.60% 85.31% -0.29%
==========================================
Files 18 18
Lines 3285 3297 +12
Branches 621 614 -7
==========================================
+ Hits 2812 2813 +1
- Misses 345 349 +4
- Partials 128 135 +7
Continue to review full report at Codecov.
|
python/taichi/lang/impl.py
Outdated
def try_materialize(self): | ||
if not self.layout_materialized: | ||
self.materialize_layout_callback() |
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.
@yuanming-hu What's the difference between directly self.materialize
which has a if not
guard too, isn't it? What's the point of Expr.layout_materialized
at the first place?
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.
Why not response me so long :(
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 believe he's extremely busy these days, especially last week, since he mentioned he had a paper deadline..
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.
Sorry about the delayed reply. @archibate could you clarify your question? I'm not sure if I get you correctly.
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.
Why you use a separate variable Expr.layout_materialized
instead of simple use the existing ti.get_runtime().materialized
? What the point of this design at first place?
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 see - good point. I don't remember why I did that TBH. Maybe we should try to remove Expr.layout_materilized
and use ti.get_runtime().materialized
instead, and see if anything goes wrong (of course, in a future PR).
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.
OK, I will. So far ti.get_runtime().layout_materialized
is good enough in this PR, right? Or you want to revert that now?
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.
My feeling as a reviewer is that this PR once again tries to do too much. Initially I thought we were just going to fix some Matrix helpers that were not covered by tests. But then I found out it also touched materialize_layout
and parent
. Note that materialize_layout
is a critical part of the system that requires careful reviews. Mixing it in will inevitably result in slow reviews...
I've left some comments, but I don't expect that will be enough to get this PR approved. I'd strongly suggest you not to touch the layout materialization part in this PR..
python/taichi/lang/impl.py
Outdated
def try_materialize(self): | ||
if not self.layout_materialized: | ||
self.materialize_layout_callback() |
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 believe he's extremely busy these days, especially last week, since he mentioned he had a paper deadline..
p = self.ptr | ||
for i in range(n): | ||
p = p.parent | ||
if p.type == impl.taichi_lang_core.SNodeType.root: |
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.
IIRC, the parent of root
is nullptr
, so I think we should return None
instead of making a cycle?
Co-authored-by: Ye Kuang <[email protected]>
python/taichi/lang/impl.py
Outdated
Expr.materialize_layout_callback = self.materialize | ||
self.materialize_layout_callback = self.materialize | ||
self.layout_materialized = False |
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.
IIUC, Expr.layout_materialized
is always equal to self.materialized
?
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.
Brain fried by noise, TTYL.
This reverts commit 00a05b2.
Hi, I moved the |
Hello? Do you think this PR needs further break down? IMHO it's ready for review now. |
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.
Sorry about my delayed review. I recently got too many things to do. This PR is actually pretty well-written. Thanks! Please address a few minor concerns.
docs/snode.rst
Outdated
|
||
Equivalent to ``len(tensor.shape())``. | ||
Equivalent to ``snode.shape()[i]``, used in Taichi-scope to prevent `[...]` being transformed to tensor access. |
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.
IIRC snode.shape
gives you a tuple and using []
on that doesn't get transformed to tensor access?
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.
Seems we treated specially in ti.subscript
? Cool!
Before preprocessing:
@ti.kernel
def func():
print(x.snode().shape()[1])
After preprocessing:
def func():
ti.ti_print(ti.subscript(x.snode().shape(), 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.
So can we deprecate get_shape(i)
and use shape()[i]
now according to the python exactly-one-way-to-do-one-thing rule?
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. Maybe we should directly use shape
as a @property
, so that users can simply do a.shape
instead of a.shape()
.
In this way, we can deprecate dim()
as well, since that's simply len(a.shape)
. (I think users tend to think dim
is the dimensionality of vectors/matrices instead of tensors.)
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.
Can't agree more, many users are confusing dim
with vector dimensions. Things we could do in another PR:
- deprecate
dim()
. - make
shape()
a@property
. - document
mat.n
,mat.m
inmeta.rst
.
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.
LGTM. Thanks!
Thank for approve, the 13 day PR finally draw it's end... |
* [lang] [test] Improve code coverage in Matrix and fix some methods * [skip ci] enforce code format * Improve tensor_reflection test * Better SNode with __repr__ * [skip ci] apply * [skip ci] Apply suggestions from code review Co-authored-by: Ye Kuang <[email protected]> * revert k-ye * Revert {Expr => PyTaichi}.materalized_layout_callback * Revert "[lang] [test] Improve code coverage in Matrix" This reverts commit 00a05b2. * [skip ci] Fix Matrix.snode() not found fix * [skip ci] loop_range().snode() * improve & deprecate duplicated functions * [skip ci] enforce code format Co-authored-by: Taichi Gardener <[email protected]> Co-authored-by: Ye Kuang <[email protected]>
Related issue = #... (if any)
Thanks to Codecov, I found some of the Matrix functions like
one
andvar
wasn't functional at all..Sleepy now, ff2mtoyo :)