diff --git a/Device/Data/DataUtils.cpp b/Device/Data/DataUtils.cpp index 9bcd7511e55f7c509b25bb4cb7e19ed8c101b984..9b67b58d4b0fa3adc1a96fe1de345081a8ef7cf7 100644 --- a/Device/Data/DataUtils.cpp +++ b/Device/Data/DataUtils.cpp @@ -30,8 +30,8 @@ std::vector<std::vector<double>> FT2DArray(const std::vector<std::vector<double> } // namespace //! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). -double DataUtils::getRelativeDifference(const OutputData<double>& dat, - const OutputData<double>& ref) { +double DataUtils::relativeDataDifference(const OutputData<double>& dat, + const OutputData<double>& ref) { if (!dat.hasSameDimensions(ref)) throw std::runtime_error("OutputData dimension differs from reference"); @@ -47,7 +47,7 @@ double DataUtils::getRelativeDifference(const OutputData<double>& dat, //! Returns true is relative difference is below threshold; prints informative output bool DataUtils::checkRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref, const double threshold) { - const double diff = getRelativeDifference(dat, ref); + const double diff = relativeDataDifference(dat, ref); if (diff > threshold) { std::cerr << "FAILED: relative deviation of dat from ref is " << diff << ", above given threshold " << threshold << "\n"; diff --git a/Device/Data/DataUtils.h b/Device/Data/DataUtils.h index 3b05ea509d420f41de157a8a1018a23b4168d27a..efdd2c008fdf163bb94a57072670e18c8c5b201c 100644 --- a/Device/Data/DataUtils.h +++ b/Device/Data/DataUtils.h @@ -20,6 +20,9 @@ namespace DataUtils { +//! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). +double relativeDataDifference(const OutputData<double>& dat, const OutputData<double>& ref); + //! Returns true is relative difference is below threshold; prints informative output bool checkRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref, const double threshold); @@ -41,9 +44,6 @@ std::vector<std::vector<double>> create2DArrayfromOutputData(const OutputData<do #ifndef SWIG -//! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). -double getRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref); - std::unique_ptr<OutputData<double>> createRelativeDifferenceData(const OutputData<double>& data, const OutputData<double>& reference); diff --git a/Device/Histo/HistoUtils.cpp b/Device/Histo/HistoUtils.cpp index 30a4428f68449d254733c20bc508bd74133bd348..e2ed7f7e71d8d4dde7d0454aa1b79a17db8c4cbe 100644 --- a/Device/Histo/HistoUtils.cpp +++ b/Device/Histo/HistoUtils.cpp @@ -67,7 +67,7 @@ double HistoUtils::RelativeDifference(const SimulationResult& dat, const Simulat } double HistoUtils::getRelativeDifference(const IHistogram& dat, const IHistogram& ref) { - return DataUtils::getRelativeDifference( + return DataUtils::relativeDataDifference( *std::unique_ptr<OutputData<double>>(dat.getData().meanValues()), *std::unique_ptr<OutputData<double>>(ref.getData().meanValues())); } diff --git a/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp b/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp index 1b21254f9f722fe7a9acce4b4a0b1eac6ec6170c..46940579d4d0286baf5788af6cab1c4603fde30d 100644 --- a/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp +++ b/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp @@ -49,7 +49,7 @@ TEST_F(BatchSimulation, BatchSimulation) { *result += *batchResult; } - double diff = DataUtils::getRelativeDifference(*result, *reference); + double diff = DataUtils::relativeDataDifference(*result, *reference); EXPECT_LE(diff, threshold); } diff --git a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp index ba89ef97adb1706eb577bc5b6d1c5123b43f8dd8..580f3f30a3e75b8bba8e5bec139ea6905f18fd8d 100644 --- a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp +++ b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp @@ -33,7 +33,7 @@ std::unique_ptr<OutputData<double>> createTestData() { bool test_io(const OutputData<double>* data, const std::string& file_name) { IntensityDataIOFactory::writeOutputData(*data, file_name); std::unique_ptr<OutputData<double>> loaded(IntensityDataIOFactory::readOutputData(file_name)); - return DataUtils::getRelativeDifference(*data, *loaded) <= 1e-06; + return DataUtils::relativeDataDifference(*data, *loaded) <= 1e-06; } } // namespace diff --git a/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp b/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp index e99b636fd635ded8e95ba206adf36722497a3d76..33a1175367cd80d97b9e36d3fc26cc3335adac7d 100644 --- a/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp +++ b/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp @@ -62,7 +62,7 @@ bool test_fft(const std::string& input_image_name, const std::string& reference_ std::cout << "comparing" << std::endl; bool success(false); if (reference_fft) - success = DataUtils::getRelativeDifference(*fft, *reference_fft) <= threshold; + success = DataUtils::relativeDataDifference(*fft, *reference_fft) <= threshold; if (!success) { FileSystemUtils::createDirectory(BATesting::TestOutDir_Core()); diff --git a/Tests/Functional/Python/PyPersistence/CMakeLists.txt b/Tests/Functional/Python/PyPersistence/CMakeLists.txt index 00a6defb321078447d52915d3704023abf0c6e5e..4df473168a41475befd18961dca7d96d82c8835f 100644 --- a/Tests/Functional/Python/PyPersistence/CMakeLists.txt +++ b/Tests/Functional/Python/PyPersistence/CMakeLists.txt @@ -22,50 +22,43 @@ function(test_example example tolerance) add_test(${test_name} ${Python3_EXECUTABLE} -B ${example_mod}) endfunction() -test_example(sim01_Particles/CylindersAndPrisms 2e-10) -test_example(sim01_Particles/CylindersInBA 2e-10) -test_example(sim01_Particles/CylindersInDWBA 2e-10) -test_example(sim01_Particles/CylindersWithSizeDistribution 2e-10) -test_example(sim01_Particles/RotatedPyramids 2e-10) -test_example(sim01_Particles/TwoTypesOfCylindersWithSizeDistribution 2e-10) +test_example(scatter2d/ApproximationDA 2e-10) +test_example(scatter2d/ApproximationLMA 2e-10) +test_example(scatter2d/ApproximationSSCA 2e-10) +test_example(scatter2d/BeamDivergence 2e-10) +test_example(scatter2d/BuriedParticles 2e-10) +test_example(scatter2d/ConstantBackground 2e-10) +test_example(scatter2d/CoreShellNanoparticles 2e-10) +test_example(scatter2d/CorrelatedRoughness 2e-10) +test_example(scatter2d/CosineRipplesAtRectLattice 2e-10) +test_example(scatter2d/CylindersAndPrisms 2e-10) +test_example(scatter2d/CylindersInAverageLayer 2e-10) +test_example(scatter2d/CylindersInBA 2e-10) +test_example(scatter2d/CylindersInDWBA 2e-10) +test_example(scatter2d/CylindersWithSizeDistribution 2e-10) +test_example(scatter2d/DetectorResolutionFunction 2e-10) +test_example(scatter2d/HalfSpheresInAverageTopLayer 2e-10) +test_example(scatter2d/HexagonalLatticesWithBasis 2e-10) +test_example(scatter2d/Interference1DRadialParaCrystal 2e-10) +test_example(scatter2d/Interference2DCenteredSquareLattice 2e-10) +test_example(scatter2d/Interference2DLatticeSumOfRotated 2e-10) +test_example(scatter2d/Interference2DParaCrystal 2e-10) +test_example(scatter2d/Interference2DRotatedSquareLattice 2e-10) +test_example(scatter2d/Interference2DSquareLattice 2e-10) +test_example(scatter2d/MagneticSpheres 2e-10) +test_example(scatter2d/RectangularGrating 0.5) +test_example(scatter2d/RotatedPyramids 2e-10) +test_example(scatter2d/SpheresAtHexLattice 2e-10) +test_example(scatter2d/TriangularRipple 2e-10) +test_example(scatter2d/TwoTypesOfCylindersWithSizeDistribution 2e-10) -test_example(sim02_Complexes/CoreShellNanoparticles 2e-10) -test_example(sim02_Complexes/CustomFormFactor 2e-10) -test_example(sim02_Complexes/HexagonalLatticesWithBasis 2e-10) - -test_example(sim03_Structures/ApproximationDA 2e-10) -test_example(sim03_Structures/ApproximationLMA 2e-10) -test_example(sim03_Structures/ApproximationSSCA 2e-10) -test_example(sim03_Structures/CosineRipplesAtRectLattice 2e-10) -test_example(sim03_Structures/Interference1DLattice 1.5) -test_example(sim03_Structures/Interference1DRadialParaCrystal 2e-10) -test_example(sim03_Structures/Interference2DCenteredSquareLattice 2e-10) -test_example(sim03_Structures/Interference2DParaCrystal 2e-10) -test_example(sim03_Structures/Interference2DRotatedSquareLattice 2e-10) -test_example(sim03_Structures/Interference2DSquareLattice 2e-10) -test_example(sim03_Structures/Interference2DLatticeSumOfRotated 2e-10) -test_example(sim03_Structures/RectangularGrating 0.5) -test_example(sim03_Structures/SpheresAtHexLattice 2e-10) -test_example(sim03_Structures/TriangularRipple 2e-10) - -test_example(sim04_Multilayers/BuriedParticles 2e-10) -test_example(sim04_Multilayers/CorrelatedRoughness 2e-10) -test_example(sim04_Multilayers/CylindersInAverageLayer 2e-10) -test_example(sim04_Multilayers/HalfSpheresInAverageTopLayer 2e-10) - -test_example(sim05_Magnetism/MagneticSpheres 2e-10) - -test_example(sim11_Device/BeamDivergence 2e-10) -test_example(sim11_Device/DetectorResolutionFunction 2e-10) -test_example(sim11_Device/OffSpecularSimulation 2e-10) -test_example(sim11_Device/ConstantBackground 2e-10) - -test_example(sim21_Reflectometry/BasicSpecularSimulation 2e-10) -test_example(sim21_Reflectometry/BeamAngularDivergence 2e-10) -test_example(sim21_Reflectometry/BeamFullDivergence 2e-10) -test_example(sim21_Reflectometry/TimeOfFlightReflectometry 2e-10) -test_example(sim21_Reflectometry/TOFRWithResolution 2e-10) - -test_example(special40_DepthProbe/DepthProbe 2e-10) - -test_example(sim31_Parameterization/SimulationParameters 2e-10) +test_example(varia/BasicSpecularSimulation 2e-10) +test_example(varia/BeamAngularDivergence 2e-10) +test_example(varia/BeamFullDivergence 2e-10) +test_example(varia/CustomFormFactor 2e-10) +test_example(varia/DepthProbe 2e-10) +test_example(varia/Interference1DLattice 1.5) +test_example(varia/OffSpecularSimulation 2e-10) +test_example(varia/SimulationParameters 2e-10) +test_example(varia/TOFRWithResolution 2e-10) +test_example(varia/TimeOfFlightReflectometry 2e-10) diff --git a/Tests/Functional/Python/PyPersistence/PyPersistence.py.in b/Tests/Functional/Python/PyPersistence/PyPersistence.py.in index 51a877e200299274c4656a5650f3d97824d0c592..a2b1d365be5aa0ce6221e90682308ed65e5adfa3 100644 --- a/Tests/Functional/Python/PyPersistence/PyPersistence.py.in +++ b/Tests/Functional/Python/PyPersistence/PyPersistence.py.in @@ -149,7 +149,7 @@ def check_result(result, example_name): print("Loading reference file '{}'".format(reffile)) reference = ba.IntensityDataIOFactory.readOutputData(reffile) - diff = ba.getRelativeDifference(ba.importArrayToOutputData(result.array()), reference) + diff = ba.relativeDataDifference(ba.importArrayToOutputData(result.array()), reference) if diff > TOLERANCE: print("Failure - Difference {0} is above tolerance level {1}".format(diff, TOLERANCE)) diff --git a/Tests/UnitTests/GUI/Utils.cpp b/Tests/UnitTests/GUI/Utils.cpp index b61db960f8d35b596de9ff4d0612b16349fd353b..9b53cef3ec4573c6ad980f3df448b7201b8d714b 100644 --- a/Tests/UnitTests/GUI/Utils.cpp +++ b/Tests/UnitTests/GUI/Utils.cpp @@ -54,7 +54,7 @@ RealDataItem* GuiUnittestUtils::createRealData(const QString& name, SessionModel } bool GuiUnittestUtils::isTheSame(const OutputData<double>& data1, const OutputData<double>& data2) { - double diff = DataUtils::getRelativeDifference(data1, data2); + double diff = DataUtils::relativeDataDifference(data1, data2); return diff < 1e-10; } diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index c5ed4c48cb0f5cb62f3be6ba0b1421f8d90b14ef..00765ed9352f4dfa37a06ceda17c1b4cfe88751b 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -3093,6 +3093,11 @@ Parse double values from string to vector of double. // File: namespaceDataUtils.xml +%feature("docstring") DataUtils::relativeDataDifference "double DataUtils::relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref) + +Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). +"; + %feature("docstring") DataUtils::checkRelativeDifference "bool DataUtils::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold) Returns true is relative difference is below threshold; prints informative output. @@ -3123,11 +3128,6 @@ Transforms x,y coordinate from bin-fraction-coordinates to OutputData's axes co Creates a vector of vectors of double (2D Array) from OutputData. "; -%feature("docstring") DataUtils::getRelativeDifference "double DataUtils::getRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref) - -Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). -"; - %feature("docstring") DataUtils::createRelativeDifferenceData "std::unique_ptr< OutputData< double > > DataUtils::createRelativeDifferenceData(const OutputData< double > &data, const OutputData< double > &reference) "; diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 3ffa4ce078fcd59d1e3c5546e15c65537a19558f..2f65ed267755d538225fb7bf8cb23d13b85b9467 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -2616,6 +2616,16 @@ class IntensityData(object): _libBornAgainDevice.IntensityData_swigregister(IntensityData) +def relativeDataDifference(dat, ref): + r""" + relativeDataDifference(IntensityData dat, IntensityData ref) -> double + double DataUtils::relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref) + + Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). + + """ + return _libBornAgainDevice.relativeDataDifference(dat, ref) + def checkRelativeDifference(dat, ref, threshold): r""" checkRelativeDifference(IntensityData dat, IntensityData ref, double const threshold) -> bool diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index 6ecaa195c40d63008e1e421d8a7a9dae5afd27a2..39d3b01cb6da43d436bdd90a83f0c4e87de8a941 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -30489,6 +30489,42 @@ SWIGINTERN PyObject *IntensityData_swiginit(PyObject *SWIGUNUSEDPARM(self), PyOb return SWIG_Python_InitShadowInstance(args); } +SWIGINTERN PyObject *_wrap_relativeDataDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OutputData< double > *arg1 = 0 ; + OutputData< double > *arg2 = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject *swig_obj[2] ; + double result; + + if (!SWIG_Python_UnpackTuple(args, "relativeDataDifference", 2, 2, swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_OutputDataT_double_t, 0 | 0); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "relativeDataDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); + } + if (!argp1) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "relativeDataDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); + } + arg1 = reinterpret_cast< OutputData< double > * >(argp1); + res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_OutputDataT_double_t, 0 | 0); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "relativeDataDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); + } + if (!argp2) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "relativeDataDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); + } + arg2 = reinterpret_cast< OutputData< double > * >(argp2); + result = (double)DataUtils::relativeDataDifference((OutputData< double > const &)*arg1,(OutputData< double > const &)*arg2); + resultobj = SWIG_From_double(static_cast< double >(result)); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_checkRelativeDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; OutputData< double > *arg1 = 0 ; @@ -45683,6 +45719,13 @@ static PyMethodDef SwigMethods[] = { { "IntensityData___setitem__", _wrap_IntensityData___setitem__, METH_VARARGS, "IntensityData___setitem__(IntensityData self, unsigned int i, double value) -> double"}, { "IntensityData_swigregister", IntensityData_swigregister, METH_O, NULL}, { "IntensityData_swiginit", IntensityData_swiginit, METH_VARARGS, NULL}, + { "relativeDataDifference", _wrap_relativeDataDifference, METH_VARARGS, "\n" + "relativeDataDifference(IntensityData dat, IntensityData ref) -> double\n" + "double DataUtils::relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref)\n" + "\n" + "Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). \n" + "\n" + ""}, { "checkRelativeDifference", _wrap_checkRelativeDifference, METH_VARARGS, "\n" "checkRelativeDifference(IntensityData dat, IntensityData ref, double const threshold) -> bool\n" "bool DataUtils::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold)\n"