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

Function edgetam_window_unpartition_cpu

sam3.cpp:5580–5604  ·  view source on GitHub ↗

Inverse of window partition: [D, 16, 256] → [D, H, W] spatial layout. Rearranges 256 windows of 16 tokens each back into [D, H*W] feature map. Output has ggml layout [D, W, H] (ne[0]=D, ne[1]=W, ne[2]=H).

Source from the content-addressed store, hash-verified

5578// Rearranges 256 windows of 16 tokens each back into [D, H*W] feature map.
5579// Output has ggml layout [D, W, H] (ne[0]=D, ne[1]=W, ne[2]=H).
5580static void edgetam_window_unpartition_cpu(
5581 const float* src, int D, int H, int W,
5582 int window_size, float* dst) {
5583 const int nw_h = H / window_size;
5584 const int nw_w = W / window_size;
5585 const int ws2 = window_size * window_size;
5586
5587 for (int wh = 0; wh < nw_h; ++wh) {
5588 for (int ww = 0; ww < nw_w; ++ww) {
5589 int win_idx = wh * nw_w + ww;
5590 for (int ph = 0; ph < window_size; ++ph) {
5591 for (int pw = 0; pw < window_size; ++pw) {
5592 int tok_idx = ph * window_size + pw;
5593 int dst_h = wh * window_size + ph;
5594 int dst_w = ww * window_size + pw;
5595 int dst_pos = dst_w + dst_h * W;
5596
5597 const float* s = src + win_idx * (D * ws2) + tok_idx * D;
5598 float* d = dst + dst_pos * D;
5599 memcpy(d, s, D * sizeof(float));
5600 }
5601 }
5602 }
5603 }
5604}
5605
5606static bool edgetam_perceiver_forward(
5607 const sam3_model& model,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected