From 734889c98eb7a271dedd437f7dea0ad2517a2c5e Mon Sep 17 00:00:00 2001 From: Takeshi Ikuma Date: Sun, 28 Feb 2021 12:00:25 -0600 Subject: [PATCH] Reverted format to master --- src/parselmouth/Vector.cpp | 197 +++++++++++++++++-------------------- 1 file changed, 91 insertions(+), 106 deletions(-) diff --git a/src/parselmouth/Vector.cpp b/src/parselmouth/Vector.cpp index 6badb3d6..f5ca299b 100644 --- a/src/parselmouth/Vector.cpp +++ b/src/parselmouth/Vector.cpp @@ -30,119 +30,104 @@ namespace py = pybind11; using namespace py::literals; -namespace parselmouth +namespace parselmouth { + +PRAAT_ENUM_BINDING(ValueInterpolation) { + value("NEAREST", kVector_valueInterpolation::NEAREST); + value("LINEAR", kVector_valueInterpolation::LINEAR); + value("CUBIC", kVector_valueInterpolation::CUBIC); + value("SINC70", kVector_valueInterpolation::SINC70); + value("SINC700", kVector_valueInterpolation::SINC700); + + make_implicitly_convertible_from_string(*this); +} + + +PRAAT_ENUM_BINDING(PeakInterpolation) { + value("NONE", kVector_peakInterpolation::NONE); + value("PARABOLIC", kVector_peakInterpolation::PARABOLIC); + value("CUBIC", kVector_peakInterpolation::CUBIC); + value("SINC70", kVector_peakInterpolation::SINC70); + value("SINC700", kVector_peakInterpolation::SINC700); + + make_implicitly_convertible_from_string(*this); +} + +PRAAT_CLASS_BINDING(Vector) { + using signature_cast_placeholder::_; + + // TODO Something to get rid of duplicate functions with different names? + def("add", + &Vector_addScalar, + "number"_a); + + def("__iadd__", + [](Vector self, double number) { Vector_addScalar(self, number); return self; }, + "number"_a, py::is_operator()); + + def("__add__", + [](Vector self, double number) { auto result = Data_copy(self); Vector_addScalar(result.get(), number); return result; }, + "number"_a, py::is_operator()); + + def("__radd__", + [](Vector self, double number) { auto result = Data_copy(self); Vector_addScalar(result.get(), number); return result; }, + "number"_a, py::is_operator()); + + def("subtract", + [](Vector self, double number) { Vector_addScalar(self, -number); }, + "number"_a); - PRAAT_ENUM_BINDING(ValueInterpolation) - { - value("NEAREST", kVector_valueInterpolation::NEAREST); - value("LINEAR", kVector_valueInterpolation::LINEAR); - value("CUBIC", kVector_valueInterpolation::CUBIC); - value("SINC70", kVector_valueInterpolation::SINC70); - value("SINC700", kVector_valueInterpolation::SINC700); - - make_implicitly_convertible_from_string(*this); - } - - PRAAT_ENUM_BINDING(PeakInterpolation) - { - value("NONE", kVector_peakInterpolation::NONE); - value("PARABOLIC", kVector_peakInterpolation::PARABOLIC); - value("CUBIC", kVector_peakInterpolation::CUBIC); - value("SINC70", kVector_peakInterpolation::SINC70); - value("SINC700", kVector_peakInterpolation::SINC700); - - make_implicitly_convertible_from_string(*this); - } - - PRAAT_CLASS_BINDING(Vector) - { - using signature_cast_placeholder::_; - - // TODO Something to get rid of duplicate functions with different names? - def("add", - &Vector_addScalar, - "number"_a); - - def( - "__iadd__", - [](Vector self, double number) { Vector_addScalar(self, number); return self; }, - "number"_a, py::is_operator()); - - def( - "__add__", - [](Vector self, double number) { auto result = Data_copy(self); Vector_addScalar(result.get(), number); return result; }, - "number"_a, py::is_operator()); - - def( - "__radd__", - [](Vector self, double number) { auto result = Data_copy(self); Vector_addScalar(result.get(), number); return result; }, - "number"_a, py::is_operator()); - - def( - "subtract", - [](Vector self, double number) { Vector_addScalar(self, -number); }, - "number"_a); - - def( - "__isub__", - [](Vector self, double number) { Vector_addScalar(self, -number); return self; }, - "number"_a, py::is_operator()); - - def( - "__sub__", - [](Vector self, double number) { auto result = Data_copy(self); Vector_addScalar(result.get(), -number); return result; }, - "number"_a, py::is_operator()); - - def("subtract_mean", - &Vector_subtractMean); - - def("multiply", - &Vector_multiplyByScalar, - "factor"_a); - - def( - "__imul__", - [](Vector self, double factor) { Vector_multiplyByScalar(self, factor); return self; }, - "factor"_a, py::is_operator()); - - def( - "__mul__", - [](Vector self, double factor) { auto result = Data_copy(self); Vector_multiplyByScalar(result.get(), factor); return result; }, - "factor"_a, py::is_operator()); - - def( - "__rmul__", - [](Vector self, double factor) { auto result = Data_copy(self); Vector_multiplyByScalar(result.get(), factor); return result; }, - "factor"_a, py::is_operator()); - - def( - "divide", // TODO Not zero? - [](Vector self, double factor) { Vector_multiplyByScalar(self, 1 / factor); }, - "factor"_a); - - def( - "__itruediv__", - [](Vector self, double factor) { Vector_multiplyByScalar(self, 1 / factor); return self; }, - "factor"_a, py::is_operator()); - - def( - "__truediv__", - [](Vector self, double factor) { auto result = Data_copy(self); Vector_multiplyByScalar(result.get(), 1 / factor); return result; }, - "factor"_a, py::is_operator()); + def("__isub__", + [](Vector self, double number) { Vector_addScalar(self, -number); return self; }, + "number"_a, py::is_operator()); + + def("__sub__", + [](Vector self, double number) { auto result = Data_copy(self); Vector_addScalar(result.get(), -number); return result; }, + "number"_a, py::is_operator()); + + def("subtract_mean", + &Vector_subtractMean); + + def("multiply", + &Vector_multiplyByScalar, + "factor"_a); + + def("__imul__", + [](Vector self, double factor) { Vector_multiplyByScalar(self, factor); return self; }, + "factor"_a, py::is_operator()); + + def("__mul__", + [](Vector self, double factor) { auto result = Data_copy(self); Vector_multiplyByScalar(result.get(), factor); return result; }, + "factor"_a, py::is_operator()); + + def("__rmul__", + [](Vector self, double factor) { auto result = Data_copy(self); Vector_multiplyByScalar(result.get(), factor); return result; }, + "factor"_a, py::is_operator()); + + def("divide", // TODO Not zero? + [](Vector self, double factor) { Vector_multiplyByScalar(self, 1 / factor); }, + "factor"_a); + + def("__itruediv__", + [](Vector self, double factor) { Vector_multiplyByScalar(self, 1 / factor); return self; }, + "factor"_a, py::is_operator()); + + def("__truediv__", + [](Vector self, double factor) { auto result = Data_copy(self); Vector_multiplyByScalar(result.get(), 1 / factor); return result; }, + "factor"_a, py::is_operator()); def("scale", args_cast<_, Positive<_>>(Vector_scale), "scale"_a); - def("scale_peak", - args_cast<_, Positive<_>>(Vector_scale), - "new_peak"_a = 0.99); + def("scale_peak", + args_cast<_, Positive<_>>(Vector_scale), + "new_peak"_a = 0.99); - def( - "get_value", // TODO Default for interpolation? Different for Sound (SINC70), Harmonicity/Intensity/Formants (CUBIC) and Ltas (LINEAR); take praat_TimeFunction.h into account - [](Vector self, double x, std::optional channel, kVector_valueInterpolation interpolation) { return Vector_getValueAtX(self, x, channel.value_or(Vector_CHANNEL_AVERAGE), interpolation); }, - "x"_a, "channel"_a = std::nullopt, "interpolation"_a = kVector_valueInterpolation::CUBIC); - } + def("get_value", // TODO Default for interpolation? Different for Sound (SINC70), Harmonicity/Intensity/Formants (CUBIC) and Ltas (LINEAR); take praat_TimeFunction.h into account + [](Vector self, double x, std::optional channel, kVector_valueInterpolation interpolation) { return Vector_getValueAtX (self, x, channel.value_or(Vector_CHANNEL_AVERAGE), interpolation); }, + "x"_a, "channel"_a = std::nullopt, "interpolation"_a = kVector_valueInterpolation::CUBIC); +} } // namespace parselmouth