counted-float
This Python package provides functionality for...
- counting floating point operations (FLOPs) of numerical algorithms implemented in plain Python, optionally weighted by their relative cost of execution
- running benchmarks to estimate the relative cost of executing various floating-point operations (requires
numbaoptional dependency for achieving accurate results)
The target application area is evaluation of research prototypes of numerical algorithms where (weighted) flop counting can be useful for estimating total computational cost, in cases where benchmarking a compiled version (C, Rust, ...) is not feasible or desirable.
Flop weights are computed using a highly curated dataset spanning a wide range of modern CPUs:
- 19 benchmarks, 16 spec sheets, 12 third party measurements (Agner Fog, uops.info)
- covering x86 (Intel, AMD) and ARM (Apple, AWS, Azure) architectures
Full documentation: counted-float.readthedocs.io
Installation
Use your favorite package manager such as uv or pip:
pip install counted-float # install without optional dependencies
pip install counted-float[numba] # install with numba optional dependency
pip install counted-float[cli] # install with CLI support (click)
Numba is optional due to its relatively large size (40-50MB, including llvmlite), but without it, benchmarks will not be reliable (but will still run, but not in jit-compiled form).
Quick start
CountedFloat is a drop-in replacement for the built-in float; it is "contagious", so results of
math operations involving a CountedFloat stay CountedFloat:
from counted_float import CountedFloat
cf = CountedFloat(1.3)
f = 2.8
result = cf + f # result = CountedFloat(4.1)
is_float_1 = isinstance(cf, float) # True
is_float_2 = isinstance(result, float) # True
FLOPs performed by CountedFloat values are counted while a FlopCountingContext is active:
from counted_float import CountedFloat, FlopCountingContext
cf1 = CountedFloat(1.73)
cf2 = CountedFloat(2.94)
with FlopCountingContext() as ctx:
_ = cf1 * cf2
_ = cf1 + cf2
counts = ctx.flop_counts() # {FlopType.MUL: 1, FlopType.ADD: 1}
counts.total_count() # 2
Performance overhead
Using CountedFloat instead of plain float costs roughly 40–60× per
operation (environment-dependent) — the price of Python-level operator
dispatch and result wrapping. Measure your own machine with
counted_float benchmark-counted-float. Two facts worth knowing:
- the overhead is inherent and
PauseFlopCountingdoes not reduce it (the instrumented operators still execute; only count registration stops) — the escape hatch for hot uncounted regions is converting back viafloat(x); - overhead never affects count accuracy — counts are exact regardless.
This makes CountedFloat a tool for research and prototyping code, not
production hot loops.
Documentation
The documentation site covers the rest:
- Counting FLOPs — the counting model, counting contexts, pausing
- Math patching semantics — how (and when)
math.*functions are instrumented - FLOP weights — built-in consensus weights, configuring your own
- Benchmarking — estimating flop weights on your own hardware
- CLI reference — using
counted_floatas a stand-alone command-line tool - Known limitations — what falls outside the counting model
- Reference — per-FLOP-type counting rules, methodology, CPU scope
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 counted_float-1.5.0.tar.gz.
File metadata
- Download URL: counted_float-1.5.0.tar.gz
- Upload date:
- Size: 101.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03edb5b7a28d3978b05beaa8952e9ec0d08da1f5c1234ab470111c2d50304fbc
|
|
| MD5 |
6296e8df03f7488c0096a0272b757b61
|
|
| BLAKE2b-256 |
9706e367e28209e19663a21dccfee83a118bafb34ac53c0202799e8372703c7b
|
Provenance
The following attestation bundles were made for counted_float-1.5.0.tar.gz:
Publisher:
release_tag.yml on bertpl/counted-float
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
counted_float-1.5.0.tar.gz -
Subject digest:
03edb5b7a28d3978b05beaa8952e9ec0d08da1f5c1234ab470111c2d50304fbc - Sigstore transparency entry: 2167831502
- Sigstore integration time:
-
Permalink:
bertpl/counted-float@77954420ccb1b753d141a3017b1de84e26035a55 -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/bertpl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_tag.yml@77954420ccb1b753d141a3017b1de84e26035a55 -
Trigger Event:
push
-
Statement type:
File details
Details for the file counted_float-1.5.0-py3-none-any.whl.
File metadata
- Download URL: counted_float-1.5.0-py3-none-any.whl
- Upload date:
- Size: 147.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca55a3f75d97007314715d3dbb1701d1b94d7aac77f4c3d6e2c177b6e3ecf4f8
|
|
| MD5 |
cf1e48e2d407bb57971c9b1e04e2bf8b
|
|
| BLAKE2b-256 |
4bd4e42e795e7dedf3d839de6a03e9cd50b18b08e52e64c7afcd006376e8c0b2
|
Provenance
The following attestation bundles were made for counted_float-1.5.0-py3-none-any.whl:
Publisher:
release_tag.yml on bertpl/counted-float
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
counted_float-1.5.0-py3-none-any.whl -
Subject digest:
ca55a3f75d97007314715d3dbb1701d1b94d7aac77f4c3d6e2c177b6e3ecf4f8 - Sigstore transparency entry: 2167831521
- Sigstore integration time:
-
Permalink:
bertpl/counted-float@77954420ccb1b753d141a3017b1de84e26035a55 -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/bertpl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_tag.yml@77954420ccb1b753d141a3017b1de84e26035a55 -
Trigger Event:
push
-
Statement type: