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

Commit

Permalink
merge latest lieonn.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsofcotton authored Jun 22, 2024
1 parent 1779b32 commit f34ac5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ Please refer bitsofcotton/p8 for this.
2024/06/11 elim nouse commands.
2024/06/21 merge latest lieonn. re-add clean\[lL\]c? commands.
2024/06/22 merge latest lieonn.
2024/06/23 merge latest lieonn.

54 changes: 30 additions & 24 deletions lieonn.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3127,7 +3127,7 @@ template <typename T> static inline vector<pair<vector<SimpleVector<T> >, vector

template <typename T> class P012L {
public:
inline P012L(const int& var = 4, const int& step = 1) {
inline P012L(const int& step = 1, const int& var = 4) {
assert(1 < var && 0 < step);
varlen = var;
this->step = step;
Expand Down Expand Up @@ -3292,7 +3292,7 @@ public:
}
inline ~P0() { ; };
inline T next(const SimpleVector<T>& in) {
return pnextcacher<T>(in.size(), step, r).dot(in);
return pnextcacher<T>(in.size(), ((step - 1) % in.size()) + 1, r).dot(in);
}
int step;
};
Expand Down Expand Up @@ -3485,7 +3485,7 @@ public:
// cf. bitsofcotton/randtools .
template <typename T, bool nonlinear = true> class P01 {
public:
inline P01(const int& var = 4, const int& step = 1) {
inline P01(const int& step = 1, const int& var = 4) {
assert(0 < var && 0 < step);
this->varlen = var;
this->step = step;
Expand Down Expand Up @@ -3547,7 +3547,7 @@ private:
template <typename T, typename P> class PBond {
public:
inline PBond() { ; }
inline PBond(P&& p, const int& status) {
inline PBond(const int& status, P&& p = P()) {
assert(0 < status);
this->p = p;
f = idFeeder<T>(status);
Expand Down Expand Up @@ -3578,15 +3578,18 @@ public:

// N.B. this class feeds new states into predictor as a new dimension of
// linear sum.
template <typename T, typename P, bool lstart = true> class Pprogression {
template <typename T, typename P> class Pprogression {
public:
inline Pprogression() { ; }
inline Pprogression(const P& p, const int& loop0 = 1, const int& istat = 3) {
inline Pprogression(const int& loop0, const int& istat) {
assert(loop0);
const auto loop(abs(loop0));
(this->p).resize(loop);
for(int i = 0; i < (this->p).size(); i ++)
(this->p)[i].resize(i + 1, p);
p.resize(loop);
for(int i = 0; i < (this->p).size(); i ++) {
p[i].reserve(i + 1);
for(int j = 0; j <= i; j ++)
p[i].emplace_back(PBond<T, P>(istat + i, P(i + 1)));
}
h = idFeeder<T>(loop);
{
vector<int> ph0;
Expand Down Expand Up @@ -3620,18 +3623,18 @@ public:
auto M(zero);
if(! h.full) return M;
for(int i = 0; i < p.size(); i ++) {
if(! lstart || (p.size() - 1 - i) * istat <= t)
if(p.size() - 1 - i <= t)
bb[i].next(p[i][t % p[i].size()].next(
progression(hh, hh.size() - 1, i)));
}
if(! lstart || p.size() * istat <= t)
if(p.size() <= t)
for(int i = 0; i < p.size(); i ++)
M += bb[i].res[0] + (i && addp ?
progression(hh, hh.size() - 2, i - 1) : zero);
t ++;
return addp ? M /= T(int(p.size())) : M;
}
vector<vector<P> > p;
vector<vector<PBond<T, P> > > p;
idFeeder<T> h;
vector<vector<int> > ph;
vector<vector<T> > eh;
Expand All @@ -3656,10 +3659,10 @@ public:
};

template <typename T> using P10 =
PAthenB<T, Pprogression<T, PBond<T, P01<T> > >,
Pprogression<T, PBond<T, P0maxRank<T> > > >;
PAthenB<T, Pprogression<T, P01<T> >,
Pprogression<T, P0maxRank<T> > >;
template <typename T> using P210 =
PAthenB<T, Pprogression<T, PBond<T, P012L<T> > >, P10<T> >;
PAthenB<T, Pprogression<T, P012L<T> >, P10<T> >;

// N.B. invariant gathers some of the group on the input pattern.
template <typename T> SimpleMatrix<T> concat(const SimpleMatrix<T>& m0, const SimpleMatrix<T>& m1) {
Expand Down Expand Up @@ -4236,7 +4239,8 @@ template <typename T> pair<SimpleVector<T>, SimpleVector<T> > predv(const vector
seconds[i] = makeProgramInvariant<T>(in[i], - T(int(1)), true).second;
}
// N.B. we need Pprogression<..., P01...> with maximum range.
const int p0(in.size() / (5 * 5 - 4 + 2));
const int istat(5 * 5 - 4 + 2);
const int p0((in.size() - istat) / 3);
SimpleVector<T> p;
SimpleVector<T> q;
p.resize(in[0].size());
Expand All @@ -4248,15 +4252,17 @@ template <typename T> pair<SimpleVector<T>, SimpleVector<T> > predv(const vector
#endif
for(int j = 0; j < in[0].size(); j ++) {
cerr << j << " / " << in[0].size() << endl;
Pprogression<T, PBond<T, P01<T> > > pf(PBond<T, P01<T> >(P01<T>(4), 5 * 5 - 4 + 2), p0, 5 * 5 - 4 + 2);
Pprogression<T, PBond<T, P01<T> > > pb(PBond<T, P01<T> >(P01<T>(4), 5 * 5 - 4 + 2), p0, 5 * 5 - 4 + 2);
Pprogression<T, P01<T> > pf(p0, istat);
Pprogression<T, P01<T> > pb(p0, istat);
for(int i = 0; i < in.size(); i ++) {
p[j] = pf.next(makeProgramInvariantPartial<T>(in[i][j], seconds[i], true));
q[j] = pb.next(makeProgramInvariantPartial<T>(in[in.size() - i - 1][j], seconds[seconds.size() - i - 1], true));
p[j] = pf.next(makeProgramInvariantPartial<T>(in[i][j],
seconds[i], true));
q[j] = pb.next(makeProgramInvariantPartial<T>(in[in.size() - i - 1][j],
seconds[seconds.size() - i - 1], true));
}
}
Pprogression<T, PBond<T, P01<T> > > pf(PBond<T, P01<T> >(P01<T>(4), 5 * 5 - 4 + 2), p0, 5 * 5 - 4 + 2);
Pprogression<T, PBond<T, P01<T> > > pb(PBond<T, P01<T> >(P01<T>(4), 5 * 5 - 4 + 2), p0, 5 * 5 - 4 + 2);
Pprogression<T, P01<T> > pf(p0, istat);
Pprogression<T, P01<T> > pb(p0, istat);
T rp;
T rq;
for(int i = 0; i < in.size(); i ++) {
Expand Down Expand Up @@ -4435,13 +4441,13 @@ template <typename T> static inline vector<SimpleMatrix<T> > xyz2rgb(const vecto

static const vector<int>& pnTinySingle(const int& upper = 1) {
static vector<int> pn;
if(! pn.size()) pn.push_back(2);
if(! pn.size()) pn.emplace_back(2);
pn.reserve(upper);
for(int i = pn.size(); i < upper; i ++) {
for(int j = pn[pn.size() - 1] + 1; 0 <= j; j ++) {
for(int k = 0; k < pn.size(); k ++)
if(! (j % pn[k])) goto next_pn;
pn.push_back(j);
pn.emplace_back(j);
break;
next_pn:
;
Expand Down

0 comments on commit f34ac5e

Please sign in to comment.