| 998 | } |
| 999 | |
| 1000 | Mat embedding(const Mat &x, const Mat &weight, const Option &opt) { |
| 1001 | if (x.empty() || weight.empty()) return {}; |
| 1002 | Mat output(weight.w, x.w * x.h); |
| 1003 | if (output.empty()) return {}; |
| 1004 | |
| 1005 | #pragma omp parallel for num_threads(opt.num_threads) |
| 1006 | for (int i = 0; i < x.c; i++){ |
| 1007 | const float *x_p = x.channel(i); |
| 1008 | const float *w_p = weight.channel(i); |
| 1009 | float *ptr = output.channel(i); |
| 1010 | for (int j = 0; j < x.w * x.h; j++) { |
| 1011 | int word_index = static_cast<int>(x_p[j]); |
| 1012 | memcpy(ptr, w_p + weight.w * word_index, weight.w * sizeof(float)); |
| 1013 | ptr += output.w; |
| 1014 | } |
| 1015 | } |
| 1016 | return output; |
| 1017 | } |
| 1018 | |
| 1019 | Mat flip(const Mat &x, const Option &opt, int dim) { |
| 1020 | Mat output; |
no test coverage detected