Skip to content

Commit

Permalink
correlation montlhy
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Jul 18, 2024
1 parent 67ba855 commit 4bdf895
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
33 changes: 11 additions & 22 deletions src/libs/antares/correlation/correlation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,13 @@ int InterAreaCorrelationSaveToFile(const Matrix<>* m, const AreaList* l, const c

Correlation::Correlation():
annual(nullptr),
monthly(nullptr),
pMode(modeNone)
{
}

Correlation::~Correlation()
{
delete annual;
delete[] monthly;
}

bool Correlation::loadFromFile(Study& study, const AnyString& filename, bool warnings)
Expand Down Expand Up @@ -406,7 +404,7 @@ void Correlation::internalSaveToINI(Study& study, IO::File::Stream& file) const
logs.error() << correlationName << ": the annual correlation coefficients are missing";
}

if (monthly)
if (!monthly.empty())
{
for (int month = 0; month < 12; month++)
{
Expand Down Expand Up @@ -441,7 +439,7 @@ bool Correlation::internalLoadFromINITry(Study& study, const IniFile& ini, bool

if (JIT::usedFromGUI or pMode == modeMonthly)
{
monthly = new Matrix<>[12];
monthly.resize(12);
for (uint i = 0; i < 12; ++i)
{
monthly[i].resize(study.areas.size(), study.areas.size());
Expand Down Expand Up @@ -481,11 +479,8 @@ void Correlation::reset(Study& study)
delete annual;
annual = nullptr;
}
if (monthly)
{
delete[] monthly;
monthly = nullptr;
}

monthly.clear();

pMode = modeAnnual;
if (JIT::usedFromGUI)
Expand All @@ -496,7 +491,7 @@ void Correlation::reset(Study& study)
annual->fillUnit();

// Preparing the monthly correlation matrices
monthly = new Matrix<>[12];
monthly.resize(12);
for (int i = 0; i < 12; ++i)
{
monthly[i].resize(study.areas.size(), study.areas.size());
Expand All @@ -519,11 +514,8 @@ void Correlation::clear()
delete annual;
annual = nullptr;
}
if (monthly)
{
delete[] monthly;
monthly = nullptr;
}

monthly.clear();
}

bool Correlation::internalLoadFromINI(Study& study, const IniFile& ini, bool warnings)
Expand All @@ -534,11 +526,8 @@ bool Correlation::internalLoadFromINI(Study& study, const IniFile& ini, bool war
delete annual;
annual = nullptr;
}
if (monthly)
{
delete[] monthly;
monthly = nullptr;
}

monthly.clear();

if (!internalLoadFromINITry(study, ini, warnings))
{
Expand All @@ -552,7 +541,7 @@ bool Correlation::internalLoadFromINI(Study& study, const IniFile& ini, bool war
annual->fillUnit();

// Preparing the monthly correlation matrices
monthly = new Matrix<>[12];
monthly.resize(12);
for (int i = 0; i < 12; ++i)
{
monthly[i].resize(study.areas.size(), study.areas.size());
Expand Down Expand Up @@ -638,7 +627,7 @@ uint64_t Correlation::memoryUsage() const
{
r += annual->memoryUsage();
}
if (monthly)
if (!monthly.empty())
{
for (uint i = 0; i != 12; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Correlation final
//! The correlation matrix for the whole year
Matrix<>* annual;
//! All correlation matrices per month (12)
Matrix<>* monthly; // [12]
std::vector<Matrix<>> monthly; // [12]

//! The name to displays in logs
Yuni::CString<30, false> correlationName;
Expand Down

0 comments on commit 4bdf895

Please sign in to comment.