counted-float 0.9.7__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. {counted_float-0.9.7 → counted_float-1.0.0}/PKG-INFO +34 -6
  2. {counted_float-0.9.7 → counted_float-1.0.0}/README.md +33 -5
  3. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/_cli.py +7 -1
  4. counted_float-1.0.0/counted_float/_core/benchmarking/__init__.py +37 -0
  5. counted_float-1.0.0/counted_float/_core/benchmarking/counted_float/__init__.py +1 -0
  6. counted_float-1.0.0/counted_float/_core/benchmarking/counted_float/_counted_float_benchmark.py +83 -0
  7. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/benchmarking/micro/_micro_benchmark.py +2 -2
  8. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_missing_data.py +1 -5
  9. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/benchmarking/__init__.py +2 -1
  10. {counted_float-0.9.7 → counted_float-1.0.0}/pyproject.toml +1 -1
  11. counted_float-0.9.7/counted_float/_core/benchmarking/__init__.py +0 -11
  12. {counted_float-0.9.7 → counted_float-1.0.0}/.gitignore +0 -0
  13. {counted_float-0.9.7 → counted_float-1.0.0}/LICENSE +0 -0
  14. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/__init__.py +0 -0
  15. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/__init__.py +0 -0
  16. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/__init__.py +0 -0
  17. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/_array_generator.py +0 -0
  18. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/_flops_benchmark_suite.py +0 -0
  19. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/_flops_micro_benchmark.py +0 -0
  20. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/benchmarking/micro/__init__.py +0 -0
  21. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/compatibility/__init__.py +0 -0
  22. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/compatibility/_numba.py +0 -0
  23. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/__init__.py +0 -0
  24. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/_builtin_data.py +0 -0
  25. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/_context_managers.py +0 -0
  26. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/_counted_float.py +0 -0
  27. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/_global_counter.py +0 -0
  28. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/config/__init__.py +0 -0
  29. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/config/_config.py +0 -0
  30. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/counting/config/_defaults.py +0 -0
  31. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/__init__.py +0 -0
  32. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_base.py +0 -0
  33. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_flop_counts.py +0 -0
  34. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_flop_type.py +0 -0
  35. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_flop_weights.py +0 -0
  36. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_flops_benchmark_meta_data.py +0 -0
  37. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_flops_benchmark_result.py +0 -0
  38. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_flops_benchmark_type.py +0 -0
  39. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_instruction_latencies.py +0 -0
  40. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/models/_micro_benchmark_result.py +0 -0
  41. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/__init__.py +0 -0
  42. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_cpu_freq.py +0 -0
  43. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_formatting.py +0 -0
  44. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_geo_mean.py +0 -0
  45. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_latency.py +0 -0
  46. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_rounding.py +0 -0
  47. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/_core/utils/_timer.py +0 -0
  48. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/config/__init__.py +0 -0
  49. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/apple_m3_max_mbp16.json +0 -0
  50. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/apple_m3_mba15.json +0 -0
  51. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/ec2_m6g_xlarge_graviton_2_neoverse_n1.json +0 -0
  52. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/ec2_m7g_xlarge_graviton_3_neoverse_v1.json +0 -0
  53. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/gh_apple_m1.json +0 -0
  54. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v8_cortex_a76.json +0 -0
  55. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v9_cortex_x1.json +0 -0
  56. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v9_neoverse_n1.json +0 -0
  57. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v9_neoverse_v1.json +0 -0
  58. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_0/benchmarks/ec2_m8g_xlarge_graviton_4_neoverse_v2.json +0 -0
  59. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_0/benchmarks/gh_azure_cobalt_100_neoverse_n2.json +0 -0
  60. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_cortex_x2.json +0 -0
  61. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_cortex_x3.json +0 -0
  62. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_neoverse_n2.json +0 -0
  63. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_neoverse_v2.json +0 -0
  64. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_2/benchmarks/apple_m4_pro_mbp16.json +0 -0
  65. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_2/specs/arm_v9_cortex_x4.json +0 -0
  66. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_2/specs/arm_v9_cortex_x925.json +0 -0
  67. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/arm/v9_2/specs/arm_v9_neoverse_v3.json +0 -0
  68. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2017_zen1/analysis_uops_info_zen1+.json +0 -0
  69. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2017_zen1/benchmark_ryzen_1700x.json +0 -0
  70. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/analysis_agner_fog_r7_5800x.json +0 -0
  71. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/analysis_uops_info_zen3.json +0 -0
  72. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/benchmark_gh_amd_epyc_7763_linux.json +0 -0
  73. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/benchmark_gh_amd_epyc_7763_windows.json +0 -0
  74. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/analysis_agner_fog_r9_7900x.json +0 -0
  75. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/analysis_uops_info_zen4.json +0 -0
  76. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/benchmark_ec2_m7a_xlarge_zen4.json +0 -0
  77. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/specs_amd.json +0 -0
  78. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2024_zen5/analysis_agner_fog_r7_9800x3d.json +0 -0
  79. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2024_zen5/benchmark_ec2_m8a_xlarge_zen5.json +0 -0
  80. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/amd/2024_zen5/specs_amd.json +0 -0
  81. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/analysis_agner_fog_coffee_lake.json +0 -0
  82. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/analysis_uops_info_coffee_lake.json +0 -0
  83. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/benchmark_gh_intel_i7_8700B_macos.json +0 -0
  84. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/benchmark_intel_i7_8550U_windows.json +0 -0
  85. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_agner_fog_ice_lake.json +0 -0
  86. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_uops_info_ice_lake.json +0 -0
  87. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_uops_info_tiger_lake.json +0 -0
  88. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/benchmark_ec2_m6i_xlarge_ice_lake.json +0 -0
  89. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2021_golden_cove_gen_12/analysis_uops_info_alder_lake_p.json +0 -0
  90. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2021_golden_cove_gen_12/benchmark_ec2_m7i_xlarge_sapphire_rapids.json +0 -0
  91. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2021_golden_cove_gen_12/specs_intel.json +0 -0
  92. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2022_raptor_cove_gen_13_14/benchmark_ec2_i7i_xlarge_emerald_rapids.json +0 -0
  93. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2022_raptor_cove_gen_13_14/specs_intel.json +0 -0
  94. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2023_redwood_cove_ultra_1/benchmark_ec2_m8i_xlarge_granite_rapids.json +0 -0
  95. {counted_float-0.9.7 → counted_float-1.0.0}/counted_float/data/x86/intel/2023_redwood_cove_ultra_1/specs_intel.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: counted-float
3
- Version: 0.9.7
3
+ Version: 1.0.0
4
4
  Summary: Count floating-point operations in Python code & benchmark relative flop costs.
5
5
  Project-URL: Source, https://github.com/bertpl/counted-float
6
6
  Project-URL: ChangeLog, https://github.com/bertpl/counted-float/blob/develop/CHANGELOG.md
@@ -21,9 +21,9 @@ Description-Content-Type: text/markdown
21
21
 
22
22
  <!--START_SECTION:images-->
23
23
  ![shields.io-python-versions](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue)
24
- ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v0.9.7/badge-test-count.svg)
25
- ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v0.9.7/badge-coverage.svg)
26
- ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v0.9.7/splash.webp)
24
+ ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v1.0.0/badge-test-count.svg)
25
+ ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v1.0.0/badge-coverage.svg)
26
+ ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v1.0.0/splash.webp)
27
27
  <!--END_SECTION:images-->
28
28
 
29
29
  # counted-float
@@ -467,10 +467,38 @@ ALL 0.47 0.70
467
467
 
468
468
  ```
469
469
 
470
- # 5. Known limitations
470
+ ## 4.2. Test performance of `CountedFloat` vs `float`
471
+
472
+ ```
473
+ [~] counted_float benchmark-counted-float
474
+ ```
475
+ See next section for results.
476
+
477
+ # 5. Performance impact
478
+
479
+ Obviously, using `CountedFloat` instead of regular `float` will have a performance impact due to the overhead of counting operations.
480
+ It is not advised to use `CountedFloat` for production code, but just for research code for which you want to estimate the floating-point operation count.
481
+
482
+ Micro-benchmarking of a bisection algorithm using `counted_float benchmark-counted-float` teaches us this:
483
+ ```
484
+ ------------------------------------------------------------------------------------------------------------------------
485
+ Running CountedFloat benchmark...
486
+
487
+ float : wwwwwwwwwwwwwww................................... [ 12.34 µs ± 1.2% | 50.1K cpu cycles ± 1.2% ] / execution
488
+ CountedFloat : wwwwwwwwwwwwwww................................... [ 459.95 µs ± 0.2% | 1.87M cpu cycles ± 0.2% ] / execution
489
+ ------------------------------------------------------------------------------------------------------------------------
490
+
491
+ CountedFloat Benchmark Results:
492
+ Bisection using float : 12.34 µs / execution
493
+ Bisection using CountedFloat : 459.95 µs / execution
494
+
495
+ CountedFloat is 37.3x slower than float
496
+ ```
497
+
498
+ # 6. Known limitations
471
499
 
472
500
  - currently any non-Python-built-in math operations are not counted (e.g. `numpy`)
473
- - not all Python built-in math operations are counted (e.g. `log`, `log10`, `exp`, `exp10`)
501
+ - not all Python built-in math operations are counted (e.g. hyperbolic functions)
474
502
  - flop weights should be taken with a grain of salt and should only provide relative ballpark estimates w.r.t computational complexity. Production implementations in a compiled language could have vastly differing performance depending on cpu cache sizes, branch prediction misses, compiler optimizations using vector operations (AVX etc...), etc...
475
503
 
476
504
  # Appendix A - Flop counting / analysis details
@@ -1,8 +1,8 @@
1
1
  <!--START_SECTION:images-->
2
2
  ![shields.io-python-versions](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue)
3
- ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v0.9.7/badge-test-count.svg)
4
- ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v0.9.7/badge-coverage.svg)
5
- ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v0.9.7/splash.webp)
3
+ ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v1.0.0/badge-test-count.svg)
4
+ ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v1.0.0/badge-coverage.svg)
5
+ ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v1.0.0/splash.webp)
6
6
  <!--END_SECTION:images-->
7
7
 
8
8
  # counted-float
@@ -446,10 +446,38 @@ ALL 0.47 0.70
446
446
 
447
447
  ```
448
448
 
449
- # 5. Known limitations
449
+ ## 4.2. Test performance of `CountedFloat` vs `float`
450
+
451
+ ```
452
+ [~] counted_float benchmark-counted-float
453
+ ```
454
+ See next section for results.
455
+
456
+ # 5. Performance impact
457
+
458
+ Obviously, using `CountedFloat` instead of regular `float` will have a performance impact due to the overhead of counting operations.
459
+ It is not advised to use `CountedFloat` for production code, but just for research code for which you want to estimate the floating-point operation count.
460
+
461
+ Micro-benchmarking of a bisection algorithm using `counted_float benchmark-counted-float` teaches us this:
462
+ ```
463
+ ------------------------------------------------------------------------------------------------------------------------
464
+ Running CountedFloat benchmark...
465
+
466
+ float : wwwwwwwwwwwwwww................................... [ 12.34 µs ± 1.2% | 50.1K cpu cycles ± 1.2% ] / execution
467
+ CountedFloat : wwwwwwwwwwwwwww................................... [ 459.95 µs ± 0.2% | 1.87M cpu cycles ± 0.2% ] / execution
468
+ ------------------------------------------------------------------------------------------------------------------------
469
+
470
+ CountedFloat Benchmark Results:
471
+ Bisection using float : 12.34 µs / execution
472
+ Bisection using CountedFloat : 459.95 µs / execution
473
+
474
+ CountedFloat is 37.3x slower than float
475
+ ```
476
+
477
+ # 6. Known limitations
450
478
 
451
479
  - currently any non-Python-built-in math operations are not counted (e.g. `numpy`)
452
- - not all Python built-in math operations are counted (e.g. `log`, `log10`, `exp`, `exp10`)
480
+ - not all Python built-in math operations are counted (e.g. hyperbolic functions)
453
481
  - flop weights should be taken with a grain of salt and should only provide relative ballpark estimates w.r.t computational complexity. Production implementations in a compiled language could have vastly differing performance depending on cpu cache sizes, branch prediction misses, compiler optimizations using vector operations (AVX etc...), etc...
454
482
 
455
483
  # Appendix A - Flop counting / analysis details
