MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_sem_diffuse

Function cbm_sem_diffuse

src/semantic/semantic.c:1664–1683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1662/* ── Graph diffusion ─────────────────────────────────────────────── */
1663
1664void cbm_sem_diffuse(cbm_sem_vec_t *combined, const cbm_sem_vec_t *neighbors, int neighbor_count,
1665 float alpha) {
1666 if (!combined || !neighbors || neighbor_count <= 0) {
1667 return;
1668 }
1669 /* Blend: combined = (1-α) × combined + α × mean(neighbors) */
1670 cbm_sem_vec_t mean;
1671 memset(&mean, 0, sizeof(mean));
1672 for (int n = 0; n < neighbor_count; n++) {
1673 for (int i = 0; i < CBM_SEM_DIM; i++) {
1674 mean.v[i] += neighbors[n].v[i];
1675 }
1676 }
1677 float inv_n = CBM_SEM_UNIT_POS / (float)neighbor_count;
1678 float one_minus_alpha = CBM_SEM_UNIT_POS - alpha;
1679 for (int i = 0; i < CBM_SEM_DIM; i++) {
1680 combined->v[i] = (one_minus_alpha * combined->v[i]) + (alpha * mean.v[i] * inv_n);
1681 }
1682 cbm_sem_normalize(combined);
1683}

Callers 1

test_semantic.cFile · 0.85

Calls 1

cbm_sem_normalizeFunction · 0.85

Tested by

no test coverage detected