MCPcopy Create free account
hub / github.com/conflow-dev/ConFlow / emb_ss

Function emb_ss

sgx_tf_ops/Enclave/Enclave.cpp:106–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106void emb_ss(float* input,float* output,int M,int C,int num,int dim){
107 int N = M*num*dim;
108 float *x = (float*)malloc(sizeof(float)*N);
109 memset(x, 0, sizeof(float)*N);
110 for (int i = 0; i < M; i++) {
111 for (int j = 0; j < num; j++) {
112 int idx = static_cast<int>(fabs(input[i*C+j*(dim+1)+dim] * 100))%10;
113 for (int k = 0; k < dim; k++) {
114 x[i*num*dim+j*dim+k] = input[i*C+j*(dim+1)+k] + sgx_arr[idx][k%128];
115 }
116 }
117 }
118 float mean = 0.0f, std, mean_sqr = 0.0f;
119 float c_mean = 0.0f, c_mean_sqr = 0.0f;
120
121 for (int j = 0; j < N; j++) {
122 float y = (x[j]/static_cast<float>(N)) - c_mean;
123 float t = mean + y;
124 c_mean = (t - mean) - y;
125 mean = t;
126
127 float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr;
128 float t2 = mean_sqr + y2;
129 c_mean_sqr = (t2 - mean_sqr) - y2;
130 mean_sqr = t2;
131 }
132 std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt);
133 mean = mean/static_cast<float>(Nt);
134 for(int i=0;i<N*(Ne-1);i++){
135 output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1);
136 }
137 for(int j=N*(Ne-1);j<N*Ne;j++){
138 output[j] = 0.0f;
139 float sum = 0.0f;
140 float c = 0.0f;
141 for(int i=0;i<Nt;i++){
142 float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c;
143 float t = sum + y;
144 c = (t - sum) - y;
145 sum = t;
146 }
147 output[j] =x[j-N*(Ne-1)] + sum;
148 }
149 free(x);
150 return;
151}
152
153void emb_ss_grad(float* grad,float* output,int M,int C,int num,int dim){
154 int N = M*num*dim;

Callers 1

embedding_ssFunction · 0.85

Calls 1

gaussrandFunction · 0.85

Tested by

no test coverage detected