@@ -1,7 +1,7 @@
1
1
  import click
2
2
 
3
3
  from counted_float import BuiltInData
4
- from counted_float.benchmarking import run_flops_benchmark
4
+ from counted_float._core.benchmarking import run_counted_float_benchmark, run_flops_benchmark
5
5
 
6
6
 
7
7
  # -------------------------------------------------------------------------
@@ -22,3 +22,9 @@ def benchmark():
22
22
  @click.option("--key_filter", default="", help="Optional key filter for built-in data")
23
23
  def show_data(key_filter: str):
24
24
  BuiltInData.show(key_filter=key_filter)
25
+
26
+
27
+ @cli.command(short_help="run benchmark of float vs CountedFloat performance")
28
+ def benchmark_counted_float():
29
+ result = run_counted_float_benchmark()
30
+ result.show()
@@ -0,0 +1,37 @@
1
+ from .counted_float import BenchmarkCountedFloat, BenchmarkFloat, CountedFloatBenchmarkResults
2
+ from .flops import FlopsBenchmarkResults, FlopsBenchmarkSuite
3
+
4
+
5
+ def run_flops_benchmark(n_seconds_per_run_target: float = 0.1) -> FlopsBenchmarkResults:
6
+ """Run the flops benchmark suite with default settings returns a FlopsBenchmarkResults object."""
7
+
8
+ benchmark_results = FlopsBenchmarkSuite().run(n_seconds_per_run_target=n_seconds_per_run_target)
9
+
10
+ print()
11
+
12
+ return benchmark_results
13
+
14
+
15
+ def run_counted_float_benchmark(t_target_sec: float = 0.1) -> CountedFloatBenchmarkResults:
16
+ """Run benchmark to compare performance of float vs CountedFloat."""
17
+ print("-" * 120)
18
+ print("Running CountedFloat benchmark...")
19
+ print()
20
+
21
+ result_float = BenchmarkFloat().run_many(
22
+ n_runs_total=50,
23
+ n_runs_warmup=15,
24
+ n_seconds_per_run_target=t_target_sec,
25
+ )
26
+ result_counted_float = BenchmarkCountedFloat().run_many(
27
+ n_runs_total=50,
28
+ n_runs_warmup=15,
29
+ n_seconds_per_run_target=t_target_sec,
30
+ )
31
+ print("-" * 120)
32
+ print()
33
+
34
+ return CountedFloatBenchmarkResults(
35
+ float_time_nsec=result_float.summary_stats_nsecs_per_exec().q50,
36
+ counted_float_time_nsec=result_counted_float.summary_stats_nsecs_per_exec().q50,
37
+ )
@@ -0,0 +1 @@
1
+ from ._counted_float_benchmark import BenchmarkCountedFloat, BenchmarkFloat, CountedFloatBenchmarkResults
@@ -0,0 +1,83 @@
1
+ from counted_float._core.benchmarking.micro import MicroBenchmark
2
+ from counted_float._core.counting import CountedFloat
3
+ from counted_float._core.models import MyBaseModel
4
+ from counted_float._core.utils import format_time_duration
5
+
6
+
7
+ # =================================================================================================
8
+ # Result class
9
+ # =================================================================================================
10
+ class CountedFloatBenchmarkResults(MyBaseModel):
11
+ float_time_nsec: float
12
+ counted_float_time_nsec: float
13
+
14
+ def show(self):
15
+ print("CountedFloat Benchmark Results:")
16
+ print(f" Bisection using float : {format_time_duration(self.float_time_nsec)} / execution")
17
+ print(f" Bisection using CountedFloat : {format_time_duration(self.counted_float_time_nsec)} / execution")
18
+ ratio = self.counted_float_time_nsec / self.float_time_nsec
19
+ print()
20
+ print(f"CountedFloat is {ratio:.1f}x slower than float")
21
+
22
+
23
+ # =================================================================================================
24
+ # MicroBenchmarks
25
+ # =================================================================================================
26
+ def _zero_function(x: float) -> float:
27
+ # function for which we want to find a root
28
+ return (x * x * x) - 7.0
29
+
30
+
31
+ class BenchmarkFloat(MicroBenchmark):
32
+ def __init__(self):
33
+ super().__init__(name="float")
34
+ self._n_executions = 1
35
+
36
+ def _prepare_benchmark(self, n_executions: int):
37
+ self._n_executions = n_executions
38
+
39
+ def _run_benchmark(self):
40
+ for _ in range(self._n_executions):
41
+ # Execute bisection to find root of _zero_function in interval [-1e50,1e50],
42
+ # using standard float() arithmetic
43
+ a = -1e50
44
+ b = 1e50
45
+ fa = _zero_function(a)
46
+ fb = _zero_function(b)
47
+ while b - a > 1e-15:
48
+ mid = 0.5 * (a + b)
49
+ fmid = _zero_function(mid)
50
+ if fmid < 0:
51
+ a = mid
52
+ fa = fmid
53
+ else:
54
+ b = mid
55
+ fb = fmid
56
+
57
+
58
+ class BenchmarkCountedFloat(MicroBenchmark):
59
+ def __init__(self):
60
+ super().__init__(name="CountedFloat")
61
+ self._n_executions = 1
62
+
63
+ def _prepare_benchmark(self, n_executions: int):
64
+ self._n_executions = n_executions
65
+
66
+ def _run_benchmark(self):
67
+ for _ in range(self._n_executions):
68
+ # Execute bisection to find root of _zero_function in interval [-1e50,1e50],
69
+ # with identical implementation as BenchmarkFloat, except that we initialize a,b as CountedFloats,
70
+ # which will make sure all the remaining operations are also executed using CountedFloat arithmetic
71
+ a = CountedFloat(-1e50)
72
+ b = CountedFloat(1e50)
73
+ fa = _zero_function(a)
74
+ fb = _zero_function(b)
75
+ while b - a > 1e-15:
76
+ mid = 0.5 * (a + b)
77
+ fmid = _zero_function(mid)
78
+ if fmid < 0:
79
+ a = mid
80
+ fa = fmid
81
+ else:
82
+ b = mid
83
+ fb = fmid
@@ -115,9 +115,9 @@ class MicroBenchmark(ABC):
115
115
  run by the MicroBenchmarkRunner class to ensure that the benchmark_runs runs for a reasonable amount of time
