MTRX generateMatrix(Mnd mnd) { MTRX output; int mn = mnd.m * mnd.n; int m = mnd.m; for (int mn1 = 0; mn1 < mn; mn1++) { int m1 = mn1 / m; int n1 = mn1 % m; VEC v; for (int mn2 = 0; mn2 < mn; mn2++) { int m2 = mn2 / m; int n2 = mn2 % m; if (mn1 == mn2 || abs(m1 - m2) + abs(n1 - n2) == mnd.d) { v.push_back(1); } else { v.push_back(0); } } for (int mn3 = 0; mn3 < mn; mn3++) { v.push_back(mn1 == mn3 ? 1 : 0); } output.push_back(v); } return output; }
void TestSslowlog(){ CRedisClient redis; redis.connect( "127.0.0.1", 6379 ); cout << "------test slowlog------" << endl; VEC vec; vec.push_back("GET"); CResult res; redis.slowlog(vec,res); cout<<res<<endl; }
void ConfHandler::setNeighborVector(VEC &neighborVector) { ConfHandler::MIT kvi; ConfHandler::MAP* map = &ConfHandler::NeighborSeeds; for (kvi = map->begin(); kvi != map->end(); kvi++) { neighborVector.push_back(kvi->second); } }
VEC multiply(const MTRX &matrix, const VEC &row) { VEC output; for (int i = 0; i < matrix.size(); i++) { int sum = 0; for (int j = 0; j < matrix[i].size(); j++) { sum += matrix[i][j] * row[j]; } output.push_back(sum % 2); } return output; }
MTRX preSolve(Mnd mnd) { MTRX matrix = generateMatrix(mnd); int rank = gaussianElimination(matrix); MTRX output; for (int i = rank; i < matrix.size(); i++) { VEC v; for (int j = matrix[0].size()/2; j < matrix[0].size(); j++) { v.push_back(matrix[i][j]); } output.push_back(v); } return output; }
/* ===================================================================== */ VOID DumpHistogram(std::ostream& out) { const UINT64 cutoff = KnobCutoff.Value(); const UINT64 maxlines = KnobMaxLines.Value(); FLT64 factor = KnobDecayFactor.Value(); out << "\033[0;0H"; out << "\033[2J"; out << "\033[44m"; out << "Functions with at least " << cutoff << " invocations in the last " << KnobThreshold.Value() << " calls "; out << "\033[0m"; out << endl; VEC CountMap; for (ADDR_CNT_MAP::iterator bi = RtnMap.begin(); bi != RtnMap.end(); bi++) { if( bi->second < cutoff ) continue; CountMap.push_back(*bi); #if 0 out << setw(18) << (void *)(bi->first) << " " << setw(10) << bi->second << " " << Target2String(bi->first) << endl; #endif } sort( CountMap.begin(), CountMap.end(), CompareLess ); UINT64 lines = 0; for (VEC::iterator bi = CountMap.begin(); bi != CountMap.end(); bi++) { out << setw(18) << (void *)(bi->first) << " " << setw(10) << bi->second << " " << Target2String(bi->first) << endl; lines++; if (lines >= maxlines) break; } for (ADDR_CNT_MAP::iterator bi = RtnMap.begin(); bi != RtnMap.end(); bi++) { bi->second = UINT64(bi->second * factor); } //out << "Total Functions: " << CountMap.size() << endl; }
TEST(AgradRevMatrix, dot_product_vd) { AVEC a; VEC b; AVAR c; for (int i = -1; i < 2; i++) { // a = (-1, 0, 1), b = (1, 2, 3) a.push_back(i); b.push_back(i + 2); } c = dot_product(&a[0], &b[0], 3); EXPECT_EQ(2, c); VEC grad; c.grad(a, grad); EXPECT_EQ(grad[0], 1); EXPECT_EQ(grad[1], 2); EXPECT_EQ(grad[2], 3); }
TEST(AgradRevMatrix, dot_product_dv_vec) { VEC a; AVEC b; AVAR c; for (int i = -1; i < 2; i++) { // a = (-1, 0, 1), b = (1, 2, 3) a.push_back(i); b.push_back(i + 2); } c = dot_product(a, b); EXPECT_EQ(2, c); VEC grad; c.grad(b, grad); EXPECT_EQ(grad[0], -1); EXPECT_EQ(grad[1], 0); EXPECT_EQ(grad[2], 1); }
TEST(AgradRev, sort_indices) { VEC a; a.push_back(1); a.push_back(2); a.push_back(2); a.push_back(3); test_sort_indices_asc(a); test_sort_indices_desc(a); VEC b; b.push_back(1.1); b.push_back(2.2); ; b.push_back(33.1); b.push_back(-12.1); b.push_back(33.1); test_sort_indices_asc(b); test_sort_indices_desc(b); VEC c; c.push_back(1.1); c.push_back(-2); c.push_back(2.1); c.push_back(3); c.push_back(2.1); test_sort_indices_asc(c); test_sort_indices_desc(c); Eigen::RowVectorXd vec1(4); vec1 << 1, -33.1, 2.1, -33.1; test_sort_indices_asc(vec1); test_sort_indices_desc(vec1); Eigen::RowVectorXd vec2(5); vec2 << 1.1e-6, -2.3, 31.1, 1, -10.1; test_sort_indices_asc(vec2); test_sort_indices_desc(vec2); Eigen::VectorXd vec3(4); vec3 << -11.1, 2.2, -3.6, 2.2; test_sort_indices_asc(vec3); test_sort_indices_desc(vec3); Eigen::VectorXd vec4(3); vec4 << -10.1, 2.12, 3.102; test_sort_indices_asc(vec4); test_sort_indices_desc(vec4); Eigen::RowVectorXd vec5 = Eigen::RowVectorXd::Random(1,10); test_sort_indices_asc(vec5); test_sort_indices_desc(vec5); Eigen::VectorXd vec6 = Eigen::VectorXd::Random(20,1); test_sort_indices_asc(vec6); test_sort_indices_desc(vec6); }