Skip to content

Commit

Permalink
Remove numpy dependency (#947)
Browse files Browse the repository at this point in the history
* Refactor code for future `numpy` removal

* Remove `numpy` dependency

* Update dependencies
  • Loading branch information
arkid15r authored Nov 5, 2024
1 parent a5f5538 commit 5f6bc8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 71 deletions.
28 changes: 14 additions & 14 deletions nettacker/core/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import string
import sys
import time

import numpy
from itertools import product

from nettacker import logger

Expand Down Expand Up @@ -184,25 +183,26 @@ def generate_and_replace_md5(content):


def generate_target_groups(targets, set_hardware_usage):
"""
Split a list of targets into smaller sublists based on a specified size.
"""
if not targets:
return targets

targets_total = len(targets)
return [
targets.tolist()
for targets in numpy.array_split(
targets,
(set_hardware_usage if set_hardware_usage <= targets_total else targets_total),
)
]
split_size = min(set_hardware_usage, targets_total)

# Calculate the size of each chunk.
chunk_size = (targets_total + split_size - 1) // split_size

return [targets[i : i + chunk_size] for i in range(0, targets_total, chunk_size)]


def arrays_to_matrix(arrays):
return (
numpy.array(numpy.meshgrid(*[arrays[array_name] for array_name in arrays]))
.T.reshape(-1, len(arrays.keys()))
.tolist()
)
"""
Generate a Cartesian product of input arrays as a list of lists.
"""
return [list(item) for item in product(*[arrays[array_name] for array_name in arrays])]


def string_to_bytes(string):
Expand Down
58 changes: 2 additions & 56 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ flask = "^3.0.1"
ipaddr = "^2.2.0"
multiprocess = "^0.70.15"
netaddr = "^0.9.0"
numpy = ">=1.26.1,<3.0.0"
paramiko = "^3.4.0"
py3dns = "^4.0.0"
pyopenssl = "^23.2.0"
Expand Down

0 comments on commit 5f6bc8e

Please sign in to comment.