Skip to content

Commit

Permalink
More introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
Li-Xiang-Ideal committed Dec 14, 2023
1 parent 353d400 commit 45afd10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mathics/eval/tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def construct_outer(lists, current, const_etc: tuple) -> Union[list, BaseElement
Parameters:
``item``: the current item to be unpacked (if not at lowest level), or joined
to current (if at lowest level)
``item``: the current item to be unpacked (if not at lowest level),
or joined to current (if at lowest level)
``rest_lists``: the rest of lists to be unpacked
Expand All @@ -124,6 +124,10 @@ def construct_outer(lists, current, const_etc: tuple) -> Union[list, BaseElement
evaluation, # evaluation: Evaluation
)
```
For those unfamiliar with ``construct_outer``, ``ConstructOuterTest``
in ``test/eval/test_tensors.py`` provides a detailed introduction and
several good examples.
"""
(
cond_next_list, # return True when the next list should be unpacked
Expand All @@ -146,7 +150,7 @@ def _unpack_outer(
if rest_lists:
return _unpack_outer(
rest_lists[0], rest_lists[1:], join_elem(current, item), 1
)
) # unpacking of a list always start from level 1
else:
return _apply_f(join_elem(current, item))
else: # unpack this list at next level
Expand Down
1 change: 1 addition & 0 deletions test/eval/test_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def testCartesianProduct(self):
evaluation,
)

# Here initial current is empty, but in some cases we expect non-empty ones like ((), Integer1)
assert construct_outer([list1, list2, list3], [], etc_1) == expected_result_1
assert construct_outer([list1, list2, list3], (), etc_2) == expected_result_1

Expand Down

0 comments on commit 45afd10

Please sign in to comment.