wip adding packed matcher

master
Ondřej Hruška 9 years ago
parent 26c94c9aef
commit a5f18e9f84
  1. 10
      main.c
  2. 58
      src/vec_match.c
  3. 23
      src/vec_match.h

@ -21,6 +21,8 @@ static float data_cprs[16] = {
static float data_cprs2[16];
static float data_cprs3[16];
int main(void)
{
for (int i = 0; i < 16; i++) {
@ -36,6 +38,14 @@ int main(void)
}
printf("\n");
len = vec_unpack(data_cprs3, 16, data_cprs2, len);
printf("unpacked len = %d\n", len);
for (int i = 0; i < len; i++) {
printf("%.1f, ", data_cprs3[i]);
}
printf("\n");
return 0;

@ -8,11 +8,14 @@
#define SQUARE(a) ((a)*(a))
bool vec_match(const float *data,
const float *ref,
const vec_match_cfg_t *cfg,
float *fuzzy_match_error,
float *abs_match_error)
#define F2ZEROES(f) roundf(-(f))
#define ZEROES2F(z) (0.0f - z)
bool vec_match_do(const float *data, const float *ref,
const vec_match_cfg_t *cfg,
float *fuzzy_match_error, float *abs_match_error,
bool packed)
{
int a, b;
@ -67,8 +70,24 @@ bool vec_match(const float *data,
bool vec_match(const float *data, const float *ref, const vec_match_cfg_t *cfg,
float *fuzzy_match_error, float *abs_match_error)
{
return vec_match_do(data, ref, cfg, fuzzy_match_error, abs_match_error, false);
}
bool vec_match_packed(const float *data, const float *ref, const vec_match_cfg_t *cfg,
float *fuzzy_match_error, float *abs_match_error)
{
return vec_match_do(data, ref, cfg, fuzzy_match_error, abs_match_error, true);
}
uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, uint32_t data_length, float threshold)
uint32_t vec_pack(float *result, uint32_t result_capacity,
const float *data, uint32_t data_length, float threshold)
{
uint32_t result_len = 0;
uint32_t zeroes = 0;
@ -80,7 +99,7 @@ uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, ui
// write zero marker to result
if (zeroes) {
if (result_len < result_capacity) {
result[result_len] = 0.0f - zeroes; // float and negative
result[result_len] = ZEROES2F(zeroes); // float and negative
}
zeroes = 0;
@ -110,3 +129,28 @@ uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, ui
uint32_t vec_unpack(float *result, uint32_t result_capacity,
const float *compr_data, uint32_t compr_length)
{
uint32_t idx = 0;
for (uint32_t i = 0; i < compr_length; i++) {
if (compr_data[i] < 0) {
uint32_t zeroes = F2ZEROES(compr_data[i]);
for (uint32_t j = 0; j < zeroes; j++) {
if (idx < result_capacity) {
result[idx] = 0;
}
idx++;
}
} else {
if (idx < result_capacity) {
result[idx] = compr_data[i];
}
idx++;
}
}
return idx;
}

@ -22,11 +22,7 @@ typedef struct {
* @param abs_match_error error metric calculated from raw data (can be used if envelope match passes)
* @return envelope match status (match using drift and offset)
*/
bool vec_match(const float *data,
const float *ref,
const vec_match_cfg_t *cfg,
float *fuzzy_match_error,
float *abs_match_error);
bool vec_match(const float *data, const float *ref, const vec_match_cfg_t *cfg, float *fuzzy_match_error, float *abs_match_error);
/**
@ -37,11 +33,7 @@ bool vec_match(const float *data,
*
* Params otherwise the same as vec_match()
*/
bool vec_match_packed(const float *data,
const float *ref,
const vec_match_cfg_t *cfg,
float *fuzzy_match_error,
float *abs_match_error);
bool vec_match_packed(const float *data, const float *ref, const vec_match_cfg_t *cfg, float *fuzzy_match_error, float *abs_match_error);
/**
@ -59,11 +51,7 @@ bool vec_match_packed(const float *data,
* @param threshold max value to be considered zero in the compression
* @return length of result vector
*/
uint32_t vec_pack(float *result,
uint32_t result_capacity,
const float *data,
uint32_t length,
float threshold);
uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, uint32_t length, float threshold);
/**
@ -78,7 +66,4 @@ uint32_t vec_pack(float *result,
* @param compr_length compressed data vector length
* @return
*/
uint32_t vec_unpack(float *result,
uint32_t result_capacity,
const float *compr_data,
uint32_t compr_length);
uint32_t vec_unpack(float *result, uint32_t result_capacity, const float *compr_data, uint32_t compr_length);

Loading…
Cancel
Save