Commit 77299df3 by xqdan Committed by Tianqi Chen

Support automatically Name Loop Variable in IRBuilder (#716) (#741)

* [SCHEDULE]enable partition const loop with build flag (#719)

    * enable partition loop with build flag

    * add a testcase, and modify LoopPartition related cases

*     * add document for split_const_loop

* [IRbuild]Support automatically Name Loop Variable in IRBuilder (#719)

    * add idx_num in class

* using typical index [i, j, k] first, then i_suffix

* keep inputs names

* fix lint

* improve comment of name

* fix lint
parent 6a0a8e98
......@@ -97,6 +97,7 @@ class IRBuilder(object):
"""
def __init__(self):
self._seq_stack = [[]]
self.nidx = 0
def _pop_seq(self):
"""Pop sequence from stack"""
......@@ -167,7 +168,8 @@ class IRBuilder(object):
The end iteration scope
name : str, optional
The name of iteration variable
The name of iteration variable, if no input names,
using typical index names i, j, k, then i_nidx
dtype : str, optional
The data type of iteration variable.
......@@ -189,6 +191,9 @@ class IRBuilder(object):
with ib.for_range(1, 10, name="i") as i:
x[i] = x[i - 1] + 1
"""
if name == 'i':
name = chr(ord(name) + self.nidx) if self.nidx < 3 else name + "_" + str(self.nidx - 3)
self.nidx += 1
self._seq_stack.append([])
loop_var = _api.var(name, dtype=dtype)
extent = end if begin == 0 else _pass.Simplify(end - begin)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment