void operate(array<T1, S1>& u, array <T2, S2>& p, sep, const array<T3, S3>& a, const size_array& idx = size_array()) // f only used internally! { if (a.empty()) { u.init(); p.init(); return; } if (FIRST) (_, p) = find++(arr(true).cat(diff(a) != 0)); // TODO: check speed of cat() else (_, p) = find++((diff(a) != 0).cat(arr(true))); u = a[p]; if (!idx.empty()) force(p) = idx[p]; }
void operate(array<T1, S1>& u, array <array <T2, S21>, S22>& p, sep, const array<T3, S3>& a, const size_array& idx = size_array()) // f only used internally! { if (a.empty()) { u.init(); p.init(); return; } size_array first = find(arr(true).cat(diff(a) != 0)); u = a[first]; if (idx.empty()) (_, p) = partition++(size_array((0, _, a.length() - 1)), first); // TODO: remove size_array copy else (_, p) = partition++(idx, first); }
void operate(array<T1, S1>& u, array <T2, S2>& p, array <T3, S3>& q, sep, const array<T4, S4>& a, const size_array& idx = size_array()) // idx only used internally! { if (a.empty()) { u.init(); p.init(); q.init(); return; } q = arr(true).cat(diff(a) != 0); if (FIRST) (_, p) = find++(q); else (_, p) = find++(cshift(q, -1)); u = a[p]; if (!idx.empty()) force(p) = idx[p]; q[0] = T3(); q = cumsum(q); }
void norm_root(array <array <T> >& X) { if (X.empty()) return; array <T> L1(X[0].length(), T()); for (size_t d = 0; d < X.length(); d++) L1 += abs(X[d]); // TODO: array <T> L1 = sum(abs(X)); const size_array nz = find(L1 != 0); // TODO: array <bool> const size_t D = X.length(); for (size_t d = 0; d < X.length(); d++) { if (X[d].length() > 100000) msg::progress(info, d, D); X[d][nz] /= L1[nz]; force(X[d]) = sqrt(abs(X[d])) * sign(X[d]); // TODO: force(X) = ... } }
void operate(array<T1, S1>& u, sep, const array<T2, S2>& a) { if (a.empty()) { u.init(); return; } u = a[arr(true).cat(diff(a) != 0)]; }
strcpy(p, "hello world"); printf("%s\n", p); // hello world END_TEST; //----------------------- normal example ---------------------- BEGIN_TEST(ArrayTest, NormalExample, @); array<int, 5> a = {{ 1, 2, 3 }}; psln(a.size()); // a.size() = 5; psln(a.max_size()); // a.max_size() = 5; EXPECT_FALSE(a.empty()); // empty() is false. printContainer(a, "array: "); // array: 1 2 3 0 0 a[a.size() - 1] = 5; // change last one printContainer(a, "array: "); // array: 1 2 3 0 5 a.at(a.size() - 2) = 4; printContainer(a, "array: "); // array: 1 2 3 4 5 int sum; sum = accumulate(a.begin(), a.end(), 0); psln(sum); // sum = 15 try {