@@ -90,17 +90,19 @@ bool vectorsEqual(const std::vector<T>& C1, const std::vector<T>& C2, const std:
90
90
91
91
92
92
template <typename T>
93
- bool vectorsEqualD (const std::vector<T>& C1, const std::vector<T>& C2, const std::vector<T>& C3, const std::vector<T>& input)
93
+ bool vectorsEqualD (const std::vector<T>& C1, const std::vector<T>& C2, const std::vector<T>& C3, const std::vector<T>& input, double ERR = 1e-13 )
94
94
{
95
95
bool testOK = true ;
96
- const double ERR = 1e-13 ;
96
+ // const double ERR = 1e-13;
97
97
if (C1.size () != C2.size ())
98
98
{
99
+ std::cout << " wrong size C1,C2" << C1.size () << " , " << C2.size () <<std::endl;
99
100
return false ;
100
101
}
101
102
102
103
if (C3.size () != C2.size ())
103
104
{
105
+ std::cout << " wrong size C2,C3" << C2.size () << " , " << C3.size () << std::endl;
104
106
return false ;
105
107
}
106
108
@@ -114,6 +116,7 @@ bool vectorsEqualD(const std::vector<T>& C1, const std::vector<T>& C2, const std
114
116
testOK = false ;
115
117
std::cout << " \n err diff@ " << i << " err1 =" << err1 << " , err2 = " << err2 << " \n " ;
116
118
std::cout << " \n val @ " << i << " C1[i] =" << C1[i] << " , C3[i] = " << C3[i] << " input val=" << input[i] <<" \n " ;
119
+ std::cout << std::endl;
117
120
break ;
118
121
}
119
122
}
@@ -331,15 +334,16 @@ int main()
331
334
// binarySelectionBetweenConst();
332
335
333
336
// return 0;
334
- std::cout << " \n \n \n \n binarySelectionBetweenLinearFunction() \n " << std::endl;
335
- binarySelectionBetweenLinearFunction ();
337
+ // std::cout << "\n \n \n \n binarySelectionBetweenLinearFunction() \n" << std::endl;
338
+ // binarySelectionBetweenLinearFunction();
339
+
336
340
// std::cout << "\n \n \n \n binarySelectionBetweenMiddleWeightFunction() \n" << std::endl;
337
- // binarySelectionBetweenMiddleWeightFunction();
341
+ // binarySelectionBetweenMiddleWeightFunction();
338
342
339
343
// return 0;
340
344
341
- // std::cout << "\n \n \n \n binarySelectionBetweenHeavyWeightFunction() \n" << std::endl;
342
- // binarySelectionBetweenHeavyWeightFunction();
345
+ std::cout << " \n \n \n \n binarySelectionBetweenHeavyWeightFunction() \n " << std::endl;
346
+ binarySelectionBetweenHeavyWeightFunction ();
343
347
// return 0;
344
348
// doSum();
345
349
return 0 ;
@@ -1251,124 +1255,6 @@ void binarySelectionBetweenLinearFunction()
1251
1255
1252
1256
}
1253
1257
1254
- /*
1255
- //selecting between middle weight functions
1256
- void testBinarySelection2()
1257
- {
1258
- using FloatType = typename InstructionTraits<VecXX::INS>::FloatType;
1259
- const int TEST_LOOP_SZ = 1000;
1260
-
1261
- for (long SZ = 200; SZ < 20000; SZ += 200)
1262
- {
1263
-
1264
- auto v1 = getRandomShuffledVector(SZ); // std stl vector double or float
1265
- VecXX testVec(v1);
1266
-
1267
- auto C = v1; //copy of STL vector to write values to
1268
- auto C1 = v1;
1269
- auto C2 = v1;
1270
-
1271
- double time = 0.;
1272
- auto runName = "";
1273
- const auto one = VecXX::scalar(.0);
1274
- const auto two = VecXX::scalar(2.0);
1275
- const auto half = VecXX::scalar(0.5);
1276
-
1277
- auto MyOddLmbda = [&](auto x) { return (x - two * floor(x * half)) >= one; };
1278
-
1279
- /// from acklams inverse cdf normal
1280
- static FloatType a[] = { 0.0, -3.969683028665376e+01, 2.209460984245205e+02,-2.759285104469687e+02, 1.383577518672690e+02, -3.066479806614716e+01, 2.506628277459239e+00 };
1281
- static FloatType b[] = { 0.0, -5.447609879822406e+01, 1.615858368580409e+02, -1.556989798598866e+02, 6.680131188771972e+01, -1.328068155288572e+01 };
1282
- static FloatType c[] = { 0.0,-7.784894002430293e-03,-3.223964580411365e-01, -2.400758277161838e+00, -2.549732539343734e+00, 4.374664141464968e+00, 2.938163982698783e+00 };
1283
- static FloatType d[] = { 0.0, 7.784695709041462e-03, 3.224671290700398e-01, 2.445134137142996e+00, 3.754408661907416e+00 };
1284
-
1285
-
1286
- auto trueLambda = [&](auto q)
1287
- {
1288
- auto X = (((((c[1] * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) * q + c[6]) /
1289
- ((((d[1] * q + d[2]) * q + d[3]) * q + d[4]) * q + VecXX::scalar(1.0));
1290
- return X;
1291
- };
1292
-
1293
-
1294
- auto falseLambda = [&](auto q)
1295
- {
1296
- auto X = (((((a[1] * q + a[2]) * q + a[3]) * q + a[4]) * q + a[5]) * q + a[6]) /
1297
- ((((b[1] * q + b[2]) * q + b[3]) * q + b[4]) * q + VecXX::scalar(1.0));
1298
- return X;
1299
- };
1300
-
1301
- auto writeResults = [&]() { std::cout << "size" << SZ << "," << runName << ", " << " # calcs, " << numOps(TEST_LOOP_SZ , SZ) << ", run time =, " << time << ", rate =, " << numOps(TEST_LOOP_SZ, SZ) / time << ", , "; };
1302
-
1303
-
1304
- { runName = "for loop";
1305
- {
1306
- TimerGuard timer(time);
1307
- {
1308
- for (long l = 0; l < TEST_LOOP_SZ; l++)
1309
- {
1310
- for (int k = 0; k < SZ; k++)
1311
- {
1312
- auto x = v1[k];
1313
- C[k] = MyOddLmbda(x) ? trueLambda(x) : falseLambda(x);
1314
- }
1315
- }
1316
- }
1317
- }
1318
- writeResults();
1319
- }
1320
-
1321
- //calculate both true and false lambdas for all values and select/blend values together
1322
- { runName = "DR3 selectTransform ";
1323
- VecXX res;
1324
- {
1325
- TimerGuard timer(time);
1326
- {
1327
- for (long l = 0; l < TEST_LOOP_SZ; l++)
1328
- {
1329
- res = selectTransform(MyOddLmbda, testVec, trueLambda, falseLambda);
1330
- }
1331
- }
1332
- }
1333
- writeResults();
1334
- C1 = res;
1335
- }
1336
-
1337
-
1338
-
1339
- //binary filter into concrete views of true and false elements according to MyOddLambda. Then apply true and false lambdas and finally merge values together
1340
- { runName = "DR3 filterTransform";
1341
- VecXX res;
1342
- {
1343
- TimerGuard timer(time);
1344
- {
1345
- for (long l = 0; l < TEST_LOOP_SZ; l++)
1346
- {
1347
- res = filterTransform(MyOddLmbda, testVec, trueLambda, falseLambda);
1348
- }
1349
- }
1350
- }
1351
- writeResults();
1352
- C2 = res;
1353
- }
1354
-
1355
- //compare resulyts of calcs
1356
- bool testOK = vectorsEqual(C1, C2, C);
1357
-
1358
- if (testOK)
1359
- {
1360
- std::cout << "Matching results";
1361
- }
1362
- else
1363
- {
1364
- std::cout << " FAIL results dont match";
1365
- }
1366
- std::cout << "\n";
1367
- }
1368
-
1369
- }
1370
- */
1371
-
1372
1258
1373
1259
void binarySelectionBetweenMiddleWeightFunction ()
1374
1260
{
@@ -1882,14 +1768,14 @@ void binarySelectionBetweenHeavyWeightFunction()
1882
1768
// warm up
1883
1769
for (long l = 0 ; l < WARM_UP_LOOP; l++)
1884
1770
{
1885
- auto res = filterTransform (MyOddLmbda, testVec, trueLambdaS, falseLambdaS);
1771
+ res = filterTransform (MyOddLmbda, testVec, trueLambdaS, falseLambdaS);
1886
1772
}
1887
1773
1888
1774
TimerGuard timer (time);
1889
1775
{
1890
1776
for (long l = 0 ; l < TEST_LOOP_SZ; l++)
1891
1777
{
1892
- auto res = filterTransform (MyOddLmbda, testVec, trueLambdaS, falseLambdaS);
1778
+ res = filterTransform (MyOddLmbda, testVec, trueLambdaS, falseLambdaS);
1893
1779
}
1894
1780
}
1895
1781
}
@@ -1919,7 +1805,7 @@ void binarySelectionBetweenHeavyWeightFunction()
1919
1805
auto valStl = run_res_for_loop.m_calc_results [elem.first ];
1920
1806
auto valDr3_filterTransform = dr3_raw_resultsFilter.m_calc_results [elem.first ];
1921
1807
1922
- bool VecsOK = vectorsEqualD (valDr3_select, valStl, valDr3_filterTransform, valDr3_filterTransform);
1808
+ bool VecsOK = vectorsEqualD (valDr3_select, valStl,valDr3_filterTransform, valDr3_filterTransform, 3e-11 );
1923
1809
auto strMatch = VecsOK ? " calcs match" : " cal difference" ;
1924
1810
1925
1811
std::cout << " for loop binarySelectionBetweenSimpleAndHeavyFunctions , size " << elem.first << " , " << elem.second .first << " , +- ," << elem.second .second << " \t \t DR3 filter_transform heavy weight , size " << elem.first << " , " << stats_DR3_filter[elem.first ].first << " , +- ," << stats_DR3_filter[elem.first ].second << " \t \t DR3 binarySelection heavy Weight , size " << elem.first << " , " << stats_DR3[elem.first ].first << " , +- , " << stats_DR3[elem.first ].second << " , numerical check: " << strMatch << " \n " ;
0 commit comments