Skip to content

Commit

Permalink
updated function'
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Apr 25, 2024
1 parent adad87a commit 5e3c8cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions tests/test_vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def test_sample_n_evenly_spaced_side_cases():


def test_sample_n_evenly_spaced_even_cases():
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 2) == [1, 4]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 3) == [1, 3, 5]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 4) == [1, 2, 3, 4]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 5) == [1, 2, 3, 4, 5]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 2) == [1, 6]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 3) == [1, 3, 6]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 4) == [1, 3, 4, 6]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 5) == [1, 2, 3, 5, 6]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6], 6) == [1, 2, 3, 4, 5, 6]


def test_sample_n_evenly_spaced_odd_cases():
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 2) == [1, 5]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 2) == [1, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 3) == [1, 4, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 4) == [1, 3, 5, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 5) == [1, 2, 3, 5, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 6) == [1, 2, 3, 4, 5, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 5) == [1, 3, 4, 5, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 6) == [1, 2, 3, 5, 6, 7]
assert sample_n_evenly_spaced([1, 2, 3, 4, 5, 6, 7], 7) == [1, 2, 3, 4, 5, 6, 7]
14 changes: 8 additions & 6 deletions vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,16 @@ def _handle_viz_tools(
def sample_n_evenly_spaced(lst: Sequence, n: int) -> Sequence:
if n <= 0:
return []

if len(lst) <= n:
elif len(lst) == 0:
return []
elif n == 1:
return [lst[0]]
elif n >= len(lst):
return lst

interval = len(lst) // n if len(lst) % 2 == 0 else len(lst) // n + 1
indices = list(range(len(lst)))
picked_indices = sorted([indices[(i * interval) % len(lst)] for i in range(n)])
return [lst[i] for i in picked_indices]
spacing = (len(lst) - 1) / (n - 1)
return [lst[round(spacing * i)] for i in range(n)]



def visualize_result(all_tool_results: List[Dict]) -> Sequence[Union[str, Path]]:
Expand Down

0 comments on commit 5e3c8cd

Please sign in to comment.