From 44a5dab193b8e30af344828bbadfd2d4e16e3d0f Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Mon, 10 May 2021 15:20:26 +0200 Subject: [PATCH] rectify python generation for FormFactorSphereLogNormalRadius --- .../FormFactorSphereLogNormalRadius.cpp | 17 +++++++++++++++++ .../FormFactorSphereLogNormalRadius.h | 4 ++++ .../Core/Core/PythonFormattingTest.cpp | 7 ------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Sample/SoftParticle/FormFactorSphereLogNormalRadius.cpp b/Sample/SoftParticle/FormFactorSphereLogNormalRadius.cpp index 60f01e92dc3..a7be588d83e 100644 --- a/Sample/SoftParticle/FormFactorSphereLogNormalRadius.cpp +++ b/Sample/SoftParticle/FormFactorSphereLogNormalRadius.cpp @@ -13,6 +13,7 @@ // ************************************************************************************************ #include "Sample/SoftParticle/FormFactorSphereLogNormalRadius.h" +#include "Base/Py/PyFmt.h" #include "Param/Distrib/Distributions.h" #include "Param/Varia/ParameterSample.h" #include "Sample/LibFF/SomeFormFactors.h" @@ -60,6 +61,22 @@ complex_t FormFactorSphereLogNormalRadius::evaluate_for_q(cvector_t q) const return result; } +std::string FormFactorSphereLogNormalRadius::pythonConstructor() const +{ + const std::string ctorName = m_nodeMeta.className; + + std::vector<std::pair<std::variant<double, int>, std::string>> arguments; + + for (size_t i = 0; i < m_nodeMeta.paraMeta.size(); i++) + arguments.push_back({m_P[i], m_nodeMeta.paraMeta[i].unit}); + + // m_n_samples is not part of the meta data (impossible due to size_t vs. double...). + // Therefore it has to be added separately + arguments.push_back({(int)m_n_samples, ""}); + + return ctorName + "(" + pyfmt::printArguments(arguments) + ")"; +} + void FormFactorSphereLogNormalRadius::onChange() { m_shape3D = std::make_unique<TruncatedEllipsoid>(m_mean, m_mean, m_mean, 2.0 * m_mean, 0.0); diff --git a/Sample/SoftParticle/FormFactorSphereLogNormalRadius.h b/Sample/SoftParticle/FormFactorSphereLogNormalRadius.h index 02e8c3dc056..5768662239c 100644 --- a/Sample/SoftParticle/FormFactorSphereLogNormalRadius.h +++ b/Sample/SoftParticle/FormFactorSphereLogNormalRadius.h @@ -34,6 +34,10 @@ public: complex_t evaluate_for_q(cvector_t q) const override; +#ifndef SWIG + virtual std::string pythonConstructor() const; +#endif + protected: void onChange() override; diff --git a/Tests/UnitTests/Core/Core/PythonFormattingTest.cpp b/Tests/UnitTests/Core/Core/PythonFormattingTest.cpp index 1daad6c1cdb..40bc70305fa 100644 --- a/Tests/UnitTests/Core/Core/PythonFormattingTest.cpp +++ b/Tests/UnitTests/Core/Core/PythonFormattingTest.cpp @@ -286,14 +286,7 @@ TEST_F(PythonFormattingTest, printFormFactors) EXPECT_EQ(FormFactorBarLorentz(100, 20, 4).pythonConstructor(), "FormFactorBarLorentz(100*nm, 20*nm, 4*nm)"); -} -TEST_F(PythonFormattingTest, DISABLED_FormFactorSphereLogNormalRadius) -{ - // #baPool ++ this fails already for non refactored code: 3rd parameter "sample" is not - // contained in the original py-ctor generation. The generated py code expects all three - // parameters (see libBornAgain.sample.py)! - // => decide what to do and enable the test EXPECT_EQ(FormFactorSphereLogNormalRadius(100, 20, 10).pythonConstructor(), "FormFactorSphereLogNormalRadius(100*nm, 20.0, 10)"); } \ No newline at end of file -- GitLab