Counted Operations
Operations that consume the FLOP budget. Every call deducts its analytical cost from the active budget before execution.
Cost rules of thumb:
- Unary (exp, log, sqrt, ...): 1 FLOP per output element
- Binary (add, multiply, maximum, ...): 1 FLOP per output element (after broadcasting)
- Reductions (sum, mean, max, ...): 1 FLOP per input element
- Einsum:
product_of_all_index_dims x op_factor(op_factor=2 for inner products)
See FLOP Counting Model for full details.
API Reference
mechestim._einsum.einsum(subscripts, *operands, optimize='auto', symmetric_axes=None, **kwargs)
Evaluate Einstein summation with FLOP counting and optional path optimization.
Wraps numpy.einsum with analytical FLOP cost computation and
optional symmetry savings. If any input is a SymmetricTensor,
the cost is automatically reduced. If symmetric_axes is provided
and the output passes validation, a SymmetricTensor is returned.
All contractions go through opt_einsum's contract_path to find an
optimal pairwise decomposition. The FLOP cost uses opt_einsum's cost
model which includes op_factor (multiply-add = 2 FLOPs for inner
products).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscripts
|
str
|
Einstein summation subscript string (e.g., |
required |
*operands
|
ndarray
|
Input arrays. |
()
|
optimize
|
str, bool, or list of tuple
|
Contraction path strategy. Default
|
'auto'
|
symmetric_axes
|
list of tuple of int
|
Output dimension symmetry groups. Declares that the result
is symmetric in the given axes and wraps it as a
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray or SymmetricTensor
|
The result of the einsum. |
Raises:
| Type | Description |
|---|---|
BudgetExhaustedError
|
If the operation would exceed the FLOP budget. |
NoBudgetContextError
|
If called outside a |
SymmetryError
|
If |
Source code in src/mechestim/_einsum.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
mechestim._einsum.einsum_path(subscripts, *operands, optimize='auto')
Compute the optimal contraction path without executing.
Returns (path, PathInfo) with zero budget cost. The returned
path can be passed back to me.einsum(..., optimize=path)
to execute with that exact contraction order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscripts
|
str
|
Einstein summation subscript string. |
required |
*operands
|
ndarray
|
Input arrays. |
()
|
optimize
|
str, bool, or list of tuple
|
Path optimization strategy. Default |
'auto'
|
Returns:
| Name | Type | Description |
|---|---|---|
path |
list of tuple of int
|
The contraction path. Pass to |
info |
PathInfo
|
Diagnostics including per-step costs and symmetry savings. |
Source code in src/mechestim/_einsum.py
mechestim._pointwise
Counted pointwise operations and reductions for mechestim.
around(a, decimals=0, out=None)
Counted version of np.around. Cost = numel(output) FLOPs.
Source code in src/mechestim/_pointwise.py
clip(a, a_min=None, a_max=None, out=None, **kwargs)
Counted version of np.clip. Cost = numel(input) or unique_elements if symmetric.
Source code in src/mechestim/_pointwise.py
convolve(a, v, mode='full')
Counted version of np.convolve.
Source code in src/mechestim/_pointwise.py
corrcoef(x, y=None, **kwargs)
Counted version of np.corrcoef.
Source code in src/mechestim/_pointwise.py
correlate(a, v, mode='valid')
Counted version of np.correlate.
Source code in src/mechestim/_pointwise.py
cov(m, y=None, **kwargs)
Counted version of np.cov.
Source code in src/mechestim/_pointwise.py
cross(a, b, **kwargs)
Counted version of np.cross.
Source code in src/mechestim/_pointwise.py
diff(a, n=1, axis=-1, **kwargs)
Counted version of np.diff.
Source code in src/mechestim/_pointwise.py
dot(a, b)
Counted version of np.dot.
Source code in src/mechestim/_pointwise.py
ediff1d(ary, **kwargs)
Counted version of np.ediff1d.
Source code in src/mechestim/_pointwise.py
gradient(f, *varargs, **kwargs)
Counted version of np.gradient.
Source code in src/mechestim/_pointwise.py
inner(a, b)
Counted version of np.inner.
Source code in src/mechestim/_pointwise.py
interp(x, xp, fp, **kwargs)
Counted version of np.interp.
Source code in src/mechestim/_pointwise.py
isclose(a, b, **kwargs)
Counted version of np.isclose. Cost = numel(output) FLOPs.
Source code in src/mechestim/_pointwise.py
kron(a, b)
Counted version of np.kron.
Source code in src/mechestim/_pointwise.py
matmul(a, b)
Counted version of np.matmul.
Source code in src/mechestim/_pointwise.py
outer(a, b, out=None)
Counted version of np.outer.
Source code in src/mechestim/_pointwise.py
ptp(a, axis=None, **kwargs)
Peak-to-peak range. Cost = numel(input) FLOPs.
Source code in src/mechestim/_pointwise.py
round(a, decimals=0, out=None)
Counted version of np.round. Cost = numel(output) FLOPs.
Source code in src/mechestim/_pointwise.py
tensordot(a, b, axes=2)
Counted version of np.tensordot.
Source code in src/mechestim/_pointwise.py
trapezoid(y, x=None, dx=1.0, axis=-1)
Counted version of np.trapezoid.
Source code in src/mechestim/_pointwise.py
trapz(y, x=None, dx=1.0, axis=-1)
Counted version of np.trapz (deprecated alias for trapezoid).
Source code in src/mechestim/_pointwise.py
vdot(a, b)
Counted version of np.vdot.
Source code in src/mechestim/_pointwise.py
mechestim._polynomial
Counted polynomial operations for mechestim.
poly(seq_of_zeros)
Return polynomial coefficients from roots. Wraps numpy.poly.
Source code in src/mechestim/_polynomial.py
poly_cost(n)
polyadd(a1, a2)
Add two polynomials. Wraps numpy.polyadd.
Source code in src/mechestim/_polynomial.py
polyadd_cost(n1, n2)
polyder(p, m=1)
Differentiate a polynomial. Wraps numpy.polyder.
Source code in src/mechestim/_polynomial.py
polyder_cost(n)
polydiv(u, v)
Divide one polynomial by another. Wraps numpy.polydiv.
Source code in src/mechestim/_polynomial.py
polydiv_cost(n1, n2)
polyfit(x, y, deg, **kwargs)
Least-squares polynomial fit. Wraps numpy.polyfit.
Source code in src/mechestim/_polynomial.py
polyfit_cost(m, deg)
polyint(p, m=1, k=None)
Integrate a polynomial. Wraps numpy.polyint.
Source code in src/mechestim/_polynomial.py
polyint_cost(n)
polymul(a1, a2)
Multiply polynomials. Wraps numpy.polymul.
Source code in src/mechestim/_polynomial.py
polymul_cost(n1, n2)
polysub(a1, a2)
Subtract two polynomials. Wraps numpy.polysub.
Source code in src/mechestim/_polynomial.py
polysub_cost(n1, n2)
polyval(p, x)
Evaluate a polynomial at given points. Wraps numpy.polyval.
Source code in src/mechestim/_polynomial.py
polyval_cost(deg, m)
roots(p)
Return the roots of a polynomial with given coefficients. Wraps numpy.roots.
Source code in src/mechestim/_polynomial.py
mechestim._window
Window function wrappers with FLOP counting.
bartlett_cost(n)
FLOP cost of Bartlett window generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Window length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: n. |
Notes
One linear evaluation per sample.
Source code in src/mechestim/_window.py
blackman_cost(n)
FLOP cost of Blackman window generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Window length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 3n. |
Notes
Three cosine terms per sample.
Source code in src/mechestim/_window.py
hamming_cost(n)
FLOP cost of Hamming window generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Window length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 2n. |
Notes
One cosine evaluation plus one linear combination per sample.
Source code in src/mechestim/_window.py
hanning_cost(n)
FLOP cost of Hanning window generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Window length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 2n. |
Notes
One cosine evaluation plus one linear combination per sample.
Source code in src/mechestim/_window.py
kaiser_cost(n)
FLOP cost of Kaiser window generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Window length. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: 3n. |
Notes
Bessel function evaluation per sample.
Source code in src/mechestim/_window.py
mechestim._unwrap
Unwrap wrapper with FLOP counting.
unwrap_cost(shape)
FLOP cost of phase unwrapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple of int
|
Input array shape. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Estimated FLOP count: numel(input). |
Notes
Cost covers element-wise differencing and conditional adjustment.
Source code in src/mechestim/_unwrap.py
mechestim._sorting_ops
Counted wrappers for sorting, search, and set operations.
argpartition(a, kth, axis=-1, **kwargs)
Counted version of numpy.argpartition. Cost: n FLOPs per slice.
Source code in src/mechestim/_sorting_ops.py
argsort(a, axis=-1, **kwargs)
Counted version of numpy.argsort. Cost: n*ceil(log2(n)) FLOPs per slice.
Source code in src/mechestim/_sorting_ops.py
digitize(x, bins, **kwargs)
Counted version of numpy.digitize.
Cost: n * ceil(log2(len(bins))) where n = numel(x).
Source code in src/mechestim/_sorting_ops.py
in1d(ar1, ar2, **kwargs)
Counted version of numpy.in1d. Cost: (n+m)*ceil(log2(n+m)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
intersect1d(ar1, ar2, **kwargs)
Counted version of numpy.intersect1d. Cost: (n+m)*ceil(log2(n+m)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
isin(element, test_elements, **kwargs)
Counted version of numpy.isin. Cost: (n+m)*ceil(log2(n+m)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
lexsort(keys, axis=-1)
Counted version of numpy.lexsort.
Cost: k * sort_cost(n) where k = len(keys) and n = len(keys[0]).
Source code in src/mechestim/_sorting_ops.py
partition(a, kth, axis=-1, **kwargs)
Counted version of numpy.partition. Cost: n FLOPs per slice (quickselect).
Source code in src/mechestim/_sorting_ops.py
searchsorted(a, v, **kwargs)
Counted version of numpy.searchsorted.
Cost: m * ceil(log2(n)) where m = numel(v) and n = len(a).
Source code in src/mechestim/_sorting_ops.py
setdiff1d(ar1, ar2, **kwargs)
Counted version of numpy.setdiff1d. Cost: (n+m)*ceil(log2(n+m)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
setxor1d(ar1, ar2, **kwargs)
Counted version of numpy.setxor1d. Cost: (n+m)*ceil(log2(n+m)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
sort(a, axis=-1, **kwargs)
Counted version of numpy.sort. Cost: n*ceil(log2(n)) FLOPs per slice.
Source code in src/mechestim/_sorting_ops.py
union1d(ar1, ar2)
Counted version of numpy.union1d. Cost: (n+m)*ceil(log2(n+m)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
unique(ar, **kwargs)
Counted version of numpy.unique. Cost: n*ceil(log2(n)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
unique_all(x)
Counted version of numpy.unique_all. Cost: n*ceil(log2(n)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
unique_counts(x)
Counted version of numpy.unique_counts. Cost: n*ceil(log2(n)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
unique_inverse(x)
Counted version of numpy.unique_inverse. Cost: n*ceil(log2(n)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
unique_values(x)
Counted version of numpy.unique_values. Cost: n*ceil(log2(n)) FLOPs.
Source code in src/mechestim/_sorting_ops.py
mechestim._counting_ops
Counted wrappers for trace, histogram, and generation operations.
These are operations that look "free" but involve genuine computation. Each function charges a FLOP cost to the active budget.