from __future__ import annotations

import gc
import inspect
import os
import time
from pathlib import Path
from typing import Dict, List, Set

import dill as pickle
import pytest
from inference.core.workflows.execution_engine.v1.executor.execution_data_manager.dynamic_batches_manager import \
    DynamicBatchIndex
from inference.core.workflows.execution_engine.v1.executor.execution_data_manager.step_input_assembler import \
    intersect_masks_per_dimension


def codeflash_wrap(codeflash_wrapped, codeflash_test_module_name, codeflash_test_class_name, codeflash_test_name, codeflash_function_name, codeflash_line_id, codeflash_loop_index, *args, **kwargs):
    test_id = f'{codeflash_test_module_name}:{codeflash_test_class_name}:{codeflash_test_name}:{codeflash_line_id}:{codeflash_loop_index}'
    if not hasattr(codeflash_wrap, 'index'):
        codeflash_wrap.index = {}
    if test_id in codeflash_wrap.index:
        codeflash_wrap.index[test_id] += 1
    else:
        codeflash_wrap.index[test_id] = 0
    codeflash_test_index = codeflash_wrap.index[test_id]
    invocation_id = f'{codeflash_line_id}_{codeflash_test_index}'
    test_stdout_tag = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_loop_index}:{invocation_id}"
    print(f'!$######{test_stdout_tag}######$!')
    exception = None
    gc.disable()
    try:
        counter = time.perf_counter_ns()
        return_value = codeflash_wrapped(*args, **kwargs)
        codeflash_duration = time.perf_counter_ns() - counter
    except Exception as e:
        codeflash_duration = time.perf_counter_ns() - counter
        exception = e
    gc.enable()
    print(f'!######{test_stdout_tag}######!')
    iteration = os.environ['CODEFLASH_TEST_ITERATION']
    with Path('{codeflash_run_tmp_dir_client_side}', f'test_return_values_{iteration}.bin').open('ab') as f:
        pickled_values = pickle.dumps((args, kwargs, exception)) if exception else pickle.dumps((args, kwargs, return_value))
        _test_name = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_line_id}".encode('ascii')
        f.write(len(_test_name).to_bytes(4, byteorder='big'))
        f.write(_test_name)
        f.write(codeflash_duration.to_bytes(8, byteorder='big'))
        f.write(len(pickled_values).to_bytes(4, byteorder='big'))
        f.write(pickled_values)
        f.write(codeflash_loop_index.to_bytes(8, byteorder='big'))
        f.write(len(invocation_id).to_bytes(4, byteorder='big'))
        f.write(invocation_id.encode('ascii'))
    if exception:
        raise exception
    return return_value

def test_single_dimension_single_mask_single_index():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_single_dimension_single_mask_single_index', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_dimension_single_mask_multiple_indices():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,), (2,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_single_dimension_single_mask_multiple_indices', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_dimension_multiple_masks_with_intersection():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,), (2,)}, {(1,), (2,), (3,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_single_dimension_multiple_masks_with_intersection', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_dimension_multiple_masks_no_intersection():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,)}, {(2,), (3,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_single_dimension_multiple_masks_no_intersection', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_multiple_dimensions_consistent_indices():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2), (3, 4, 5)}, {(0,), (1, 2), (3, 4, 5)}]
    dimensions = {1, 2, 3}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_multiple_dimensions_consistent_indices', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_multiple_dimensions_partial_intersection():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2), (3, 4, 5)}, {(0,), (1, 2), (6, 7, 8)}]
    dimensions = {1, 2, 3}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_multiple_dimensions_partial_intersection', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_three_masks_with_intersection():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,)}, {(0,), (1,), (2,)}, {(0,), (1,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_three_masks_with_intersection', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_dimension_absent_from_some_masks():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2)}, {(3, 4, 5)}]
    dimensions = {1, 2, 3}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_dimension_absent_from_some_masks', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_sorted_dimensions_order():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(5, 6), (1,), (2, 3, 4)}]
    dimensions = {3, 1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_sorted_dimensions_order', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_empty_dimensions_set():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2)}]
    dimensions = set()
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_empty_dimensions_set', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_empty_batch_masks():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = []
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_empty_batch_masks', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_all_masks_empty_sets():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [set(), set(), set()]
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_all_masks_empty_sets', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_mask_empty_set():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [set()]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_single_mask_empty_set', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_high_dimensional_indices():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)}, {(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)}]
    dimensions = {10}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_high_dimensional_indices', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_mixed_dimension_sizes_in_single_mask():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2), (3, 4, 5), (6, 7, 8, 9)}]
    dimensions = {1, 2, 3, 4}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_mixed_dimension_sizes_in_single_mask', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_dimension_zero_not_in_tuples():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(), (1,)}, {(), (1,)}]
    dimensions = {0, 1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_dimension_zero_not_in_tuples', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_duplicate_indices_in_set():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,)}, {(0,), (1,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_duplicate_indices_in_set', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_dimensions():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{tuple([i]) for i in range(100)}]
    dimensions = set(range(1, 101))
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_large_number_of_dimensions', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for dim in range(2, 101):
        pass

