| 107 | } |
| 108 | |
| 109 | int |
| 110 | main() |
| 111 | { |
| 112 | srand(42); |
| 113 | std::vector<struct ufunc> umathfunc = { |
| 114 | {"sin", sin, sin, 1.49, 1.00}, |
| 115 | {"cos", cos, cos, 1.49, 1.00}, |
| 116 | {"tan", tan, tan, 3.91, 3.93}, |
| 117 | {"arcsin", asin, asin, 3.12, 2.55}, |
| 118 | {"arccos", acos, acos, 2.1, 1.67}, |
| 119 | {"arctan", atan, atan, 2.3, 2.52}, |
| 120 | {"sinh", sinh, sinh, 1.55, 1.89}, |
| 121 | {"cosh", cosh, cosh, 2.48, 1.97}, |
| 122 | {"tanh", tanh, tanh, 1.38, 1.19}, |
| 123 | {"arcsinh", asinh, asinh, 1.01, 1.48}, |
| 124 | {"arccosh", acosh, acosh, 1.16, 1.05}, |
| 125 | {"arctanh", atanh, atanh, 1.45, 1.46}, |
| 126 | {"cbrt", cbrt, cbrt, 1.94, 1.82}, |
| 127 | //{"exp",exp,exp,3.76,1.53}, |
| 128 | {"exp2", exp2, exp2, 1.01, 1.04}, |
| 129 | {"expm1", expm1, expm1, 2.62, 2.1}, |
| 130 | //{"log",log,log,1.84,1.67}, |
| 131 | {"log10", log10, log10, 3.5, 1.92}, |
| 132 | {"log1p", log1p, log1p, 1.96, 1.93}, |
| 133 | {"log2", log2, log2, 2.12, 1.84}, |
| 134 | }; |
| 135 | |
| 136 | for (int ii = 0; ii < umathfunc.size(); ++ii) { |
| 137 | // ignore sin/cos |
| 138 | if ((umathfunc[ii].name != "sin") && (umathfunc[ii].name != "cos")) { |
| 139 | std::string fileName = |
| 140 | "umath-validation-set-" + umathfunc[ii].name + ".csv"; |
| 141 | std::ofstream txtOut; |
| 142 | txtOut.open(fileName, std::ofstream::trunc); |
| 143 | txtOut << "dtype,input,output,ulperrortol" << std::endl; |
| 144 | |
| 145 | // Single Precision |
| 146 | auto f32in = generate_input_vector<float>(umathfunc[ii].name); |
| 147 | auto f32out = computeTrueVal<float, double>(f32in, |
| 148 | umathfunc[ii].f32func); |
| 149 | for (int jj = 0; jj < f32in.size(); ++jj) { |
| 150 | txtOut << "np.float32" << std::hex << ",0x" |
| 151 | << *reinterpret_cast<uint32_t *>(&f32in[jj]) << ",0x" |
| 152 | << *reinterpret_cast<uint32_t *>(&f32out[jj]) << "," |
| 153 | << ceil(umathfunc[ii].f32ulp) << std::endl; |
| 154 | } |
| 155 | |
| 156 | // Double Precision |
| 157 | auto f64in = generate_input_vector<double>(umathfunc[ii].name); |
| 158 | auto f64out = computeTrueVal<double, long double>( |
| 159 | f64in, umathfunc[ii].f64func); |
| 160 | for (int jj = 0; jj < f64in.size(); ++jj) { |
| 161 | txtOut << "np.float64" << std::hex << ",0x" |
| 162 | << *reinterpret_cast<uint64_t *>(&f64in[jj]) << ",0x" |
| 163 | << *reinterpret_cast<uint64_t *>(&f64out[jj]) << "," |
| 164 | << ceil(umathfunc[ii].f64ulp) << std::endl; |
| 165 | } |
| 166 | txtOut.close(); |