Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
compat with latest ddpmopt.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsofcotton committed Apr 7, 2024
1 parent cbb4cb8 commit 10da7ae
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions lieonn.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3997,37 +3997,46 @@ template <typename T> bool savep2or3(const char* filename, const vector<SimpleMa
return true;
}

template <typename T> static inline vector<SimpleMatrix<T> > normalize(const vector<SimpleMatrix<T> >& data, const T& upper = T(1)) {
template <typename T> static inline vector<vector<SimpleMatrix<T> > > normalize(const vector<vector<SimpleMatrix<T> > >& data, const T& upper = T(1)) {
T MM(0), mm(0);
bool fixed(false);
for(int k = 0; k < data.size(); k ++)
for(int i = 0; i < data[k].rows(); i ++)
for(int j = 0; j < data[k].cols(); j ++)
if(! fixed || (isfinite(data[k](i, j)) && ! isinf(data[k](i, j)) && ! isnan(data[k](i, j)))) {
if(! fixed)
MM = mm = data[k](i, j);
else {
MM = max(MM, data[k](i, j));
mm = min(mm, data[k](i, j));
for(int kk = 0; kk < data.size(); kk ++)
for(int k = 0; k < data[kk].size(); k ++)
for(int i = 0; i < data[kk][k].rows(); i ++)
for(int j = 0; j < data[kk][k].cols(); j ++)
if(! fixed || (isfinite(data[kk][k](i, j)) &&
! isinf(data[kk][k](i, j)) && ! isnan(data[kk][k](i, j)))) {
if(! fixed)
MM = mm = data[kk][k](i, j);
else {
MM = max(MM, data[kk][k](i, j));
mm = min(mm, data[kk][k](i, j));
}
fixed = true;
}
fixed = true;
}
if(MM == mm || ! fixed)
return data;
auto result(data);
for(int k = 0; k < data.size(); k ++)
for(int i = 0; i < data[k].rows(); i ++)
for(int j = 0; j < data[k].cols(); j ++) {
if(isfinite(result[k](i, j)) && ! isinf(data[k](i, j)) && ! isnan(result[k](i, j)))
result[k](i, j) -= mm;
else
result[k](i, j) = T(0);
assert(T(0) <= result[k](i, j) && result[k](i, j) <= MM - mm);
result[k](i, j) *= upper / (MM - mm);
}
for(int kk = 0; kk < data.size(); kk ++)
for(int k = 0; k < data[kk].size(); k ++)
for(int i = 0; i < data[kk][k].rows(); i ++)
for(int j = 0; j < data[kk][k].cols(); j ++) {
if(isfinite(result[k][k](i, j)) && ! isinf(data[kk][k](i, j)) && ! isnan(result[kk][k](i, j)))
result[kk][k](i, j) -= mm;
else
result[kk][k](i, j) = T(0);
assert(T(0) <= result[kk][k](i, j) && result[kk][k](i, j) <= MM - mm);
result[kk][k](i, j) *= upper / (MM - mm);
}
return result;
}

template <typename T> static inline vector<SimpleMatrix<T> > normalize(const vector<SimpleMatrix<T> >& data, const T& upper = T(1)) {
vector<vector<SimpleMatrix<T> > > w;
w.emplace_back(data);
return normalize<T>(w, upper)[0];
}

template <typename T> static inline vector<SimpleMatrix<T> > autoLevel(const vector<SimpleMatrix<T> >& data, const int& count = 0) {
vector<T> res;
res.reserve(data[0].rows() * data[0].cols() * data.size());
Expand Down

0 comments on commit 10da7ae

Please sign in to comment.