tkonolige commented on a change in pull request #6580:
URL: https://github.com/apache/incubator-tvm/pull/6580#discussion_r499745730
##########
File path: python/tvm/tir/ir_builder.py
##########
@@ -74,8 +75,23 @@ def asobject(self):
def dtype(self):
return self._content_type
+ def _linear_index(self, index):
+ if not isinstance(index, tuple):
+ return index
+ assert len(index) == len(self._shape), "Index size (%s) does not match
shape size (%s)" % (
+ len(index),
+ len(self._shape),
+ )
+ dim_size = 1
+ lidx = 0
+ for dim, idx in zip(reversed(self._shape), reversed(index)):
+ lidx += idx * dim_size
+ dim_size *= dim
+ return lidx
+
def __getitem__(self, index):
t = DataType(self._content_type)
+ index = self._linear_index(index)
Review comment:
This allows you to use multidimensional indices with IRBuilder. Manually
calculating the correct index into multidimensional arrays caused a couple of
bugs when I was developing this code. Using multidimensional indices made
everything cleaner and easier to debug.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]