mirror of
https://github.com/google/benchmark.git
synced 2024-12-26 12:30:14 +08:00
Add nb::is_flag()
annotation to Counter::Flags (#1870)
This saves us the definition of `__or__`, because we can just use the one from `enum.IntFlag`.
This commit is contained in:
parent
4e3f2d8b67
commit
d99cdd7356
@ -118,7 +118,7 @@ NB_MODULE(_benchmark, m) {
|
||||
using benchmark::Counter;
|
||||
nb::class_<Counter> py_counter(m, "Counter");
|
||||
|
||||
nb::enum_<Counter::Flags>(py_counter, "Flags", nb::is_arithmetic())
|
||||
nb::enum_<Counter::Flags>(py_counter, "Flags", nb::is_arithmetic(), nb::is_flag())
|
||||
.value("kDefaults", Counter::Flags::kDefaults)
|
||||
.value("kIsRate", Counter::Flags::kIsRate)
|
||||
.value("kAvgThreads", Counter::Flags::kAvgThreads)
|
||||
@ -129,10 +129,7 @@ NB_MODULE(_benchmark, m) {
|
||||
.value("kAvgIterations", Counter::Flags::kAvgIterations)
|
||||
.value("kAvgIterationsRate", Counter::Flags::kAvgIterationsRate)
|
||||
.value("kInvert", Counter::Flags::kInvert)
|
||||
.export_values()
|
||||
.def("__or__", [](Counter::Flags a, Counter::Flags b) {
|
||||
return static_cast<int>(a) | static_cast<int>(b);
|
||||
});
|
||||
.export_values();
|
||||
|
||||
nb::enum_<Counter::OneK>(py_counter, "OneK")
|
||||
.value("kIs1000", Counter::OneK::kIs1000)
|
||||
@ -140,11 +137,7 @@ NB_MODULE(_benchmark, m) {
|
||||
.export_values();
|
||||
|
||||
py_counter
|
||||
.def(
|
||||
"__init__",
|
||||
[](Counter* c, double value, int flags, Counter::OneK oneK) {
|
||||
new (c) Counter(value, static_cast<Counter::Flags>(flags), oneK);
|
||||
},
|
||||
.def(nb::init<double, Counter::Flags, Counter::OneK>(),
|
||||
nb::arg("value") = 0., nb::arg("flags") = Counter::kDefaults,
|
||||
nb::arg("k") = Counter::kIs1000)
|
||||
.def("__init__",
|
||||
|
Loading…
Reference in New Issue
Block a user