Skip to main content

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

Release files for bmb-compute 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for bmb-compute 0.2.0
File Interpreter ABI Platform
bmb_compute-0.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
bmb_compute-0.2.0-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
bmb_compute-0.2.0-py3-none-macosx_15_0_universal2.whl Python 3 none macOS 15.0+ universal2 (ARM64, x86-64) Details

Total release size: 204.7 kB

Release files / bmb_compute-0.2.0-py3-none-win_amd64.whl

Download URL bmb_compute-0.2.0-py3-none-win_amd64.whl
Size 87.9 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
033428b330701fb306ddd0b60c18f66ab0c3d9648d2210e9baa84724be014172
BLAKE2b-256 checksum
How to use checksums
aef5b45b6010749571222098af4b95a2b86eeac6cdbd3a4ab7ddf51e60ca6eff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / bmb_compute-0.2.0-py3-none-manylinux_2_17_x86_64.whl

Download URL bmb_compute-0.2.0-py3-none-manylinux_2_17_x86_64.whl
Size 68.4 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
30137b2db16961e93cd3a23fcad03b3af37ab9722322a36a1a1fc1db11c4e013
BLAKE2b-256 checksum
How to use checksums
706bcb32bd88486b375493157efe0b99d889bd63412540aff16171ebfa73b88f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / bmb_compute-0.2.0-py3-none-macosx_15_0_universal2.whl

Download URL bmb_compute-0.2.0-py3-none-macosx_15_0_universal2.whl
Size 48.4 kB
Tags Python 3 macOS 15.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
96d4575016210053f71a7ccfe7994624112b86e5efeca01145f0393ffe575edc
BLAKE2b-256 checksum
How to use checksums
920ef03cb7fdd7dfd4882376733d823785ebae78a64cce63b40a28d7ee6a6e20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.2.0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page