From dff811a57a8c94f5b8211fcf4617c23c44b4fa23 Mon Sep 17 00:00:00 2001 From: Lehman Garrison Date: Thu, 13 Jul 2023 11:59:13 -0400 Subject: [PATCH 1/7] mocks: warn about small theta and large mu in float32 precision --- Corrfunc/mocks/DDsmu_mocks.py | 27 ++++++++++++++++++++++ Corrfunc/mocks/DDtheta_mocks.py | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/Corrfunc/mocks/DDsmu_mocks.py b/Corrfunc/mocks/DDsmu_mocks.py index 7e3c37cc..29895539 100644 --- a/Corrfunc/mocks/DDsmu_mocks.py +++ b/Corrfunc/mocks/DDsmu_mocks.py @@ -8,6 +8,7 @@ from __future__ import (division, print_function, absolute_import, unicode_literals) +import warnings __author__ = ('Manodeep Sinha', 'Nick Hand') __all__ = ('DDsmu_mocks', ) @@ -296,6 +297,12 @@ def DDsmu_mocks(autocorr, cosmology, nthreads, mu_max, nmu_bins, binfile, integer_isa = translate_isa_string_to_enum(isa) sbinfile, delete_after_use = return_file_with_rbins(binfile) + + warn_large_mu(mu_max, + # RA and DEC are checked to be the same dtype + dtype=RA1.dtype, + ) + with sys_pipes(): extn_results = DDsmu_extn(autocorr, cosmology, nthreads, mu_max, nmu_bins, sbinfile, @@ -344,6 +351,26 @@ def DDsmu_mocks(autocorr, cosmology, nthreads, mu_max, nmu_bins, binfile, else: return results, api_time + +def warn_large_mu(mu_max, dtype): + ''' + Small theta values (large mu) underfloat float32. Warn the user. + Context: https://github.com/manodeep/Corrfunc/pull/297 + ''' + if dtype.itemsize > 4: + return + + if mu_max >= 0.9800666: # cos(0.2) + warnings.warn(""" +Be aware that small angular pair separations (mu near 1) will suffer from loss +of floating-point precision, as the input data is in float32 precision or +lower. In float32, the loss of precision is 1% in mu at separations of 0.2 +degrees, and larger at smaller separations. +For more information, see: https://github.com/manodeep/Corrfunc/pull/297 +""" + ) + + if __name__ == '__main__': import doctest doctest.testmod() diff --git a/Corrfunc/mocks/DDtheta_mocks.py b/Corrfunc/mocks/DDtheta_mocks.py index 1ac29d9d..45e30ed4 100644 --- a/Corrfunc/mocks/DDtheta_mocks.py +++ b/Corrfunc/mocks/DDtheta_mocks.py @@ -10,6 +10,7 @@ from __future__ import (division, print_function, absolute_import, unicode_literals) +import warnings __author__ = ('Manodeep Sinha', 'Kris Akira Stern') __all__ = ('DDtheta_mocks', 'find_fastest_DDtheta_mocks_bin_refs') @@ -313,6 +314,11 @@ def DDtheta_mocks(autocorr, nthreads, binfile, integer_isa = translate_isa_string_to_enum(isa) rbinfile, delete_after_use = return_file_with_rbins(binfile) + + warn_small_theta(rbinfile, + RA1.dtype, # RA and DEC are checked to be the same dtype + ) + with sys_pipes(): extn_results = DDtheta_mocks_extn(autocorr, nthreads, rbinfile, RA1, DEC1, @@ -644,6 +650,40 @@ def find_fastest_DDtheta_mocks_bin_refs(autocorr, nthreads, binfile, return ret +def warn_small_theta(thetabinfile, dtype): + ''' + Small theta values underfloat float32. Warn the user. + Context: https://github.com/manodeep/Corrfunc/pull/297 + ''' + if dtype.itemsize > 4: + return + + import numpy as np + try: + bins = np.loadtxt(thetabinfile) + except RuntimeError: + warnings.warn(""" +Could not load binfile "{}". Be aware that small angular pair separations +will suffer from loss of floating-point precision, as the input data is in +float32 precision or lower. The loss of precision is 0.5% in theta at +separations of 0.2 degrees, and larger at smaller separations. +For more information, see: https://github.com/manodeep/Corrfunc/pull/297 +""".format(thetabinfile) + ) + return + + if bins.min() <= 0.2: + warnings.warn(""" +A binning with a minimum angular separation of 0.2 degrees or less was +requested, and the input data is in float32 precision or lower. Be aware that +small angular pair separations will suffer from loss of floating-point +precision. In float32, the loss of precision is 0.5% in theta at separations of +0.2 degrees, and larger at smaller separations. +For more information, see: https://github.com/manodeep/Corrfunc/pull/297 +""" + ) + + if __name__ == '__main__': import doctest From 8b3360ad3a0416825f75be1251dccba1c5327beb Mon Sep 17 00:00:00 2001 From: Lehman Garrison Date: Fri, 14 Jul 2023 10:36:01 -0400 Subject: [PATCH 2/7] mocks: update small theta warning. Update changelog. --- CHANGES.rst | 4 ++++ Corrfunc/mocks/DDsmu_mocks.py | 5 +++-- Corrfunc/mocks/DDtheta_mocks.py | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b807b6a7..c4d10113 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,6 +18,10 @@ Changes ------- - Python >= 3.7 and numpy >= 1.16 are required for python extensions [#291] +Enhancements +------------ +- mocks: warn about small theta and large mu in float32 precision [#299] + 2.5.0 (2022-12-23) ================ diff --git a/Corrfunc/mocks/DDsmu_mocks.py b/Corrfunc/mocks/DDsmu_mocks.py index 29895539..79d8312a 100644 --- a/Corrfunc/mocks/DDsmu_mocks.py +++ b/Corrfunc/mocks/DDsmu_mocks.py @@ -355,7 +355,7 @@ def DDsmu_mocks(autocorr, cosmology, nthreads, mu_max, nmu_bins, binfile, def warn_large_mu(mu_max, dtype): ''' Small theta values (large mu) underfloat float32. Warn the user. - Context: https://github.com/manodeep/Corrfunc/pull/297 + Context: https://github.com/manodeep/Corrfunc/pull/296 (see also #297) ''' if dtype.itemsize > 4: return @@ -366,7 +366,8 @@ def warn_large_mu(mu_max, dtype): of floating-point precision, as the input data is in float32 precision or lower. In float32, the loss of precision is 1% in mu at separations of 0.2 degrees, and larger at smaller separations. -For more information, see: https://github.com/manodeep/Corrfunc/pull/297 +For more information, see: +https://github.com/manodeep/Corrfunc/pull/296 (see also #297) """ ) diff --git a/Corrfunc/mocks/DDtheta_mocks.py b/Corrfunc/mocks/DDtheta_mocks.py index 45e30ed4..a34be1c4 100644 --- a/Corrfunc/mocks/DDtheta_mocks.py +++ b/Corrfunc/mocks/DDtheta_mocks.py @@ -653,7 +653,7 @@ def find_fastest_DDtheta_mocks_bin_refs(autocorr, nthreads, binfile, def warn_small_theta(thetabinfile, dtype): ''' Small theta values underfloat float32. Warn the user. - Context: https://github.com/manodeep/Corrfunc/pull/297 + Context: https://github.com/manodeep/Corrfunc/pull/296 (see also #297) ''' if dtype.itemsize > 4: return @@ -667,7 +667,8 @@ def warn_small_theta(thetabinfile, dtype): will suffer from loss of floating-point precision, as the input data is in float32 precision or lower. The loss of precision is 0.5% in theta at separations of 0.2 degrees, and larger at smaller separations. -For more information, see: https://github.com/manodeep/Corrfunc/pull/297 +For more information, see: +https://github.com/manodeep/Corrfunc/pull/296 (see also #297) """.format(thetabinfile) ) return @@ -679,7 +680,8 @@ def warn_small_theta(thetabinfile, dtype): small angular pair separations will suffer from loss of floating-point precision. In float32, the loss of precision is 0.5% in theta at separations of 0.2 degrees, and larger at smaller separations. -For more information, see: https://github.com/manodeep/Corrfunc/pull/297 +For more information, see: +https://github.com/manodeep/Corrfunc/pull/296 (see also #297) """ ) From 0aef4e62bd5c555ab9d130615fdec062861054f1 Mon Sep 17 00:00:00 2001 From: Manodeep Sinha Date: Mon, 17 Jul 2023 21:12:55 +1000 Subject: [PATCH 3/7] Update CHANGES.rst @lgarrison Re-worded the changelog - see if that works for you. --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index c4d10113..23ab1a29 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,7 +20,7 @@ Changes Enhancements ------------ -- mocks: warn about small theta and large mu in float32 precision [#299] +- Warn about loss of precision for float32 calculations involving small ``theta`` in ``DDtheta_mocks`` and large ``mu`` in ``DDsmu_mocks`` [#299] 2.5.0 (2022-12-23) ================ From e54c451f43710ecd1d0e3cd300869c4bb952de25 Mon Sep 17 00:00:00 2001 From: Manodeep Sinha Date: Mon, 17 Jul 2023 21:13:57 +1000 Subject: [PATCH 4/7] Update DDsmu_mocks.py Fixed typo --- Corrfunc/mocks/DDsmu_mocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corrfunc/mocks/DDsmu_mocks.py b/Corrfunc/mocks/DDsmu_mocks.py index 79d8312a..326ae626 100644 --- a/Corrfunc/mocks/DDsmu_mocks.py +++ b/Corrfunc/mocks/DDsmu_mocks.py @@ -355,7 +355,7 @@ def DDsmu_mocks(autocorr, cosmology, nthreads, mu_max, nmu_bins, binfile, def warn_large_mu(mu_max, dtype): ''' Small theta values (large mu) underfloat float32. Warn the user. - Context: https://github.com/manodeep/Corrfunc/pull/296 (see also #297) + Context: https://github.com/manodeep/Corrfunc/issues/296 (see also #297) ''' if dtype.itemsize > 4: return From 43cec423b5d42fc06ec9ece5fd5fc54b9f31e1fd Mon Sep 17 00:00:00 2001 From: Manodeep Sinha Date: Mon, 17 Jul 2023 21:14:30 +1000 Subject: [PATCH 5/7] Update DDtheta_mocks.py Fixed typo --- Corrfunc/mocks/DDtheta_mocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corrfunc/mocks/DDtheta_mocks.py b/Corrfunc/mocks/DDtheta_mocks.py index a34be1c4..73725c39 100644 --- a/Corrfunc/mocks/DDtheta_mocks.py +++ b/Corrfunc/mocks/DDtheta_mocks.py @@ -653,7 +653,7 @@ def find_fastest_DDtheta_mocks_bin_refs(autocorr, nthreads, binfile, def warn_small_theta(thetabinfile, dtype): ''' Small theta values underfloat float32. Warn the user. - Context: https://github.com/manodeep/Corrfunc/pull/296 (see also #297) + Context: https://github.com/manodeep/Corrfunc/issues/296 (see also #297) ''' if dtype.itemsize > 4: return From b71d8a40e3f327358b747ae54e01bc202288f035 Mon Sep 17 00:00:00 2001 From: Manodeep Sinha Date: Mon, 17 Jul 2023 21:15:58 +1000 Subject: [PATCH 6/7] Update DDsmu_mocks.py Fixed typo --- Corrfunc/mocks/DDsmu_mocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corrfunc/mocks/DDsmu_mocks.py b/Corrfunc/mocks/DDsmu_mocks.py index 326ae626..2d141187 100644 --- a/Corrfunc/mocks/DDsmu_mocks.py +++ b/Corrfunc/mocks/DDsmu_mocks.py @@ -367,7 +367,7 @@ def warn_large_mu(mu_max, dtype): lower. In float32, the loss of precision is 1% in mu at separations of 0.2 degrees, and larger at smaller separations. For more information, see: -https://github.com/manodeep/Corrfunc/pull/296 (see also #297) +https://github.com/manodeep/Corrfunc/issues/296 (see also #297) """ ) From 6ede3722ea4eaf306c7229839c26166a94786bb3 Mon Sep 17 00:00:00 2001 From: Manodeep Sinha Date: Mon, 17 Jul 2023 21:17:02 +1000 Subject: [PATCH 7/7] Update DDtheta_mocks.py Fixed typo --- Corrfunc/mocks/DDtheta_mocks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Corrfunc/mocks/DDtheta_mocks.py b/Corrfunc/mocks/DDtheta_mocks.py index 73725c39..d4b144af 100644 --- a/Corrfunc/mocks/DDtheta_mocks.py +++ b/Corrfunc/mocks/DDtheta_mocks.py @@ -668,7 +668,7 @@ def warn_small_theta(thetabinfile, dtype): float32 precision or lower. The loss of precision is 0.5% in theta at separations of 0.2 degrees, and larger at smaller separations. For more information, see: -https://github.com/manodeep/Corrfunc/pull/296 (see also #297) +https://github.com/manodeep/Corrfunc/issues/296 (see also #297) """.format(thetabinfile) ) return @@ -681,7 +681,7 @@ def warn_small_theta(thetabinfile, dtype): precision. In float32, the loss of precision is 0.5% in theta at separations of 0.2 degrees, and larger at smaller separations. For more information, see: -https://github.com/manodeep/Corrfunc/pull/296 (see also #297) +https://github.com/manodeep/Corrfunc/issues/296 (see also #297) """ )