Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions facto/inputgen/argument/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def hierarchy(argtype) -> List[Attribute]:
return [Attribute.VALUE]

def gen_structure_with_depth_and_length(
self, depth: int, length: int, focus: Attribute
self, args: tuple, depth: int, length: int, focus: Attribute
):
if length == 0:
yield ()
Expand All @@ -57,7 +57,7 @@ def gen_structure_with_depth_and_length(
attr = self._hierarchy[-(depth + 1)]

if attr in self.gen_list_mode:
yield from self.gen_structure_with_depth(depth, focus, length)
yield from self.gen_structure_with_depth(args, depth, focus, length)
return

focus_ixs = (
Expand All @@ -67,9 +67,13 @@ def gen_structure_with_depth_and_length(
values = [()]
for ix in range(length):
if ix == focus_ix:
elements = self.gen_structure_with_depth(depth, focus, length, ix)
elements = self.gen_structure_with_depth(
args, depth, focus, length, ix
)
else:
elements = self.gen_structure_with_depth(depth, None, length, ix)
elements = self.gen_structure_with_depth(
args, depth, None, length, ix
)
new_values = []
for elem in elements:
new_values += [t + (elem,) for t in values]
Expand All @@ -78,6 +82,7 @@ def gen_structure_with_depth_and_length(

def gen_structure_with_depth(
self,
args: tuple,
depth: int,
focus: Attribute,
length: Optional[int] = None,
Expand All @@ -86,14 +91,9 @@ def gen_structure_with_depth(
attr = self._hierarchy[-(depth + 1)]

if ix is not None:
args = (self.deps, length, ix)
args += (length, ix)
elif length is not None:
args = (
self.deps,
length,
)
else:
args = (self.deps,)
args += (length,)

values = AttributeEngine(attr, self.constraints, self.valid, self.argtype).gen(
focus, *args
Expand All @@ -103,11 +103,13 @@ def gen_structure_with_depth(
if depth == 0:
yield v
else:
yield from self.gen_structure_with_depth_and_length(depth - 1, v, focus)
yield from self.gen_structure_with_depth_and_length(
args, depth - 1, v, focus
)

def gen(self, focus: Attribute):
depth = len(self._hierarchy) - 1
yield from self.gen_structure_with_depth(depth, focus)
yield from self.gen_structure_with_depth((self.deps,), depth, focus)


class MetaArg:
Expand Down
21 changes: 21 additions & 0 deletions test/inputgen/test_meta_arg_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ def test_optional_int(self):
self.assertEqual(len(ms), 1)
self.assertEqual(str(ms[0]), "ArgType.IntOpt None")

def test_tensor_list(self):
constraints = [
cp.Length.Eq(lambda deps: 4),
cp.Rank.Eq(lambda deps, length, ix: 2 if ix < 2 else 1),
cp.Size.Eq(lambda deps, length, ix, r, d: 32 if d == 0 else None),
cp.Size.Eq(
lambda deps, length, ix, r, d: 8 if ix == 0 and d == 1 else None
),
cp.Size.Eq(
lambda deps, length, ix, r, d: 16 if ix == 1 and d == 1 else None
),
]
deps = []
outarg = False

engine = MetaArgEngine(outarg, ArgType.TensorList, constraints, deps, True)
ms = list(engine.gen(None))
self.assertEqual(len(ms), 1)
m = ms[0]
self.assertEqual(m.structure, ((32, 8), (32, 16), (32,), (32,)))


if __name__ == "__main__":
unittest.main()
Loading