116
116
  (e.g. 1 second per run).
117
117
  """
118
- raise NotImplementedError()
118
+ ...
119
119
 
120
120
  @abstractmethod
121
121
  def _run_benchmark(self):
122
122
  """Run benchmark_runs. This method is called multiple times and the time spent here is measured."""
123
- raise NotImplementedError()
123
+ ...
@@ -35,11 +35,7 @@ def impute_missing_data(data: np.ndarray) -> np.ndarray:
35
35
  ]
36
36
 
37
37
  # overall exact correction is geo_mean of these factors, which we'll apply with step e_step
38
- try:
39
- c_row_correct[i_row] = geo_mean(factors) ** e_step if factors else np.nan
40
- except TypeError as e:
41
- print(e)
42
- pass
38
+ c_row_correct[i_row] = geo_mean(factors) ** e_step if factors else np.nan
43
39
 
44
40
  # compute correction factors for c_cols
45
41
  c_col_correct = np.zeros(n_cols)
@@ -1,6 +1,7 @@
1
- from counted_float._core.benchmarking import FlopsBenchmarkResults, run_flops_benchmark
1
+ from counted_float._core.benchmarking import FlopsBenchmarkResults, run_counted_float_benchmark, run_flops_benchmark
2
2
 
3
3
  __all__ = [
4
4
  "FlopsBenchmarkResults",
5
+ "run_counted_float_benchmark",
5
6
  "run_flops_benchmark",
6
7
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "counted-float"
3
- version = "0.9.7"
3
+ version = "1.0.0"
4
4
  description = "Count floating-point operations in Python code & benchmark relative flop costs."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,11 +0,0 @@
1
- from .flops import FlopsBenchmarkResults, FlopsBenchmarkSuite
2
-
3
-
4
- def run_flops_benchmark() -> FlopsBenchmarkResults:
5
- """Run the flops benchmark suite with default settings returns a FlopsBenchmarkResults object."""
6
-
7
- benchmark_results = FlopsBenchmarkSuite().run()
8
-
9
- print()
10
-
11
- return benchmark_results
File without changes
File without changes