MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / sam3_pe_encode_coord

Function sam3_pe_encode_coord

sam3.cpp:10273–10286  ·  view source on GitHub ↗

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)]

Source from the content-addressed store, hash-verified

10271// coords_norm: normalized to [0, 1], pe_gaussian: PyTorch row-major [2, 128]
10272// Output: [256] = [sin(128); cos(128)]
10273static 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.

Callers 3

sam3_populate_pe_cacheFunction · 0.85
sam3_segment_pvsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected