| 2729 | } |
| 2730 | |
| 2731 | void ecall_huberloss(float* pred,float* real,float* delta, int N,int C,int B, float* output){ |
| 2732 | float *x = (float*)malloc(sizeof(float)*N); |
| 2733 | memset(x, 0, sizeof(float)*N); |
| 2734 | for(int j=0;j<N;j++){ |
| 2735 | x[j] = 0.0f; |
| 2736 | float sum = pred[insert*N+j]; |
| 2737 | float c = 0.0f; |
| 2738 | for(int i=0;i<Nt;i++){ |
| 2739 | float y = pred[indexs[i]*N+j] - c; |
| 2740 | float t = sum + y; |
| 2741 | c = (t - sum) - y; |
| 2742 | sum = t; |
| 2743 | } |
| 2744 | x[j] = sum; |
| 2745 | } |
| 2746 | |
| 2747 | float *y = (float*)malloc(sizeof(float)*N); |
| 2748 | memset(y, 0, sizeof(float)*N); |
| 2749 | for(int j=0;j<N;j++){ |
| 2750 | y[j] = 0.0f; |
| 2751 | float sum = real[insert*N+j]; |
| 2752 | float c = 0.0f; |
| 2753 | for(int i=0;i<Nt;i++){ |
| 2754 | float z = real[indexs[i]*N+j] - c; |
| 2755 | float t = sum + z; |
| 2756 | c = (t - sum) - z; |
| 2757 | sum = t; |
| 2758 | } |
| 2759 | y[j] = sum; |
| 2760 | } |
| 2761 | int tmp_n = N/B; |
| 2762 | float delta_tmp; |
| 2763 | for (int j = 0; j < N; j++){ |
| 2764 | if(C == 1){ |
| 2765 | delta_tmp = delta[0]; |
| 2766 | } |
| 2767 | else if(C == B){ |
| 2768 | delta_tmp = delta[j/tmp_n]; |
| 2769 | } |
| 2770 | else{ |
| 2771 | delta_tmp = delta[j]; |
| 2772 | } |
| 2773 | |
| 2774 | if(fabs(y[j]-x[j]) <= delta_tmp ){ |
| 2775 | x[j] = (y[j]-x[j])*(y[j]-x[j])/static_cast<float>(2); |
| 2776 | } |
| 2777 | else if((y[j]-x[j]) > delta_tmp){ |
| 2778 | x[j] = delta_tmp*(y[j]-x[j])-(delta_tmp*delta_tmp/static_cast<float>(2)); |
| 2779 | } |
| 2780 | else{ |
| 2781 | x[j] = delta_tmp*(x[j]-y[j])-(delta_tmp*delta_tmp/static_cast<float>(2)); |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | float mean = 0.0f, std, mean_sqr = 0.0f; |
| 2786 | float c_mean = 0.0f, c_mean_sqr = 0.0f; |
| 2787 | |
| 2788 | for (int j = 0; j < N; j++) { |