@@ -4637,18 +4637,43 @@ template <typename T, int nprogress> static inline SimpleVector<T> pGuarantee(co
46374637 return res[res.size () - 1 ];
46384638}
46394639
4640+ // N.B. pre/post process
4641+ template <typename T> SimpleVector<SimpleVector<T> > preAppend (const SimpleVector<SimpleVector<T> >& in) {
4642+ SimpleVector<SimpleVector<T> > res (delta<SimpleVector<T> >(unOffsetHalf<T>(in)));
4643+ for (int i = 0 ; i < res.size (); i += 2 ) res[i] = - res[i];
4644+ return res;
4645+ }
4646+
4647+ template <typename T> SimpleVector<SimpleVector<T> > postAppend (SimpleVector<SimpleVector<T> > res, const SimpleVector<SimpleVector<T> >& in) {
4648+ SimpleVector<SimpleVector<T> > w (res.size ());
4649+ for (int i = 0 ; i < w.size () - 1 ; i ++) {
4650+ w[i].resize (res[i].size () * 2 );
4651+ w[i].setVector (0 , in[i - (w.size () - 1 ) + in.size ()] - res[i]);
4652+ w[i].setVector (res[i].size (), res[i]);
4653+ }
4654+ w[w.size () - 1 ].resize (res[res.size () - 1 ].size () * 2 );
4655+ w[w.size () - 1 ].O ().setVector (res[res.size () - 1 ].size (), res[res.size () - 1 ]);
4656+ for (int i = 1 ; i < w.size (); i ++) w[i] += w[i - 1 ];
4657+ for (int i = 0 ; i < w.size () - 1 ; i ++)
4658+ for (int j = 0 ; j < res[i].size (); j ++)
4659+ res[i][j] = (w[i][j] + w[i][w[i].size () / 2 + j]) *
4660+ w[i][w[i].size () / 2 + j];
4661+ res[res.size () - 1 ] = w[w.size () - 1 ].subVector (res[0 ].size (), res[0 ].size ());
4662+ for (int i = 1 ; i < res.size (); i ++)
4663+ for (int j = 0 ; j < res[i].size (); j ++) res[i][j] *= res[i - 1 ][j];
4664+ for (int i = 0 ; i < res.size () - 1 ; i ++)
4665+ for (int j = 0 ; j < res[i].size (); j ++)
4666+ if (in[i][j] != T (int (0 )))
4667+ res[i][j] /= in[i - (res.size () - 1 ) + in.size ()][j];
4668+ return res;
4669+ }
4670+
46404671// N.B. append pseudo-measureable condition into original input
46414672// stream but the predictor isn't depend pseudo-things.
46424673// also add whole context length markov feeding.
46434674// also this feeds something dense and as a result continuous to predictor.
4644- template <typename T, int nprogress, bool need_prep > SimpleVector<SimpleVector<T> > pAppendMeasure0 (const SimpleVector<SimpleVector<T> >& in0 , const int & bits, const string& strloop) {
4675+ template <typename T, int nprogress> SimpleVector<SimpleVector<T> > pAppendMeasure0 (const SimpleVector<SimpleVector<T> >& in , const int & bits, const string& strloop) {
46454676 assert (0 < bits);
4646- SimpleVector<SimpleVector<T> > in;
4647- if (need_prep) {
4648- in = delta<SimpleVector<T> >(unOffsetHalf<T>(in0));
4649- for (int i = 0 ; i < in.size (); i += 2 ) in[i] = - in[i];
4650- // N.B. p d | p B in upper layer.
4651- } else in = unOffsetHalf<T>(in0);
46524677 pair<SimpleVector<SimpleVector<T> >, T> wp (normalizeS<T>(
46534678 delta<SimpleVector<T> >(delta<SimpleVector<T> >(in)) ));
46544679 SimpleVector<SimpleVector<T> > p (unOffsetHalf<T>(pRS00<T, nprogress>(
@@ -4677,22 +4702,16 @@ template <typename T, int nprogress, bool need_prep> SimpleVector<SimpleVector<T
46774702 SimpleVector<SimpleVector<T> > pp (p.subVector (0 , i0 + 1 ));
46784703 for (int i = 0 ; i < pp.size (); i ++) pp[i] -= plast;
46794704 for (int i = 1 ; i < pp.size (); i ++) pp[i] += pp[i - 1 ];
4680- // N.B. somehow, ||in0 [i0]|| << ||pp[i0]||
4681- res.entity .emplace_back (i0 & 1 || ! need_prep ? move (pp[i0]) : - pp[i0]);
4705+ // N.B. somehow, ||in [i0]|| << ||pp[i0]||
4706+ res.entity .emplace_back (i0 & 1 ? move (pp[i0]) : - pp[i0]);
46824707 }
4683- if (need_prep) {
4684- for (int i = 1 ; i < res.size (); i ++) res[i] += res[i - 1 ];
4685- for (int i = res.size () - 1 ; 0 < i; i --)
4686- for (int j = 0 ; j < res[i].size (); j ++)
4687- res[i][j] *= res[i - 1 ][j] * in[i - res.size () + in.size ()][j];
4688- }
4689- // N.B. we need (p B |) p s | p0 0 1 after this line.
46904708 return res;
46914709}
46924710
46934711template <typename T, int nprogress> static inline SimpleVector<T> pAppendMeasure (const SimpleVector<SimpleVector<T> >& in0, const int & bits, const string& strloop) {
4694- SimpleVector<SimpleVector<T> > p (
4695- pAppendMeasure0<T, nprogress, true >(in0, bits, strloop));
4712+ SimpleVector<SimpleVector<T> > in (preAppend<T>(in0));
4713+ SimpleVector<SimpleVector<T> > p (postAppend<T>(
4714+ pAppendMeasure0<T, nprogress>(in, bits, strloop), in));
46964715 return p[p.size () - 1 ];
46974716}
46984717
@@ -4708,11 +4727,12 @@ template <typename T, int nprogress> static inline SimpleVector<T> pAppendMeasur
47084727// however, if the original raw stream have whole vector context each pixel
47094728// structure have better structure than PRNGs, it's better bet with the
47104729// condition after prediction shrinking.
4711- template <typename T, int nprogress> SimpleVector<SimpleVector<T> > pPRNG0 (const SimpleVector<SimpleVector<T> >& in0 , const int & bits, const string& strloop) {
4730+ template <typename T, int nprogress> SimpleVector<SimpleVector<T> > pPRNG0 (const SimpleVector<SimpleVector<T> >& in00 , const int & bits, const string& strloop) {
47124731 assert (0 < bits);
47134732#if defined(_OPENMP)
4714- for (int i = 1 ; i <= in0 .size (); i ++) pnextcacher<T>(i, 1 );
4733+ for (int i = 1 ; i <= in00 .size (); i ++) pnextcacher<T>(i, 1 );
47154734#endif
4735+ SimpleVector<SimpleVector<T> > in0 (offsetHalf<T>(preAppend<T>(in00)));
47164736 SimpleVector<SimpleVector<T> > in;
47174737 in.entity .reserve (in0.size ());
47184738 for (int i = 0 ; i < in0.size (); i ++) {
@@ -4730,8 +4750,8 @@ template <typename T, int nprogress> SimpleVector<SimpleVector<T> > pPRNG0(const
47304750 in.entity .emplace_back (work);
47314751 }
47324752 if (_P_PRNG_ <= 1 ) {
4733- SimpleVector<SimpleVector<T> > res (offsetHalf<T>(
4734- pAppendMeasure0<T, nprogress, true >(in, bits, strloop)) );
4753+ SimpleVector<SimpleVector<T> > res (offsetHalf<T>(postAppend<T>(
4754+ pAppendMeasure0<T, nprogress>(in, bits, strloop), in )) );
47354755 for (int i = 0 ; i < res.size (); i ++)
47364756 res[i] = bitsG<T, true >(res[i], - bits);
47374757 return res;
@@ -4752,22 +4772,35 @@ template <typename T, int nprogress> SimpleVector<SimpleVector<T> > pPRNG0(const
47524772 for (int k = 0 ; k < work[j].size (); k ++) work[j][k] = offsetHalf<T>(
47534773 prng[j][k] * unOffsetHalf<T>(in[j][k / _P_PRNG_]) );
47544774 }
4755- SimpleVector<SimpleVector<T> > w (pAppendMeasure0<T, nprogress, true >(work,
4756- bits, strloop));
4757- SimpleVector<SimpleVector<T> > out (w .size ());
4775+ SimpleVector<SimpleVector<T> > res (postAppend<T>(
4776+ pAppendMeasure0<T, nprogress>(work, bits, strloop), work ));
4777+ SimpleVector<SimpleVector<T> > out (res .size ());
47584778 for (int i = 0 ; i < out.size (); i ++) {
47594779 out[i].resize (in[0 ].size ());
47604780 out[i].O ();
4761- for (int j = 0 ; j < w [i].size (); j ++)
4762- out[i][j / _P_PRNG_] += w [i][j] *
4781+ for (int j = 0 ; j < res [i].size (); j ++)
4782+ out[i][j / _P_PRNG_] += res [i][j] *
47634783 prng[i - out.size () + prng.size ()][j];
47644784 out[i] = bitsG<T, true >(offsetHalf<T>(out[i]), - bits);
47654785 }
47664786 return out;
47674787}
47684788
4789+ template <typename T, int nprogress> SimpleVector<SimpleVector<T> > pPRNG1 (const SimpleVector<SimpleVector<T> >& in, const int & bits, const string& strloop) {
4790+ SimpleVector<SimpleVector<T> > p (delta<SimpleVector<T> >(unOffsetHalf<T>(
4791+ pPRNG0<T, nprogress>(in, bits, string (" +" ) + strloop))));
4792+ for (int i = 0 ; i < p.size (); i += 2 ) p[i] = - p[i];
4793+ for (int i = 1 ; i < p.size (); i ++) p[i] += p[i - 1 ];
4794+ p = delta<SimpleVector<T> >(unOffsetHalf<T>(pPRNG0<T, nprogress>(
4795+ offsetHalf<T>(p), bits, string (" -" ) + strloop)));
4796+ p.resize (p.size () - 1 );
4797+ for (int i = 0 ; i < p.size (); i += 2 ) p[i] = - p[i];
4798+ for (int i = 1 ; i < p.size (); i ++) p[i] += p[i - 1 ];
4799+ return p;
4800+ }
4801+
47694802template <typename T, int nprogress> static inline SimpleVector<T> pPRNG (const SimpleVector<SimpleVector<T> >& in0, const int & bits, const string& strloop) {
4770- SimpleVector<SimpleVector<T> > p (pPRNG0 <T, nprogress>(in0, bits, strloop));
4803+ SimpleVector<SimpleVector<T> > p (pPRNG1 <T, nprogress>(in0, bits, strloop));
47714804 return p[p.size () - 1 ];
47724805}
47734806
0 commit comments