| 288 | |
| 289 | |
| 290 | void ecall_sigmoid(float *input,int N,float *output){ |
| 291 | float *x = (float*)malloc(sizeof(float)*N); |
| 292 | memset(x, 0, sizeof(float)*N); |
| 293 | for(int j=0;j<N;j++){ |
| 294 | x[j] = 0.0f; |
| 295 | float sum = input[insert*N+j]; |
| 296 | float c = 0.0f; |
| 297 | for(int i=0;i<Nt;i++){ |
| 298 | float y = input[indexs[i]*N+j] - c; |
| 299 | float t = sum + y; |
| 300 | c = (t - sum) - y; |
| 301 | sum = t; |
| 302 | } |
| 303 | x[j] = sum; |
| 304 | } |
| 305 | for (int j = 0; j < N; j++) { |
| 306 | x[j]= static_cast<float>(1)/(static_cast<float>(1) + expf(-x[j])); |
| 307 | } |
| 308 | |
| 309 | float mean = 0.0f, std, mean_sqr = 0.0f; |
| 310 | float c_mean = 0.0f, c_mean_sqr = 0.0f; |
| 311 | |
| 312 | for (int j = 0; j < N; j++) { |
| 313 | float y = (x[j] /static_cast<float>(N)) - c_mean; |
| 314 | float t = mean + y; |
| 315 | c_mean = (t - mean) - y; |
| 316 | mean = t; |
| 317 | |
| 318 | float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr; |
| 319 | float t2 = mean_sqr + y2; |
| 320 | c_mean_sqr = (t2 - mean_sqr) - y2; |
| 321 | mean_sqr = t2; |
| 322 | } |
| 323 | std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt); |
| 324 | mean = mean/static_cast<float>(Nt); |
| 325 | for(int i=0;i<N*(Ne-1);i++){ |
| 326 | output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1); |
| 327 | } |
| 328 | for(int j=N*(Ne-1);j<N*Ne;j++){ |
| 329 | output[j] = 0.0f; |
| 330 | float sum = 0.0f; |
| 331 | float c = 0.0f; |
| 332 | for(int i=0;i<Nt;i++){ |
| 333 | float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c; |
| 334 | float t = sum + y; |
| 335 | c = (t - sum) - y; |
| 336 | sum = t; |
| 337 | } |
| 338 | output[j] =x[j-N*(Ne-1)] + sum; |
| 339 | } |
| 340 | free(x); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | void ecall_logloss(float *input,int N,int M,int C,float *label,float *weight,float *output){ |
| 345 | float *x = (float*)malloc(sizeof(float)*N); |