def test_masks_with_no_indices_at_queried_dimension():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,)}, {(2,), (3,)}]
    dimensions = {2, 3}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_masks_with_no_indices_at_queried_dimension', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_element_dimension_set():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1,), (2,)}, {(1,), (2,), (3,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_single_element_dimension_set', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_negative_values_in_indices():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(-1,), (-2, -3)}, {(-1,), (-2, -3)}]
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_negative_values_in_indices', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_mixed_positive_negative_indices():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(1,), (-1, 2)}, {(1,), (-1, 2), (3, 4)}]
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_mixed_positive_negative_indices', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_masks():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(i,) for i in range(50)} for _ in range(100)]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_large_number_of_masks', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_indices_per_mask():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(i,) for i in range(500)}, {(i,) for i in range(250, 750)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_large_number_of_indices_per_mask', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_dimensionality():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{tuple(range(1, dim + 1)) for dim in range(1, 51)}, {tuple(range(1, dim + 1)) for dim in range(1, 51)}]
    dimensions = set(range(1, 51))
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_large_dimensionality', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for dim in range(1, 51):
        pass

def test_large_scale_multiple_masks_many_dimensions():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(i,) for i in range(100)}.union({(i, j) for i in range(50) for j in range(2)}) for _ in range(10)]
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_large_scale_multiple_masks_many_dimensions', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_partial_overlap_many_masks_large_scale():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(j,) for j in range(100)}.union({(j,) for j in range(i * 100, (i + 1) * 100)}) for i in range(50)]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_partial_overlap_many_masks_large_scale', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_no_overlap_many_masks():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(i * 100 + j,) for j in range(100)} for i in range(20)]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_no_overlap_many_masks', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_indices_values():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(1000000,), (2000000, 3000000)}, {(1000000,), (2000000, 3000000)}]
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_large_indices_values', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_complex_real_world_scenario():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2), (3, 4, 5), (6, 7, 8, 9)}, {(0,), (1, 2), (3, 4, 5), (6, 7, 8, 9)}, {(10,), (11, 12), (3, 4, 5), (6, 7, 8, 9)}]
    dimensions = {1, 2, 3, 4}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_complex_real_world_scenario', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_performance_with_1000_masks_1000_indices():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(i,) for i in range(1000)} for _ in range(1000)]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_performance_with_1000_masks_1000_indices', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_edge_case_return_type_is_dict():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,)}]
    dimensions = {1}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_edge_case_return_type_is_dict', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_edge_case_return_values_are_sets():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    batch_masks = [{(0,), (1, 2)}, {(0,), (1, 2)}]
    dimensions = {1, 2}
    _call__bound__arguments = inspect.signature(intersect_masks_per_dimension).bind(batch_masks, dimensions)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(intersect_masks_per_dimension, 'tests.inference.unit_tests.test_intersect_masks_per_dimension__unit_test_1', None, 'test_edge_case_return_values_are_sets', 'intersect_masks_per_dimension', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for value in result.values():
        pass