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 Jun 9, 2024
1 parent 7c59673 commit b90abb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ Please refer bitsofcotton/p8 for this.
2024/04/23 add predC, predCbond command.
2024/05/29 cleanC, cleanc change.
2024/06/07 fix comment on test.py.
2024/06/09 compat with latest ddpmopt.

12 changes: 7 additions & 5 deletions lieonn.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,8 @@ template <typename T> static inline pair<SimpleVector<T>, T> makeProgramInvarian

template <typename T> static inline T revertProgramInvariant(const pair<T, T>& in, const bool& on01 = false) {
const auto r0(in.first * in.second);
const auto r(T(int(0)) < r0 ? r0 - floor(r0) : ceil(- r0) + r0);
const auto r1(T(int(0)) < r0 ? r0 - floor(r0) : ceil(- r0) + r0);
const auto r(T(int(0)) == r1 ? T(int(1)) : r1);
return on01 ? r :
- tan(max(- T(int(1)) + sqrt(SimpleMatrix<T>().epsilon()),
min( T(int(1)) - sqrt(SimpleMatrix<T>().epsilon()),
Expand Down Expand Up @@ -3911,7 +3912,7 @@ template <typename T> static inline bool loadstub(ifstream& input, const int& nm
continue;
} else if(mode) {
mode = false;
datas[k](j, i) = T(work) / T(nmax);
datas[k](j, i) = T(work + 1) / (T(nmax) + T(int(1)));
work = 0;
if(++ k >= ncolor) {
if(++ i >= datas[0].cols()) {
Expand Down Expand Up @@ -3997,10 +3998,10 @@ template <typename T> bool savep2or3(const char* filename, const vector<SimpleMa
for(int i = 0; i < data[0].rows(); i ++)
for(int j = 0; j < data[0].cols(); j ++)
if(data.size() == 1)
output << int(data[0](i, j) * T(depth)) << "\n";
output << max(int(0), int(data[0](i, j) * (T(depth) + T(int(1)))) - int(1)) << "\n";
else
for(int k = 0; k < 3; k ++)
output << int(data[k](i, j) * T(depth)) << "\n";
output << max(int(0), int(data[k](i, j) * (T(depth) + T(int(1)))) - int(1)) << "\n";
} catch (...) {
cerr << "An error has occured while writing file." << endl;
}
Expand Down Expand Up @@ -4235,7 +4236,7 @@ template <typename T> pair<vector<vector<SimpleVector<T> > >, vector<vector<Simp

template <typename T> pair<vector<vector<SimpleMatrix<T> > >, vector<vector<SimpleMatrix<T> > > > predMat(const vector<vector<SimpleMatrix<T> > >& in0, const int& skip = 1, const int& cj = 11) {
assert(0 < skip && in0.size() / skip && in0[0].size() && in0[0][0].rows() && in0[0][0].cols());
const int ccj(ceil(sqrt(T(cj))));
const auto ccj(int(ceil(sqrt(T(cj)))) | int(1));
assert(0 < ccj);
if(ccj * ccj * 19683 < in0[0].size() * in0[0][0].rows() * in0[0][0].cols())
cerr << "predMat : elements larger than 19683, exceeds function entropy." << endl;
Expand Down Expand Up @@ -4316,6 +4317,7 @@ template <typename T> pair<vector<SimpleSparseTensor<T> >, vector<SimpleSparseTe
goto next;
absent.emplace_back(make_pair(i, make_pair(j, k)));
next:
;
}
sort(absent.begin(), absent.end());
if(19683 < idx.size() * idx.size() * idx.size() - absent.size())
Expand Down
29 changes: 12 additions & 17 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,15 @@
curdir = os.path.basename(os.getcwd())
s = 0
while(True):
t = 1
while(True):
try:
b = subprocess.call(["mv", "predg-backward-" + str(s) + "-" + str(t) + ".ppm", curdir + "-b" + str(s) + "-" + str(t) + ".ppm"])
f = subprocess.call(["mv", "predg-forward-" + str(s) + "-" + str(t) + ".ppm", curdir + "-f" + str(s) + "-" + str(t) + ".ppm"])
if(b != 0 or f != 0):
if(t == 1): exit(0)
break
t += 1
except:
if(t == 1): exit(0)
try:
b = subprocess.call(["mv", "predg-backward-" + str(s) + ".ppm", curdir + "-b" + str(s) + ".ppm"])
f = subprocess.call(["mv", "predg-forward-" + str(s) + ".ppm", curdir + "-f" + str(s) + ".ppm"])
if(b != 0 or f != 0):
exit(0)
break
s += 1
except:
exit(0)
break
elif(argv[2] == "tilecat" or argv[2] == "tilecatb" or argv[2] == "tilecatr" or argv[2] == "tilecatbr"):
pixels = int(argv[3])
cmd = ["montage"]
Expand Down Expand Up @@ -302,11 +298,10 @@
# With ddpmopt/README.md, we have 20kbit upper limit on function entropy.
# In practical, 2 bit from MSB expecting input is enough.
# However, we expect 8 bit color for each pixel.
upix = pow(19683 / 8., .5)
upixr = upix / pow(w * h, .5)
if(argv[2][- 1] == "c"): upixr /= pow(3., .5)
elif(argv[2][- 1] == "C"): upixr /= 3.
sz = str(int(upixr * w) + 1) + "x" + str(int(upixr * h) + 1)
upix = pow(19683 / 8., .5)
upixr = upix / pow(w * w + h * h, .5)
if(argv[2][- 1] == "C"): upixr /= pow(3. , .5)
sz = str(int(upixr * w) + 1) + "x" + str(int(upixr * h) + 1)
# N.B.
# refering en.wikipedia.org/wiki/Condorcet's-jury-theorem
# n ~ 11 to get .95 from 2/3 probability.
Expand Down

0 comments on commit b90abb2

Please sign in to comment.