Utilities for multi-modal architectures team
Project description
mmar-utils
Common pure/IO utilities for multi-modal architectures team.
Installation
pip install mmar-utils
parallel_map
Mix of joblib.Parallel and tqdm.
Similar libraries
joblib.Parallel: https://joblib.readthedocs.io/en/latest/parallel.html
- doesn't support showing progress out of the box
Syntax comparison ( assuming tqdm disabled )
from math import sqrt, pow
from joblib import Parallel as P, delayed as d
from agi_med_utils import parallel_map
# ONE-ARG: THREADING
print(P(n_jobs=2)(map(d(sqrt), range(5))))
print(P(n_jobs=2)(d(sqrt)(i) for i in range(5)))
print(parallel_map(sqrt, range(5)))
# > [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
# ONE-ARG: MULTIPROCESSING
print(P(n_jobs=2, backend='multiprocessing')(d(sqrt)(i) for i in range(3)))
print(parallel_map(sqrt, range(3), process=True))
# > [0.0, 1.0, 1.4142135623730951]
# MANY-ARGS: THREADING
pow_args = [(i, j) for i in range(1, 4) for j in range(1, 3)]
print(P(n_jobs=2)(d(pow)(i, j) for i, j in pow_args))
print(parallel_map(pow, pow_args, multiple_args=True))
# > [1.0, 1.0, 2.0, 4.0, 3.0, 9.0]
# KWARGS: THREADING
def ipow_kw(*, x, y):
return 1 / pow(x, y)
ipow_kwargs = [{'x': i, 'y': j} for i, j in pow_args]
print(P(n_jobs=2)(d(ipow_kw)(**kw) for kw in ipow_kwargs))
print(parallel_map(ipow_kw, ipow_kwargs, kwargs_args=True))
# > [1.0, 1.0, 0.5, 0.25, 0.3333333333333333, 0.1111111111111111]
# KWARGS: MULTIPROCESSING
def ipow_kw_inc(*, x, y):
return 1 / pow(x, y) + 1
print(P(n_jobs=2, backend='multiprocessing')(d(ipow_kw_inc)(**kw) for kw in ipow_kwargs))
print(parallel_map(ipow_kw_inc, ipow_kwargs, kwargs_args=True, process=True))
# > [2.0, 2.0, 1.5, 1.25, 1.3333333333333333, 1.1111111111111112]
pqdm: https://pqdm.readthedocs.io/en/latest/usage.html
trace_with
Decorator for function which executes some callback on each function call.
Similar libraries
functrace: https://github.com/idanhazan/functrace
- does not remember start datetime of call, which is critical
- supports selection of parameters to remember
functrace.TraceResultobject is not serializable out of the box
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mmar_utils-1.1.12.tar.gz
(12.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mmar_utils-1.1.12.tar.gz.
File metadata
- Download URL: mmar_utils-1.1.12.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11f37c388f45e5ab4f4934b462c0e776e9ef3fe3a99aca9a3990adbad45b64e5
|
|
| MD5 |
0d4d40eb9790b9f1bd9938ad40ff67a2
|
|
| BLAKE2b-256 |
3032f12904ee5a43a0c55c7d3ef48b937da7591204ccd7081be4a788fe79a5df
|
File details
Details for the file mmar_utils-1.1.12-py3-none-any.whl.
File metadata
- Download URL: mmar_utils-1.1.12-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c47afe93c52631625b522f8b4c21a1321153885cf3b5dc6f312c7299343cd4aa
|
|
| MD5 |
a0c8712a202655dd56488bec8e7269dd
|
|
| BLAKE2b-256 |
a73cc7d2b7cbb42ae621ea674b5b292c1b489ea3aa7a007735e10fb85faf15b2
|