Skip to content

Commit

Permalink
Fix for old greedy algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Jan 16, 2025
1 parent 5938614 commit b4626ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/greedy/greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ def compute_one_with_stack(self, o: Union[var_T, id_T], stack: List[var_T], need
pos = stack.index(o)

# o is only needed once more
if o in needed_stack and needed_stack[o] == 1:
# AH: and there is a copy that can be used to swap
if o in needed_stack and needed_stack[o] == 1 and (pos >= self._dup_stack_ini
or o in stack[self._dup_stack_ini:]):

# Ignore the one that has just been computed
if pos < self._dup_stack_ini:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_greedy_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@
class TestGreedyOld:

def test_array_allocation(self):
_, _, error = greedy_from_file("greedy_old/array_allocation_size_t_bytes_memory_ptr_Block2_split_0.json")
"""
If the stack already contains all the copies needed and is a subterm of current computation, it tries
to reuse it using a swap instruction. However, if one of the copies is already part of a computation,
it tries to access one copy that is not part of it. In this case, there are no other copies and it fails
when trying to retrieve the position (ask Albert)
FIX: adding condition "pos >= self._dup_stack_ini or o in stack[self._dup_stack_ini:])" to ensure
we only try to swap it there is an available element
"""
_, _, error = greedy_from_file("greedy_old/swap_only_if_available.json")
assert error != "error", "Falla test"

0 comments on commit b4626ce

Please sign in to comment.