-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdquant_log_cpu.cc
More file actions
31 lines (27 loc) · 779 Bytes
/
Copy pathdquant_log_cpu.cc
File metadata and controls
31 lines (27 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include "quant.h"
#include "dquant_log_cpu.h"
// Applies the threshold such that values <= threshold are 0
// Maps the remaining range of values to the values 0:(2^bits)-1
// Overwrites data with the new values
void dquant_log_cpu(int len, float *data, int bits, float threshold, float maxVal)
{
int count = len * len;
int base = (1 << (bits-1)) - 1;
float lmax = logf(maxVal/threshold);
for (int idx = 0; idx < count; idx++ )
{
if (data[idx] != 0)
{
int sign=data[idx]/fabsf(data[idx]);
float lnVal=fabsf(data[idx]*(lmax/base));
data[idx] = sign*threshold*expf(lnVal);
}
}
}