| 722 | } |
| 723 | |
| 724 | void ecall_softplus(float *input,int N,float *output){ |
| 725 | float *x = (float*)malloc(sizeof(float)*N); |
| 726 | memset(x, 0, sizeof(float)*N); |
| 727 | for(int j=0;j<N;j++){ |
| 728 | x[j] = 0.0f; |
| 729 | float sum = input[insert*N+j]; |
| 730 | float c = 0.0f; |
| 731 | for(int i=0;i<Nt;i++){ |
| 732 | float y = input[indexs[i]*N+j] - c; |
| 733 | float t = sum + y; |
| 734 | c = (t - sum) - y; |
| 735 | sum = t; |
| 736 | } |
| 737 | x[j] = sum; |
| 738 | } |
| 739 | |
| 740 | for (int j = 0; j < N; j++) { |
| 741 | if(x[j] > 50.0f){ |
| 742 | x[j] = x[j]; |
| 743 | } |
| 744 | else if(x[j] < -50.0f){ |
| 745 | x[j] = 0.0f; |
| 746 | } |
| 747 | else{ |
| 748 | x[j]= logf(static_cast<float>(1)+expf(x[j])); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | float mean = 0.0f, std, mean_sqr = 0.0f; |
| 753 | float c_mean = 0.0f, c_mean_sqr = 0.0f; |
| 754 | |
| 755 | for (int j = 0; j < N; j++) { |
| 756 | float y = (x[j]/static_cast<float>(N)) - c_mean; |
| 757 | float t = mean + y; |
| 758 | c_mean = (t - mean) - y; |
| 759 | mean = t; |
| 760 | |
| 761 | float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr; |
| 762 | float t2 = mean_sqr + y2; |
| 763 | c_mean_sqr = (t2 - mean_sqr) - y2; |
| 764 | mean_sqr = t2; |
| 765 | } |
| 766 | std = sqrtf(fabs(mean_sqr - mean * mean))/static_cast<float>(Nt); |
| 767 | mean = mean/static_cast<float>(Nt); |
| 768 | for(int i=0;i<N*(Ne-1);i++){ |
| 769 | output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1); |
| 770 | } |
| 771 | for(int j=N*(Ne-1);j<N*Ne;j++){ |
| 772 | output[j] = 0.0f; |
| 773 | float sum = 0.0f; |
| 774 | float c = 0.0f; |
| 775 | for(int i=0;i<Nt;i++){ |
| 776 | float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c; |
| 777 | float t = sum + y; |
| 778 | c = (t - sum) - y; |
| 779 | sum = t; |
| 780 | } |
| 781 | output[j] =x[j-N*(Ne-1)] + sum; |