| 1256 | } |
| 1257 | |
| 1258 | void ecall_exp(float *input, int N, float *output) { |
| 1259 | float *x = (float*)malloc(sizeof(float)*N); |
| 1260 | memset(x, 0, sizeof(float)*N); |
| 1261 | for(int j=0;j<N;j++){ |
| 1262 | x[j] = 0.0f; |
| 1263 | float sum = input[insert*N+j]; |
| 1264 | float c = 0.0f; |
| 1265 | for(int i=0;i<Nt;i++){ |
| 1266 | float y = input[indexs[i]*N+j] - c; |
| 1267 | float t = sum + y; |
| 1268 | c = (t - sum) - y; |
| 1269 | sum = t; |
| 1270 | } |
| 1271 | x[j] = sum; |
| 1272 | |
| 1273 | } |
| 1274 | |
| 1275 | for (int j = 0; j < N; j++) { |
| 1276 | x[j] = expf(x[j]); |
| 1277 | } |
| 1278 | |
| 1279 | float mean = 0.0f, std, mean_sqr = 0.0f; |
| 1280 | float c_mean = 0.0f, c_mean_sqr = 0.0f; |
| 1281 | for (int j = 0; j < N; j++) { |
| 1282 | float y = (x[j]/static_cast<float>(N)) - c_mean; |
| 1283 | float t = mean + y; |
| 1284 | c_mean = (t - mean) - y; |
| 1285 | mean = t; |
| 1286 | |
| 1287 | float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr; |
| 1288 | float t2 = mean_sqr + y2; |
| 1289 | c_mean_sqr = (t2 - mean_sqr) - y2; |
| 1290 | mean_sqr = t2; |
| 1291 | } |
| 1292 | std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt); |
| 1293 | mean = mean/static_cast<float>(Nt); |
| 1294 | for(int i=0;i<N*(Ne-1);i++){ |
| 1295 | output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1); |
| 1296 | } |
| 1297 | for(int j=N*(Ne-1);j<N*Ne;j++){ |
| 1298 | output[j] = 0.0f; |
| 1299 | float sum = 0.0f; |
| 1300 | float c = 0.0f; |
| 1301 | for(int i=0;i<Nt;i++){ |
| 1302 | float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c; |
| 1303 | float t = sum + y; |
| 1304 | c = (t - sum) - y; |
| 1305 | sum = t; |
| 1306 | } |
| 1307 | output[j] =x[j-N*(Ne-1)] + sum; |
| 1308 | } |
| 1309 | free(x); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | void ecall_exp_grad(float *input, float *grad, int N, float *output) { |
| 1314 | float *x = (float*)malloc(sizeof(float)*N); |