Skip to content

Commit

Permalink
Refactor container_helpers.py to import numpy only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieHakim committed Apr 15, 2024
1 parent 7bf30c2 commit 97debe6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bnpm/container_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from collections.abc import MutableMapping
from typing import Dict, Any, Optional, Union, List, Tuple, Callable, Iterable, Iterator, Type

import numpy as np

"""
This module is intended to have minimal dependencies.
It is called by server.py which is intended to run
Expand Down Expand Up @@ -247,6 +245,8 @@ def find_differences_across_dictionaries(dicts):
List of dictionary items that are
different in at least one dictionary.
"""
import numpy as np

def get_binary_search_combos(n):
combos = list(np.arange(n))
if len(combos)%2 == 1:
Expand Down Expand Up @@ -567,6 +567,7 @@ def make_grid_search_dicts(search_space):
parameter values from the search space.\n
Example: [{'lr': 0.1, 'batch_size': 32}, {'lr': 0.1, 'batch_size': 64}, ...]
"""
import itertools
vals_comb = list(itertools.product(*search_space.values()))
ss_comb_dicts = [{k: val for k, val in zip(search_space.keys(), vals)} for vals in vals_comb]
return ss_comb_dicts

0 comments on commit 97debe6

Please sign in to comment.