From 62fafef148dd547b4f2c180c5d43bd9c6d43c6ed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:21:15 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/units_python.cpp | 102 ++++++++++++++++---------------- test/python/test_measurement.py | 16 ++--- test/python/test_units.py | 4 +- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/python/units_python.cpp b/python/units_python.cpp index f75f8c17..9669c4cc 100644 --- a/python/units_python.cpp +++ b/python/units_python.cpp @@ -35,11 +35,11 @@ NB_MODULE(units_llnl_ext, mod) .def( "__init__", [](units::precise_unit* type, - const char* arg0, - const char* commodity) { - new (type) units::precise_unit{ - units::unit_from_string(std::string(arg0)), - units::getCommodity(std::string(commodity))}; + const char* arg0, + const char* commodity) { + new (type) units::precise_unit{ + units::unit_from_string(std::string(arg0)), + units::getCommodity(std::string(commodity))}; }) .def("multiplier", &units::precise_unit::multiplier) .def( @@ -74,28 +74,28 @@ NB_MODULE(units_llnl_ext, mod) .def( "is_exactly_the_same", [](const units::precise_unit& type1, - const units::precise_unit& type2) { - return type1.is_exactly_the_same(type2); + const units::precise_unit& type2) { + return type1.is_exactly_the_same(type2); }) .def( "has_same_base", [](const units::precise_unit& type1, - const units::precise_unit& type2) { - return type1.has_same_base(type2); + const units::precise_unit& type2) { + return type1.has_same_base(type2); }, "check if two units have the same base units as each other") .def( "equivalent_non_counting", [](const units::precise_unit& type1, - const units::precise_unit& type2) { - return type1.equivalent_non_counting(type2); + const units::precise_unit& type2) { + return type1.equivalent_non_counting(type2); }, "check if two units are equivalent in the non-counting units portion of the units (moles|radians|count)") .def( "is_convertible", [](const units::precise_unit& type1, - const units::precise_unit& type2) { - return type1.is_convertible(type2); + const units::precise_unit& type2) { + return type1.is_convertible(type2); }, "check if two units are convertible to each other") .def( @@ -158,8 +158,8 @@ NB_MODULE(units_llnl_ext, mod) return units::to_string(type); }) .def("to_string", [](const units::precise_unit& type) { - return units::to_string(type); - }); + return units::to_string(type); + }); nb::class_( mod, @@ -175,17 +175,17 @@ NB_MODULE(units_llnl_ext, mod) .def( "__init__", [](units::precise_measurement* measurement, - double value, - const char* arg0) { - new (measurement) units::precise_measurement( - value, units::unit_from_string(std::string(arg0))); + double value, + const char* arg0) { + new (measurement) units::precise_measurement( + value, units::unit_from_string(std::string(arg0))); }) .def( "__init__", [](units::precise_measurement* measurement, - double value, - const units::precise_unit& unit) { - new (measurement) units::precise_measurement(value, unit); + double value, + const units::precise_unit& unit) { + new (measurement) units::precise_measurement(value, unit); }) .def("value", &units::precise_measurement::value) .def( @@ -206,28 +206,28 @@ NB_MODULE(units_llnl_ext, mod) .def( "value_as", [](const units::precise_measurement& measurement, - const units::precise_unit& unit) { - return measurement.value_as(unit); + const units::precise_unit& unit) { + return measurement.value_as(unit); }) .def( "value_as", [](const units::precise_measurement& measurement, - const char* units) { - return measurement.value_as( - units::unit_from_string(std::string(units))); + const char* units) { + return measurement.value_as( + units::unit_from_string(std::string(units))); }) .def( "convert_to", [](const units::precise_measurement& measurement, - const units::precise_unit& unit) { - return measurement.convert_to(unit); + const units::precise_unit& unit) { + return measurement.convert_to(unit); }) .def( "convert_to", [](const units::precise_measurement& measurement, - const char* units) { - return measurement.convert_to( - units::unit_from_string(std::string(units))); + const char* units) { + return measurement.convert_to( + units::unit_from_string(std::string(units))); }) .def("convert_to_base", &units::precise_measurement::convert_to_base) .def("as_unit", &units::precise_measurement::as_unit) @@ -247,7 +247,9 @@ NB_MODULE(units_llnl_ext, mod) .def(nb::self < nb::self) .def( "__pow__", - [](const units::precise_measurement& measurement, int power) { return pow(measurement,power); }, + [](const units::precise_measurement& measurement, int power) { + return pow(measurement, power); + }, nb::is_operator()) .def( "is_valid", @@ -275,15 +277,15 @@ NB_MODULE(units_llnl_ext, mod) return units::to_string(measurement); }) .def("to_string", [](const units::precise_measurement& measurement) { - return units::to_string(measurement); - }); + return units::to_string(measurement); + }); mod.def( "convert", [](double val, - const units::precise_unit& unitIn, - const units::precise_unit& unitOut) { - return units::convert(val, unitIn, unitOut); + const units::precise_unit& unitIn, + const units::precise_unit& unitOut) { + return units::convert(val, unitIn, unitOut); }, "value"_a, "unit_in"_a, @@ -304,10 +306,10 @@ NB_MODULE(units_llnl_ext, mod) mod.def( "convert_pu", [](double val, - const units::precise_unit& unitIn, - const units::precise_unit& unitOut, - double base_value) { - return units::convert(val, unitIn, unitOut, base_value); + const units::precise_unit& unitIn, + const units::precise_unit& unitOut, + double base_value) { + return units::convert(val, unitIn, unitOut, base_value); }, "value"_a, "unit_in"_a, @@ -317,14 +319,14 @@ NB_MODULE(units_llnl_ext, mod) mod.def( "convert_pu", [](double val, - const char* unitIn, - const char* unitOut, - double base_value) { - return units::convert( - val, - units::unit_from_string(std::string(unitIn)), - units::unit_from_string(std::string(unitOut)), - base_value); + const char* unitIn, + const char* unitOut, + double base_value) { + return units::convert( + val, + units::unit_from_string(std::string(unitIn)), + units::unit_from_string(std::string(unitOut)), + base_value); }, "value"_a, "unit_in"_a, diff --git a/test/python/test_measurement.py b/test/python/test_measurement.py index 9457f455..be163b66 100644 --- a/test/python/test_measurement.py +++ b/test/python/test_measurement.py @@ -11,22 +11,22 @@ def test_basic_measurement(): m3=m1/m2 m4=u.measurement('4.0 m/s') assert(m3==m4) - + def test_basic_measurement2(): m1=u.measurement(10,'m') m2=u.measurement(2.5, 's') m3=m1/m2 m4=u.measurement(4.0, 'm/s') assert(m3==m4) - + def test_basic_measurement3(): - + u1=u.unit('m') u2=u.unit('s') - + m1=u.measurement(10,u1) m2=u.measurement(2.5, u2) - + m4=u.measurement(4.0, u1/u2) assert(m1/m2==m4) @@ -42,7 +42,7 @@ def test_conditions(): assert(not m3.is_normal()) assert(m3.is_valid()) - + def test_root(): m1=u.measurement('100 m^6 per second squared') m2=m1.root(2) @@ -50,14 +50,14 @@ def test_root(): m4=u.measurement('10 m*m*m/s') assert(m2==m3) assert(m3==m4) - + def test_pow(): m1=u.measurement('10 m') m2=m1**2 m3=m1**3 assert(m2==m1*m1) assert(m3==m1*m1*m1) - + def test_comparisons(): m1=u.measurement('10 m') m2=u.measurement('11 m') diff --git a/test/python/test_units.py b/test/python/test_units.py index e50a7015..0efb4009 100644 --- a/test/python/test_units.py +++ b/test/python/test_units.py @@ -11,7 +11,7 @@ def test_basic_unit(): u3=u1/u2 u4=u.unit('mph') assert(u3.is_convertible(u4)) - + def test_basic_multiplication(): u1=u.unit('m') u2=u.unit('s') @@ -34,7 +34,7 @@ def test_conditions(): assert(u1.is_finite()) assert(u3.is_valid()) assert(not u3.is_finite()) - + def test_root(): u1=u.unit('m^6 per second squared') u2=u1.root(2)