
mechestim
NumPy-compatible math primitives with analytical FLOP counting.
mechestim is not a drop-in NumPy replacement
Operations have analytical FLOP costs and 32 operations are blocked.
A BudgetContext is optional โ a global default activates automatically โ but
using one explicitly gives you budget limits, namespacing, and summaries.
See Operation Categories.
Pick the path that matches what you need right now.
๐ I want to get started
๐ Something isn't working
๐ I want to write efficient code with mechestim
- Migrate from NumPy
- Use Einsum
- Exploit Symmetry
- Use Linear Algebra
- Plan Your Budget
- Debug Budget Overruns
๐ง I want to understand how it works
- FLOP Counting Model โ how costs are computed, why FLOPs
- Operation Categories โ free vs counted vs unsupported
๐ I want to understand the sandboxed architecture
- Client-Server Model โ why it exists, how it works
- Running with Docker โ local setup with Docker
๐งช I want to work on the repository
- Contributor Guide โ repo layout, test commands, generated docs
Quick example
Operations run freely without any setup โ the global default budget tracks FLOPs automatically:
import mechestim as me
# No BudgetContext needed โ the global default is active
scale = me.sqrt(me.array(2 / 256))
W = me.multiply(me.random.randn(256, 256), scale)
x = me.einsum('ij,j->i', W, me.random.randn(256))
print(me.budget_summary())
For budget limits and namespacing, use an explicit BudgetContext:
import mechestim as me
depth, width = 5, 256
with me.BudgetContext(flop_budget=10**8, namespace="mlp-forward") as budget:
# Weight init โ randn and multiply are both counted
scale = me.sqrt(me.array(2 / width))
weights = [me.multiply(me.random.randn(width, width), scale)
for _ in range(depth)]
# Forward pass
x = me.random.randn(width)
h = x
for i, W in enumerate(weights):
h = me.einsum('ij,j->i', W, h) # linear layer
if i < depth - 1:
h = me.maximum(h, 0) # ReLU
print(me.budget_summary())
mechestim FLOP Budget Summary
==============================
Namespace: mlp-forward
Total budget: 100,000,000
Used: 1,312,001 (1.3%)
Remaining: 98,687,999 (98.7%)
By operation:
einsum 655,360 ( 50.0%) [5 calls]
random.randn 327,936 ( 25.0%) [6 calls]
multiply 327,680 ( 25.0%) [5 calls]
maximum 1,024 ( 0.1%) [4 calls]
sqrt 1 ( 0.0%) [1 call]
Installation
Full Taxonomy
- Getting Started: Installation, Your First Budget
- How-To: Migrate from NumPy, Use Einsum, Exploit Symmetry, Use Linear Algebra, Use FFT, Plan Your Budget, Debug Budget Overruns
- Concepts: FLOP Counting Model, Operation Categories, NumPy Compatibility Testing
- Architecture: Client-Server Model, Running with Docker
- Development: Contributor Guide
- API Reference: Counted Ops, Free Ops, Symmetric Tensors, Linear Algebra, FFT, Random, Polynomial, Window Functions, Budget, FLOP Cost Query, Errors
- Reference: For AI Agents, Operation Audit, FLOP Cost Cheat Sheet
- Troubleshooting: Common Errors
- Changelog: Changelog