Skip to main content

A library for elementwise multithreaded algebra and multithreaded random number generation.

Project description

mtalg — Multithreaded Algebra

version PyPI Latest Release build_test Quality Gate Status Coverage License Downloads

About

mtalg is a package for multithreaded algebra and random number generation.

While numpy does support out of the box multithreaded linear algebra (numpy.linalg) for operations such as matrix multiplication, decomposition, spectral analysis, and related functions, which are building on libraries such as BLAS and LAPACK, the same does not hold true for simpler algebraic element-wise operations. Similarly can be said for the generation of random variates.

mtalg is the fastest library known to us for large scale element-wise algebraic operations and non-GPU-based random number generation. For more info on benchmarks you can see the dedicated section below.

Major benefits become apparent past 10^7 operations for both the element-wise algebra and the random number generator modules.

Installation

pip install mtalg

How to use

Import mtalg and random number generator

import mtalg
from mtalg.random import MultithreadedRNG

Create an instance of the multithreaded random number generator with seed for reproducability and number of threads to be used

mrng = MultithreadedRNG(seed=1, num_threads=4)

Create two arrays

a = mrng.standard_normal(size=(10_000, 5_000))
b = mrng.uniform(size=(10_000, 5_000), low=0, high=10)

Set number of threads to be used by default for algebra functions and subsquent random number generators (if num_threads parameter is not specified)

mtalg.set_num_threads(4)

Add b to a (a is modified in-place)

mtalg.add(a, b)

Subtract a from b (b is modified in-place)

mtalg.sub(a, b, direction='right')

Multiply, divide and raise to power (a is modified in-place)

mtalg.mul(a, b)
mtalg.div(a, b)
mtalg.pow(a, b)

Benchmarks *

Elementwise algebra

Random number generation

* Benchmarks are carrried out using an Intel(R) Xeon(R) Gold 6142M CPU @ 2.60GHz and 24 threads

Acknowledgments

The module for multithreaded generation of random numbers is inspired from here.

Authors

Wouter Wakker and Luca Mingarelli, 2021

Python

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

mtalg-1.0.0.tar.gz (14.0 kB view hashes)

Uploaded Source

Built Distribution

mtalg-1.0.0-py3-none-any.whl (19.8 kB view hashes)

Uploaded Python 3

Supported by

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