MCPcopy Create free account
hub / github.com/MegEngine/MegCC / main

Function main

ci/compare_vec.c:96–129  ·  view source on GitHub ↗

two bin file which has 1024 float, compute similarity score

Source from the content-addressed store, hash-verified

94}
95//! two bin file which has 1024 float, compute similarity score
96int main(int argn, void** args) {
97 float alpha = 2.297190;
98 float beta = -2.659770;
99 float threshold = 55.3;
100 int feature_size = 4096;
101 float* buffer_a = read_file((char*)(args[1]));
102 float* buffer_b = read_file((char*)(args[2]));
103
104 water(seed, (unsigned char*)buffer_a, feature_size);
105 water(seed, (unsigned char*)buffer_b, feature_size);
106
107 water(seed, (unsigned char*)buffer_a, feature_size);
108 water(seed, (unsigned char*)buffer_b, feature_size);
109
110 float score = 1e38f;
111 size_t feature_size_in_float = feature_size / sizeof(float);
112 /**
113 * whole buffer is a complete feature without being seperate into two
114 * segments
115 */
116 size_t start = 0;
117 size_t end = feature_size_in_float;
118 float distance = 0;
119 for (size_t i = start; i < end; i++) {
120 distance += (buffer_a[i] - buffer_b[i]) * (buffer_a[i] - buffer_b[i]);
121 }
122 float score_full = (float)(100.0f / (1.0 + exp(alpha * distance + beta)));
123
124 score = piecewise_normalize(score_full, 0.f, 100.f, threshold, 0, 100, 80);
125
126 printf("---->>>full_score=%f, score=%f, distance %f\n", score_full, score,
127 distance);
128 return 0;
129}

Callers

nothing calls this directly

Calls 3

read_fileFunction · 0.70
waterFunction · 0.70
piecewise_normalizeFunction · 0.70

Tested by

no test coverage detected