Skip to content

Commit

Permalink
Feed batch_size to function instead of global
Browse files Browse the repository at this point in the history
  • Loading branch information
endolith committed Nov 2, 2023
1 parent 2ed24c8 commit ee10c4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions examples/niemi_1968_table_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
assert n_batches * batch_size == n_elections


def simulate_batch(n_voters, n_cands):
def simulate_batch(n_voters, n_cands, batch_size):
condorcet_paradox_count = Counter()
# Reuse the same chunk of memory to save time
election = np.empty((n_voters, n_cands), dtype=np.uint8)
Expand All @@ -79,7 +79,8 @@ def simulate_batch(n_voters, n_cands):

jobs = []
for n_cands in n_cands_list:
jobs.extend([delayed(simulate_batch)(n_voters, n_cands)] * n_batches)
jobs.extend(n_batches *
[delayed(simulate_batch)(n_voters, n_cands, batch_size)])

print(f'{len(jobs)} tasks total:')
results = Parallel(n_jobs=-3, verbose=5)(jobs)
Expand Down
5 changes: 3 additions & 2 deletions examples/niemi_1968_table_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
assert n_batches * batch_size == n_elections


def simulate_batch(n_voters, n_cands):
def simulate_batch(n_voters, n_cands, batch_size):
condorcet_paradox_count = Counter()
# Reuse the same chunk of memory to save time
election = np.empty((n_voters, n_cands), dtype=np.uint8)
Expand All @@ -56,7 +56,8 @@ def simulate_batch(n_voters, n_cands):
jobs = []
for n_voters in n_voters_list:
for n_cands in n_cands_list:
jobs.extend([delayed(simulate_batch)(n_voters, n_cands)] * n_batches)
jobs.extend(n_batches *
[delayed(simulate_batch)(n_voters, n_cands, batch_size)])

print(f'{len(jobs)} tasks total:')
results = Parallel(n_jobs=-3, verbose=5)(jobs)
Expand Down
5 changes: 3 additions & 2 deletions examples/wikipedia_condorcet_paradox_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
assert n_batches * batch_size == n_elections


def simulate_batch(n_voters, n_cands):
def simulate_batch(n_voters, n_cands, batch_size):
condorcet_paradox_count = Counter()
# Reuse the same chunk of memory to save time
election = np.empty((n_voters, n_cands), dtype=np.uint8)
Expand All @@ -63,7 +63,8 @@ def simulate_batch(n_voters, n_cands):

jobs = []
for n_voters in WP_table:
jobs.extend([delayed(simulate_batch)(n_voters, n_cands)] * n_batches)
jobs.extend(n_batches *
[delayed(simulate_batch)(n_voters, n_cands, batch_size)])

print(f'{len(jobs)} tasks total:')
results = Parallel(n_jobs=-3, verbose=5)(jobs)
Expand Down

0 comments on commit ee10c4f

Please sign in to comment.