diff --git a/Device/Histo/HistogramUtils.cpp b/Device/Histo/HistogramUtils.cpp index 642ae4418ee50765a382d31e75d454ddf4f8bd2b..6a9f0610f9d939ed15c0dc125d518f52a674d871 100644 --- a/Device/Histo/HistogramUtils.cpp +++ b/Device/Histo/HistogramUtils.cpp @@ -16,6 +16,7 @@ #include "Base/Axis/Bin.h" #include "Base/Math/Numeric.h" #include "Device/Data/DataUtils.h" +#include "Device/Data/Powerfield.h" #include "Device/Histo/Histogram2D.h" #include "Device/Histo/IOFactory.h" #include "Device/Histo/SimulationResult.h" @@ -79,12 +80,12 @@ double DataUtils::Histo::getRelativeDifference(const IHistogram& dat, const IHis } //! Returns true is relative difference is below threshold; prints informative output -bool DataUtils::Histo::checkRelativeDifference(const Powerfield<double>& dat, - const Powerfield<double>& ref, +bool DataUtils::Histo::checkRelativeDifference(const std::vector<double>& dat, + const std::vector<double>& ref, const double threshold) { - const std::unique_ptr<const IHistogram> histo(IHistogram::createHistogram(dat)); - if (histo->getMinimum() == 0 && histo->getMaximum() == 0) { + if (*std::min_element(dat.begin(), dat.end()) == 0 && + *std::max_element(dat.begin(), dat.end()) == 0) { std::cerr << "FAILED: simulated data set is empty" << std::endl; return false; } @@ -116,7 +117,7 @@ bool DataUtils::Histo::agreesWithReference(const SimulationResult& dat, return false; } std::unique_ptr<Powerfield<double>> datDat(dat.data()); - return DataUtils::Histo::checkRelativeDifference(*datDat, *refDat, tol); + return DataUtils::Histo::checkRelativeDifference(datDat->cvector(), refDat->cvector(), tol); } bool DataUtils::Histo::filesAgree(const std::string& datFileName, const std::string& refFileName, @@ -148,5 +149,5 @@ bool DataUtils::Histo::filesAgree(const std::string& datFileName, const std::str } ASSERT(refDat); - return DataUtils::Histo::checkRelativeDifference(*datDat, *refDat, tol); + return DataUtils::Histo::checkRelativeDifference(datDat->cvector(), refDat->cvector(), tol); } diff --git a/Device/Histo/HistogramUtils.h b/Device/Histo/HistogramUtils.h index 64ad0a6aa9617707d6c4c2956e434c78c5c493c5..a94baadb364dc414f62d7d707fd9efcbc0d739dd 100644 --- a/Device/Histo/HistogramUtils.h +++ b/Device/Histo/HistogramUtils.h @@ -15,7 +15,6 @@ #ifndef BORNAGAIN_DEVICE_HISTO_HISTOGRAMUTILS_H #define BORNAGAIN_DEVICE_HISTO_HISTOGRAMUTILS_H -#include "Device/Data/Powerfield.h" #include <string> #include <vector> @@ -40,7 +39,7 @@ double RelativeDifference(const SimulationResult& dat, const SimulationResult& r double getRelativeDifference(const IHistogram& dat, const IHistogram& ref); //! Returns true is relative difference is below threshold; prints informative output -bool checkRelativeDifference(const Powerfield<double>& dat, const Powerfield<double>& ref, +bool checkRelativeDifference(const std::vector<double>& dat, const std::vector<double>& ref, double threshold); //! Returns true if SimulatioResult agrees with data from reference file diff --git a/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp b/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp index ec0d721bba0a8cd17c0ed376a59f26a09a168809..cfba572daef1bdc6469252eee2122bf6616b2934 100644 --- a/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp +++ b/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp @@ -14,6 +14,8 @@ #include "BATesting.h" #include "Base/Util/FileSystemUtils.h" +#include "Base/Util/Assert.h" +#include "Device/Data/Powerfield.h" #include "Device/Histo/HistogramUtils.h" #include "Device/Histo/IOFactory.h" #include <iostream> @@ -45,5 +47,5 @@ int compareTwoReferences(const std::string& name0, const std::string& name1, con std::unique_ptr<Powerfield<double>> data0 = load(name0); std::unique_ptr<Powerfield<double>> data1 = load(name1); - return DataUtils::Histo::checkRelativeDifference(*data0, *data1, limit); + return DataUtils::Histo::checkRelativeDifference(data0->cvector(), data1->cvector(), limit); } diff --git a/Tests/Functional/Core/SuitePersist/Check.cpp b/Tests/Functional/Core/SuitePersist/Check.cpp index 6a36d3f2d9e9619e8a0ca5143476387a9c02cbfa..c93b78bd58f2a8c5b816999f7624f972c0f60a36 100644 --- a/Tests/Functional/Core/SuitePersist/Check.cpp +++ b/Tests/Functional/Core/SuitePersist/Check.cpp @@ -14,7 +14,9 @@ #include "BABuild.h" #include "BATesting.h" +#include "Base/Util/Assert.h" #include "Base/Util/FileSystemUtils.h" +#include "Device/Data/Powerfield.h" #include "Device/Histo/HistogramUtils.h" #include "Device/Histo/IOFactory.h" #include "Device/Histo/SimulationResult.h" @@ -44,7 +46,8 @@ bool checkSimulation(const std::string& name, ISimulation& direct_simulation, co // Compare with reference if available. if (reference) { std::cout << "- check diff" << std::endl; - if (DataUtils::Histo::checkRelativeDifference(*result_data, *reference, limit)) { + if (DataUtils::Histo::checkRelativeDifference( + result_data->cvector(), reference->cvector(), limit)) { std::cout << "- success" << std::endl; return true; // regular exit } diff --git a/Tests/Functional/GUI/Check.cpp b/Tests/Functional/GUI/Check.cpp index d626a0b62ae1d9ceeba2f79742d83ea1c78c4889..5841e01784e6cfac49938d6723cd90ebc95a4e34 100644 --- a/Tests/Functional/GUI/Check.cpp +++ b/Tests/Functional/GUI/Check.cpp @@ -15,6 +15,7 @@ #include "BABuild.h" #include "BATesting.h" #include "Base/Util/FileSystemUtils.h" +#include "Device/Data/Powerfield.h" #include "Device/Histo/HistogramUtils.h" #include "Device/Histo/IOFactory.h" #include "Device/Histo/SimulationResult.h" @@ -57,7 +58,8 @@ bool checkSimulation(const std::string& name, ISimulation& sim, const double lim const std::unique_ptr<Powerfield<double>> ref_data = sim.simulate().data(); - bool ok = DataUtils::Histo::checkRelativeDifference(*data2, *ref_data, limit); + bool ok = DataUtils::Histo::checkRelativeDifference( + data2->cvector(), ref_data->cvector(), limit); if (ok) return true; diff --git a/Tests/Functional/Py/Suite/Check.cpp b/Tests/Functional/Py/Suite/Check.cpp index 54a548682ab812e285b0497b460fe12137a6a23a..e8cdb9a15a7e8c4d48e75bd70a582d2728502591 100644 --- a/Tests/Functional/Py/Suite/Check.cpp +++ b/Tests/Functional/Py/Suite/Check.cpp @@ -15,6 +15,7 @@ #include "BABuild.h" #include "BATesting.h" #include "Base/Util/FileSystemUtils.h" +#include "Device/Data/Powerfield.h" #include "Device/Histo/HistogramUtils.h" #include "Device/Histo/IOFactory.h" #include "Device/Histo/SimulationResult.h" @@ -25,8 +26,7 @@ namespace { -std::unique_ptr<Powerfield<double>> domainData(const std::string& test_name, - const ISimulation& direct_simulation) +std::vector<double> domainData(const std::string& test_name, const ISimulation& direct_simulation) { const std::string output_name = BaseUtils::Filesystem::jointPath(BATesting::TestOutDir_AdHoc(), test_name); @@ -61,7 +61,7 @@ std::unique_ptr<Powerfield<double>> domainData(const std::string& test_name, auto result = std::unique_ptr<Powerfield<double>>(IOFactory::readPowerfield(output_path)); if (!result) throw std::runtime_error("Could not read back simulation output from file " + output_path); - return result; + return result->cvector(); } } // namespace @@ -72,10 +72,10 @@ bool checkSimulation(const std::string& name, ISimulation& direct_simulation, co { std::cout << "PySuite test: checkSimulation(" << name << ")" << std::endl; - const std::unique_ptr<Powerfield<double>> domain_data = domainData(name, direct_simulation); + const std::vector<double> domain_data = domainData(name, direct_simulation); std::cout << "- got domain data" << std::endl; - const std::unique_ptr<Powerfield<double>> ref_data = direct_simulation.simulate().data(); + const std::vector<double> ref_data = direct_simulation.simulate().data()->cvector(); std::cout << "- ran simulation" << std::endl; - return DataUtils::Histo::checkRelativeDifference(*domain_data, *ref_data, limit); + return DataUtils::Histo::checkRelativeDifference(domain_data, ref_data, limit); } diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index c4400f2d5c510142dd09530791f92962b1499f5b..c7813ea21a1de6039f2c97f4ca098e5c0abc7e1c 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -2445,7 +2445,7 @@ Returns sum of relative differences between each pair of elements: (a, b) -> 2*a %feature("docstring") DataUtils::Histo::getRelativeDifference "double DataUtils::Histo::getRelativeDifference(const IHistogram &dat, const IHistogram &ref) "; -%feature("docstring") DataUtils::Histo::checkRelativeDifference "bool DataUtils::Histo::checkRelativeDifference(const Powerfield< double > &dat, const Powerfield< double > &ref, double threshold) +%feature("docstring") DataUtils::Histo::checkRelativeDifference "bool DataUtils::Histo::checkRelativeDifference(const std::vector< double > &dat, const std::vector< double > &ref, double threshold) Returns true is relative difference is below threshold; prints informative output. "; diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 8bac92b51fc27c9b358e5e8afdcea31c293beba0..b78af6ee755cfcbaa01c4f15e719b64a4d220b56 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -4143,8 +4143,8 @@ def getRelativeDifference(dat, ref): def checkRelativeDifference(dat, ref, threshold): r""" - checkRelativeDifference(IntensityData dat, IntensityData ref, double threshold) -> bool - bool DataUtils::Histo::checkRelativeDifference(const Powerfield< double > &dat, const Powerfield< double > &ref, double threshold) + checkRelativeDifference(vdouble1d_t dat, vdouble1d_t ref, double threshold) -> bool + bool DataUtils::Histo::checkRelativeDifference(const std::vector< double > &dat, const std::vector< double > &ref, double threshold) Returns true is relative difference is below threshold; prints informative output. diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index ea3e265a2f18d5062b5bfdf7d83ce72cce11e0d7..a9100b22c608866e06be8b8cd73cb7db3f8e29d4 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -35777,44 +35777,52 @@ fail: SWIGINTERN PyObject *_wrap_checkRelativeDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; - Powerfield< double > *arg1 = 0 ; - Powerfield< double > *arg2 = 0 ; + std::vector< double,std::allocator< double > > *arg1 = 0 ; + std::vector< double,std::allocator< double > > *arg2 = 0 ; double arg3 ; - void *argp1 = 0 ; - int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; + int res1 = SWIG_OLDOBJ ; + int res2 = SWIG_OLDOBJ ; double val3 ; int ecode3 = 0 ; PyObject *swig_obj[3] ; bool result; if (!SWIG_Python_UnpackTuple(args, "checkRelativeDifference", 3, 3, swig_obj)) SWIG_fail; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_PowerfieldT_double_t, 0 | 0); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "Powerfield< double > const &""'"); - } - if (!argp1) { - SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "Powerfield< double > const &""'"); - } - arg1 = reinterpret_cast< Powerfield< double > * >(argp1); - res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_PowerfieldT_double_t, 0 | 0); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "Powerfield< double > const &""'"); + { + std::vector< double,std::allocator< double > > *ptr = (std::vector< double,std::allocator< double > > *)0; + res1 = swig::asptr(swig_obj[0], &ptr); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "std::vector< double,std::allocator< double > > const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "std::vector< double,std::allocator< double > > const &""'"); + } + arg1 = ptr; } - if (!argp2) { - SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "Powerfield< double > const &""'"); + { + std::vector< double,std::allocator< double > > *ptr = (std::vector< double,std::allocator< double > > *)0; + res2 = swig::asptr(swig_obj[1], &ptr); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "std::vector< double,std::allocator< double > > const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "std::vector< double,std::allocator< double > > const &""'"); + } + arg2 = ptr; } - arg2 = reinterpret_cast< Powerfield< double > * >(argp2); ecode3 = SWIG_AsVal_double(swig_obj[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "checkRelativeDifference" "', argument " "3"" of type '" "double""'"); } arg3 = static_cast< double >(val3); - result = (bool)DataUtils::Histo::checkRelativeDifference((Powerfield< double > const &)*arg1,(Powerfield< double > const &)*arg2,arg3); + result = (bool)DataUtils::Histo::checkRelativeDifference((std::vector< double,std::allocator< double > > const &)*arg1,(std::vector< double,std::allocator< double > > const &)*arg2,arg3); resultobj = SWIG_From_bool(static_cast< bool >(result)); + if (SWIG_IsNewObj(res1)) delete arg1; + if (SWIG_IsNewObj(res2)) delete arg2; return resultobj; fail: + if (SWIG_IsNewObj(res1)) delete arg1; + if (SWIG_IsNewObj(res2)) delete arg2; return NULL; } @@ -41727,8 +41735,8 @@ static PyMethodDef SwigMethods[] = { "\n" ""}, { "checkRelativeDifference", _wrap_checkRelativeDifference, METH_VARARGS, "\n" - "checkRelativeDifference(IntensityData dat, IntensityData ref, double threshold) -> bool\n" - "bool DataUtils::Histo::checkRelativeDifference(const Powerfield< double > &dat, const Powerfield< double > &ref, double threshold)\n" + "checkRelativeDifference(vdouble1d_t dat, vdouble1d_t ref, double threshold) -> bool\n" + "bool DataUtils::Histo::checkRelativeDifference(const std::vector< double > &dat, const std::vector< double > &ref, double threshold)\n" "\n" "Returns true is relative difference is below threshold; prints informative output. \n" "\n"