Skip to content

mechestim logo

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

๐Ÿง  I want to understand how it works

๐Ÿ— I want to understand the sandboxed architecture

๐Ÿงช I want to work on the repository

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

uv add git+https://github.com/AIcrowd/mechestim.git

Full Taxonomy