High-performance numeric computation powered by BMB — math, statistics, random, vector ops
Project description
bmb-compute — Numeric Computation
Math, statistics, random numbers, and vector operations compiled from BMB.
Installation
pip install bmb-compute
Quick Start
import bmb_compute
# Math
bmb_compute.sqrt(144) # 12
bmb_compute.factorial(10) # 3628800
bmb_compute.ipow(2, 20) # 1048576
bmb_compute.clamp(15, 1, 10) # 10
# Statistics
bmb_compute.sum([10, 20, 30]) # 60
bmb_compute.mean_scaled([10, 20, 30]) # 20000 (= 20.000)
bmb_compute.min_val([5, 3, 8, 1]) # 1
bmb_compute.range_val([10, 50]) # 40
# Vector
bmb_compute.dot_product([1, 2, 3], [4, 5, 6]) # 32
bmb_compute.dist_squared([0, 0], [3, 4]) # 25
# Utility
bmb_compute.is_power_of_two(8) # True
bmb_compute.next_power_of_two(5) # 8
Full API (33 functions)
Math
| Function | Description |
|---|---|
abs(x) |
Absolute value |
min(a, b) / max(a, b) |
Minimum / maximum |
clamp(x, lo, hi) |
Clamp to range |
sign(x) |
Sign (-1, 0, 1) |
ipow(base, exp) |
Integer power |
sqrt(n) |
Integer square root |
factorial(n) |
Factorial (up to 20!) |
Statistics
| Function | Description |
|---|---|
sum(arr) |
Sum of elements |
mean_scaled(arr) |
Mean x 1000 |
min_val(arr) / max_val(arr) |
Min/max of array |
range_val(arr) |
Range (max - min) |
variance_scaled(arr) |
Variance x 1000000 |
median_scaled(arr) |
Median x 1000 (sorted input) |
cumsum(arr) |
Cumulative sum |
moving_avg_scaled(arr, k) |
Moving average x 1000 |
Random (XorShift64*)
| Function | Description |
|---|---|
rand_seed(seed) |
Initialize PRNG |
rand_next(state) |
Next state |
rand_pos(state) |
Positive random value |
rand_range(state, max) |
Random in [0, max) |
Vector
| Function | Description |
|---|---|
dot_product(a, b) |
Dot product |
dist_squared(a, b) |
Euclidean distance squared |
weighted_sum(values, weights) |
Weighted sum |
lerp_scaled(a, b, t) |
Linear interpolation (t: 0-1000) |
magnitude_squared(arr) |
Sum of squares |
vec_add(a, b) |
Element-wise addition |
vec_sub(a, b) |
Element-wise subtraction |
vec_scale(arr, scalar) |
Scalar multiplication |
map_square(arr) |
Square each element |
Utility
| Function | Description |
|---|---|
is_power_of_two(n) |
Power of two check |
next_power_of_two(n) |
Next power of two >= n |
How?
Written in BMB — compile-time contracts prove correctness, then generate code faster than hand-tuned C.
License
MIT
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 Distributions
Built Distributions
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 bmb_compute-0.2.0-py3-none-win_amd64.whl.
File metadata
- Download URL: bmb_compute-0.2.0-py3-none-win_amd64.whl
- Upload date:
- Size: 87.9 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
033428b330701fb306ddd0b60c18f66ab0c3d9648d2210e9baa84724be014172
|
|
| MD5 |
c2f922fd6635f52926a1d85bb14e4639
|
|
| BLAKE2b-256 |
aef5b45b6010749571222098af4b95a2b86eeac6cdbd3a4ab7ddf51e60ca6eff
|
File details
Details for the file bmb_compute-0.2.0-py3-none-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: bmb_compute-0.2.0-py3-none-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 68.4 kB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30137b2db16961e93cd3a23fcad03b3af37ab9722322a36a1a1fc1db11c4e013
|
|
| MD5 |
5caea73f1e4f2059ec59307ebef0333b
|
|
| BLAKE2b-256 |
706bcb32bd88486b375493157efe0b99d889bd63412540aff16171ebfa73b88f
|
File details
Details for the file bmb_compute-0.2.0-py3-none-macosx_15_0_universal2.whl.
File metadata
- Download URL: bmb_compute-0.2.0-py3-none-macosx_15_0_universal2.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3, macOS 15.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96d4575016210053f71a7ccfe7994624112b86e5efeca01145f0393ffe575edc
|
|
| MD5 |
f09b955a5c47a44c5958cd521f39e7fc
|
|
| BLAKE2b-256 |
920ef03cb7fdd7dfd4882376733d823785ebae78a64cce63b40a28d7ee6a6e20
|