Skip to main content

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.TraceResult object is not serializable out of the box

Project details


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.0.19.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mmar_utils-1.0.19-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file mmar_utils-1.0.19.tar.gz.

File metadata

  • Download URL: mmar_utils-1.0.19.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.31

File hashes

Hashes for mmar_utils-1.0.19.tar.gz
Algorithm Hash digest
SHA256 14e090e5ce9c966b5daca6bf5b9c88d43159e560431063383c9565f5a1c2440a
MD5 9f48e382f9bcd27fcf682b53c369c80f
BLAKE2b-256 d2c4abfa097cadb4a1706bdd08319e1f5ba7764c57c7bbccc91ca3f422e5695b

See more details on using hashes here.

File details

Details for the file mmar_utils-1.0.19-py3-none-any.whl.

File metadata

File hashes

Hashes for mmar_utils-1.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 5cca4f2067365ea4f84ceb26d9111626fe816fac8ffa0ccb30c6d4020ddcda0c
MD5 0075e99deb6e532854a9e624f413af23
BLAKE2b-256 a424231633ba4560f75cd42e484efe6c8f982c6d6f6e22f1e769f88ec4a475cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page