Skip to main content

Count floating-point operations in Python code & benchmark relative flop costs.

Project description

CI Coverage Tests Docs PyPI Python License code style: ruff OpenSSF Scorecard

counted_float logo

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 numba optional 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 numba optional dependency
pip install counted-float[numba]    # install with numba optional dependency

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

Documentation

The documentation site covers the rest:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

counted_float-1.2.1.tar.gz (96.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

counted_float-1.2.1-py3-none-any.whl (107.4 kB view details)

Uploaded Python 3

File details

Details for the file counted_float-1.2.1.tar.gz.

File metadata

  • Download URL: counted_float-1.2.1.tar.gz
  • Upload date:
  • Size: 96.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for counted_float-1.2.1.tar.gz
Algorithm Hash digest
SHA256 881000cb2615adb26cda3cb744f55649c0595d070e7177843e518c8d3e4e431f
MD5 6eddcab9c1bf1fa1ea2334d01866a9df
BLAKE2b-256 be779a0314ef34e9968d8a414e60be6795e269d0413109d0f9737110440d973d

See more details on using hashes here.

Provenance

The following attestation bundles were made for counted_float-1.2.1.tar.gz:

Publisher: release_tag.yml on bertpl/counted-float

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file counted_float-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: counted_float-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 107.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for counted_float-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d1eb94953a23beb6179e21b91a6b951a10e56b12a7851b06e5b40ef95c0ce77
MD5 9c3029b21e8c15fc6cbb313b378e5487
BLAKE2b-256 8f7703bf8283b0d6f1e5b4f2c14735bfd9c41e7c8c693ecb0f126af70291a8a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for counted_float-1.2.1-py3-none-any.whl:

Publisher: release_tag.yml on bertpl/counted-float

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page