From b8f1849561a9f0f5281d0643d49d7b97060bcf06 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Thu, 27 Jun 2024 00:23:08 +0200 Subject: [PATCH] Remove Antares::Memory::Array (#2187) --- .../array/include/antares/array/matrix.h | 9 - .../array/include/antares/array/matrix.hxx | 25 --- .../memory/include/antares/memory/memory.h | 48 ----- .../memory/include/antares/memory/memory.hxx | 48 ----- .../solver/variable/storage/minmax-data.h | 44 ++--- .../antares/solver/variable/storage/minmax.h | 20 +- .../solver/variable/storage/minmax.hxx | 1 - src/solver/variable/storage/minmax-data.cpp | 179 ++++-------------- 8 files changed, 54 insertions(+), 320 deletions(-) diff --git a/src/libs/antares/array/include/antares/array/matrix.h b/src/libs/antares/array/include/antares/array/matrix.h index f1d65c5a43..48eb27dd6f 100644 --- a/src/libs/antares/array/include/antares/array/matrix.h +++ b/src/libs/antares/array/include/antares/array/matrix.h @@ -339,15 +339,6 @@ class Matrix template void pasteToColumn(uint x, const U* data); - /*! - ** \brief Copy values into a given column in the matrix - ** - ** \param x The column index (zero-based) - ** \param data The data to copy - */ - template - void pasteToColumn(uint x, const Antares::Memory::Array& data); - /*! ** \brief Set a entire column with a given value ** diff --git a/src/libs/antares/array/include/antares/array/matrix.hxx b/src/libs/antares/array/include/antares/array/matrix.hxx index 7fabacba02..78fef9186a 100644 --- a/src/libs/antares/array/include/antares/array/matrix.hxx +++ b/src/libs/antares/array/include/antares/array/matrix.hxx @@ -488,31 +488,6 @@ void Matrix::pasteToColumn(uint x, const U* data) markAsModified(); } -template -template -void Matrix::pasteToColumn(uint x, const Antares::Memory::Array& data) -{ - assert(x < width and "Invalid column index (bigger than `this->width`)"); - ColumnType& column = entry[x]; - - // if the two types are strictly equal, we can perform some major - // optimisations - if (Yuni::Static::Type::StrictlyEqual::Yes) - { - (void)::memcpy(column, data, sizeof(T) * height); - } - else - { - // ...otherwise we have to copy each item by hand in any cases - for (uint y = 0; y != height; ++y) - { - column[y] = (T)data[y]; - } - } - - markAsModified(); -} - template void Matrix::fillColumn(uint x, const T& value) { diff --git a/src/libs/antares/memory/include/antares/memory/memory.h b/src/libs/antares/memory/include/antares/memory/memory.h index 89eb4815f4..42515c5fce 100644 --- a/src/libs/antares/memory/include/antares/memory/memory.h +++ b/src/libs/antares/memory/include/antares/memory/memory.h @@ -33,52 +33,6 @@ namespace Antares class Memory final: public Yuni::Policy::ObjectLevelLockable { public: - template - class Array final - { - public: - //! \name Constructors - //@{ - /*! - ** \brief Default constructor - */ - Array() = default; - - /*! - ** \brief Constructor from null - */ - explicit Array(const Yuni::NullPtr&); - - /*! - ** \brief Constructor with an initial allocation size - */ - explicit Array(size_t size); - - //! Copy constructor (must be empty) - Array(const Array& copy); - - template - Array(const Array&); - - /*! - ** \brief Destructor - */ - ~Array(); - //@} - - /*! - ** \brief - */ - void allocate(size_t size); - - T& operator[](uint i); - const T& operator[](uint i) const; - - private: - T* pPointer = nullptr; - - }; // class Array - template struct Stored final { @@ -101,7 +55,6 @@ class Memory final: public Yuni::Policy::ObjectLevelLockable template static void Assign(uint count, U* array, const U& value); -public: template static void Allocate(T*& out, size_t size); @@ -117,7 +70,6 @@ class Memory final: public Yuni::Policy::ObjectLevelLockable template static void Release(T*& pointer); -public: //! \name Constructor & Destructor //@{ /*! diff --git a/src/libs/antares/memory/include/antares/memory/memory.hxx b/src/libs/antares/memory/include/antares/memory/memory.hxx index 1b575150a5..aeb99b413d 100644 --- a/src/libs/antares/memory/include/antares/memory/memory.hxx +++ b/src/libs/antares/memory/include/antares/memory/memory.hxx @@ -28,54 +28,6 @@ inline uint64_t Memory::processID() const return pProcessID; } -template -Memory::Array::Array(const Yuni::NullPtr&) -{ -} - -template -Memory::Array::Array(const Memory::Array&) -{ -} - -template -template -Memory::Array::Array(const Memory::Array&) -{ -} - -template -inline Memory::Array::Array(size_t size) -{ - allocate(size); -} - -template -inline Memory::Array::~Array() -{ - delete[] pPointer; - pPointer = nullptr; -} - -template -void Memory::Array::allocate(size_t size) -{ - delete[] pPointer; - pPointer = new T[size]; -} - -template -T& Memory::Array::operator[](uint i) -{ - return (T&)pPointer[i]; -} - -template -const T& Memory::Array::operator[](uint i) const -{ - return (const T&)pPointer[i]; -} - template inline void Memory::Release(T*& pointer) { diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h b/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h index c444ca73c9..156f53fec2 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax-data.h @@ -21,19 +21,11 @@ #ifndef __SOLVER_VARIABLE_STORAGE_MINMAX_DATA_H__ #define __SOLVER_VARIABLE_STORAGE_MINMAX_DATA_H__ -#include -#include +#include + #include "antares/solver/variable/storage/intermediate.h" -namespace Antares -{ -namespace Solver -{ -namespace Variable -{ -namespace R -{ -namespace AllYears +namespace Antares::Solver::Variable::R::AllYears { class MinMaxData { @@ -44,17 +36,8 @@ class MinMaxData uint32_t indice; }; -public: - //! \name Constructor & Destructor - //@{ - /*! - ** \brief Default constructor - */ - MinMaxData(); - //! Destructor - ~MinMaxData(); - - void initialize(); + MinMaxData() = default; + ~MinMaxData() = default; void resetInf(); void resetSup(); @@ -62,19 +45,14 @@ class MinMaxData void mergeInf(uint year, const IntermediateValues& rhs); void mergeSup(uint year, const IntermediateValues& rhs); -public: - Data annual; - Data monthly[maxMonths]; - Data weekly[maxWeeksInAYear]; - Data daily[maxDaysInAYear]; - Antares::Memory::Stored::Type hourly; + std::vector annual{1}; + std::vector monthly{maxMonths}; + std::vector weekly{maxWeeksInAYear}; + std::vector daily{maxDaysInAYear}; + std::vector hourly{maxHoursInAYear}; }; // class MinMaxData -} // namespace AllYears -} // namespace R -} // namespace Variable -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Variable::R::AllYears #endif // __SOLVER_VARIABLE_STORAGE_MINMAX_DATA_H__ diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax.h b/src/solver/variable/include/antares/solver/variable/storage/minmax.h index b9aaba7bc3..8e9603fa16 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax.h +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax.h @@ -84,20 +84,20 @@ struct MinMaxBase: public NextT { case Category::hourly: InternalExportIndices(report, - Memory::RawPointer(minmax.hourly), + Memory::RawPointer(minmax.hourly.data()), fileLevel); break; case Category::daily: - InternalExportIndices(report, minmax.daily, fileLevel); + InternalExportIndices(report, minmax.daily.data(), fileLevel); break; case Category::weekly: - InternalExportIndices(report, minmax.weekly, fileLevel); + InternalExportIndices(report, minmax.weekly.data(), fileLevel); break; case Category::monthly: - InternalExportIndices(report, minmax.monthly, fileLevel); + InternalExportIndices(report, minmax.monthly.data(), fileLevel); break; case Category::annual: - InternalExportIndices<1, VCardT>(report, &minmax.annual, fileLevel); + InternalExportIndices<1, VCardT>(report, minmax.annual.data(), fileLevel); break; } } @@ -107,19 +107,19 @@ struct MinMaxBase: public NextT { case Category::hourly: InternalExportValues(report, - Memory::RawPointer(minmax.hourly)); + Memory::RawPointer(minmax.hourly.data())); break; case Category::daily: - InternalExportValues(report, minmax.daily); + InternalExportValues(report, minmax.daily.data()); break; case Category::weekly: - InternalExportValues(report, minmax.weekly); + InternalExportValues(report, minmax.weekly.data()); break; case Category::monthly: - InternalExportValues(report, minmax.monthly); + InternalExportValues(report, minmax.monthly.data()); break; case Category::annual: - InternalExportValues<1, VCardT>(report, &minmax.annual); + InternalExportValues<1, VCardT>(report, minmax.annual.data()); break; } } diff --git a/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx b/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx index de94f1d571..741e56cbba 100644 --- a/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx +++ b/src/solver/variable/include/antares/solver/variable/storage/minmax.hxx @@ -36,7 +36,6 @@ namespace AllYears template inline void MinMaxBase::initializeFromStudy(Data::Study& study) { - minmax.initialize(); // Next NextType::initializeFromStudy(study); } diff --git a/src/solver/variable/storage/minmax-data.cpp b/src/solver/variable/storage/minmax-data.cpp index 7d6e3f0565..6d25480806 100644 --- a/src/solver/variable/storage/minmax-data.cpp +++ b/src/solver/variable/storage/minmax-data.cpp @@ -21,135 +21,40 @@ #include "antares/solver/variable/storage/minmax-data.h" -#include - -#include - #include "antares/solver/variable/storage/intermediate.h" -using namespace Yuni; - namespace Antares::Solver::Variable::R::AllYears { -namespace // anonymous -{ constexpr double eps = 1.e-7; -template -struct ArrayInitializer +static void initArray(bool opInferior, std::vector& array) { - static void Init(Antares::Memory::Array& array) - { - for (uint i = 0; i != Size; ++i) - { - MinMaxData::Data& data = array[i]; - data.value = DBL_MAX; // +inf - data.indice = (uint32_t)(-1); // invalid indice - } - } - - static void Init(MinMaxData::Data* array) + for (auto& data : array) { - for (uint i = 0; i != Size; ++i) - { - MinMaxData::Data& data = array[i]; - data.value = DBL_MAX; // +inf - data.indice = (uint32_t)(-1); // invalid indice - } + data.value = opInferior ? DBL_MAX : -DBL_MAX; // +inf or -inf + data.indice = (uint32_t)(-1); // invalid indice } +} -}; // class ArrayInitializer - -template -struct ArrayInitializer +static void mergeArray(bool opInferior, + unsigned year, + std::vector& results, + const double* values) { - static void Init(Antares::Memory::Array& array) - { - for (uint i = 0; i != Size; ++i) - { - // Contrary to what we could guess, DBL_MIN is not the smallest number - // you can hold in a double, but the smallest positive number you can - // hold in a double - MinMaxData::Data& data = array[i]; - data.value = -DBL_MAX; // -inf - data.indice = (uint32_t)(-1); // invalid indice - } - } - - static void Init(MinMaxData::Data* array) + for (unsigned i = 0; i != results.size(); ++i) { - for (uint i = 0; i != Size; ++i) - { - // Contrary to what we could guess, DBL_MIN is not the smallest number - // you can hold in a double, but the smallest positive number you can - // hold in a double - MinMaxData::Data& data = array[i]; - data.value = -DBL_MAX; // -inf - data.indice = (uint32_t)(-1); // invalid indice - } - } + MinMaxData::Data& data = results[i]; -}; // class ArrayInitializer - -template -struct MergeArray -{ - template - static void Do(const uint year, - Antares::Memory::Array& results, - const U& values) - { - for (uint i = 0; i != Size; ++i) + if (opInferior) { - MinMaxData::Data& data = results[i]; if (values[i] < data.value - eps) { data.value = values[i]; data.indice = year + 1; // The year is zero-based } } - } - - template - static void Do(const uint year, MinMaxData::Data* results, const U& values) - { - for (uint i = 0; i != Size; ++i) - { - if (values[i] < results[i].value - eps) - { - results[i].value = values[i]; - results[i].indice = year + 1; // The year is zero-based - } - } - } - -}; // class MergeArray - -template -struct MergeArray<0, Size> -{ - template - static void Do(const uint year, - Antares::Memory::Array& results, - const U& values) - { - for (uint i = 0; i != Size; ++i) - { - MinMaxData::Data& data = results[i]; - if (values[i] > data.value + eps) - { - data.value = values[i]; - data.indice = year + 1; // The year is zero-based - } - } - } - - template - static void Do(const uint year, MinMaxData::Data* results, const U& values) - { - for (uint i = 0; i != Size; ++i) + else { - MinMaxData::Data& data = results[i]; if (values[i] > data.value + eps) { data.value = values[i]; @@ -157,60 +62,42 @@ struct MergeArray<0, Size> } } } - -}; // class MergeArray - -} // anonymous namespace - -MinMaxData::MinMaxData(): - hourly(nullptr) -{ -} - -MinMaxData::~MinMaxData() -{ - Antares::Memory::Release(hourly); } void MinMaxData::resetInf() { - ArrayInitializer<1, true>::Init(&annual); - ArrayInitializer::Init(monthly); - ArrayInitializer::Init(weekly); - ArrayInitializer::Init(daily); - ArrayInitializer::Init(hourly); + initArray(true, annual); + initArray(true, monthly); + initArray(true, weekly); + initArray(true, daily); + initArray(true, hourly); } void MinMaxData::resetSup() { - ArrayInitializer<1, false>::Init(&annual); - ArrayInitializer::Init(monthly); - ArrayInitializer::Init(weekly); - ArrayInitializer::Init(daily); - ArrayInitializer::Init(hourly); -} - -void MinMaxData::initialize() -{ - Antares::Memory::Allocate(hourly, maxHoursInAYear); + initArray(false, annual); + initArray(false, monthly); + initArray(false, weekly); + initArray(false, daily); + initArray(false, hourly); } void MinMaxData::mergeInf(uint year, const IntermediateValues& rhs) { - MergeArray::Do(year, monthly, rhs.month); - MergeArray::Do(year, weekly, rhs.week); - MergeArray::Do(year, daily, rhs.day); - MergeArray::Do(year, hourly, rhs.hour); - MergeArray::Do(year, &annual, &rhs.year); + mergeArray(true, year, monthly, rhs.month); + mergeArray(true, year, weekly, rhs.week); + mergeArray(true, year, daily, rhs.day); + mergeArray(true, year, hourly, rhs.hour); + mergeArray(true, year, annual, &rhs.year); } void MinMaxData::mergeSup(uint year, const IntermediateValues& rhs) { - MergeArray::Do(year, monthly, rhs.month); - MergeArray::Do(year, weekly, rhs.week); - MergeArray::Do(year, daily, rhs.day); - MergeArray::Do(year, hourly, rhs.hour); - MergeArray::Do(year, &annual, &rhs.year); + mergeArray(false, year, monthly, rhs.month); + mergeArray(false, year, weekly, rhs.week); + mergeArray(false, year, daily, rhs.day); + mergeArray(false, year, hourly, rhs.hour); + mergeArray(false, year, annual, &rhs.year); } } // namespace Antares::Solver::Variable::R::AllYears