Random Fourier positional encoding for a single (x, y) coordinate coords_norm: normalized to [0, 1], pe_gaussian: PyTorch row-major [2, 128] Output: [256] = [sin(128); cos(128)]
| 10271 | // coords_norm: normalized to [0, 1], pe_gaussian: PyTorch row-major [2, 128] |
| 10272 | // Output: [256] = [sin(128); cos(128)] |
| 10273 | static void sam3_pe_encode_coord(float* out, float x_norm, float y_norm, |
| 10274 | const float* pe_gauss, int num_pos_feats) { |
| 10275 | // Map [0,1] → [-1,1] |
| 10276 | float coords[2] = {2.0f * x_norm - 1.0f, 2.0f * y_norm - 1.0f}; |
| 10277 | |
| 10278 | // coords @ pe_gaussian → [128] |
| 10279 | for (int i = 0; i < num_pos_feats; ++i) { |
| 10280 | float dot = coords[0] * pe_gauss[i] + |
| 10281 | coords[1] * pe_gauss[num_pos_feats + i]; |
| 10282 | dot *= 2.0f * (float)M_PI; |
| 10283 | out[i] = sinf(dot); |
| 10284 | out[i + num_pos_feats] = cosf(dot); |
| 10285 | } |
| 10286 | } |
| 10287 | |
| 10288 | // Read SAM prompt encoder weights from GPU and cache them in state. |
| 10289 | // Also pre-computes the dense PE grid and no-mask tiled embedding. |
no outgoing calls
no test coverage detected