| 1383 | } |
| 1384 | |
| 1385 | void ecall_sign(float *input,int N,float *output){ |
| 1386 | float *x = (float*)malloc(sizeof(float)*N); |
| 1387 | memset(x, 0, sizeof(float)*N); |
| 1388 | for(int j=0;j<N;j++){ |
| 1389 | x[j] = 0.0f; |
| 1390 | float sum = input[insert*N+j]; |
| 1391 | float c = 0.0f; |
| 1392 | for(int i=0;i<Nt;i++){ |
| 1393 | float y = input[indexs[i]*N+j] - c; |
| 1394 | float t = sum + y; |
| 1395 | c = (t - sum) - y; |
| 1396 | sum = t; |
| 1397 | } |
| 1398 | x[j] = sum; |
| 1399 | |
| 1400 | } |
| 1401 | |
| 1402 | for (int j = 0; j < N; j++) { |
| 1403 | if(fabs(x[j]) < 1e-7f){ |
| 1404 | x[j] = 0.0f; |
| 1405 | } |
| 1406 | else if(x[j] >= 1e-7f){ |
| 1407 | x[j] = 1.0f; |
| 1408 | } |
| 1409 | else{ |
| 1410 | x[j] = -1.0f; |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | float mean = 0.0f, std, mean_sqr = 0.0f; |
| 1415 | float c_mean = 0.0f, c_mean_sqr = 0.0f; |
| 1416 | for (int j = 0; j < N; j++) { |
| 1417 | float y = (x[j]/static_cast<float>(N)) - c_mean; |
| 1418 | float t = mean + y; |
| 1419 | c_mean = (t - mean) - y; |
| 1420 | mean = t; |
| 1421 | |
| 1422 | float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr; |
| 1423 | float t2 = mean_sqr + y2; |
| 1424 | c_mean_sqr = (t2 - mean_sqr) - y2; |
| 1425 | mean_sqr = t2; |
| 1426 | } |
| 1427 | std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt); |
| 1428 | mean = mean/static_cast<float>(Nt); |
| 1429 | for(int i=0;i<N*(Ne-1);i++){ |
| 1430 | output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1); |
| 1431 | } |
| 1432 | for(int j=N*(Ne-1);j<N*Ne;j++){ |
| 1433 | output[j] = 0.0f; |
| 1434 | float sum = 0.0f; |
| 1435 | float c = 0.0f; |
| 1436 | for(int i=0;i<Nt;i++){ |
| 1437 | float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c; |
| 1438 | float t = sum + y; |
| 1439 | c = (t - sum) - y; |
| 1440 | sum = t; |
| 1441 | } |
| 1442 | output[j] =x[j-N*(Ne-1)] + sum; |