def finiteprecision(self, coeff=None, totalbits=None, shiftbits=None):
if coeff is None:
coeff = self.coefficients
if totalbits is None:
totalbits = self.totalbits
if shiftbits is None:
shiftbits = self.shiftbits
res = coeff * 0 + coeff
for x in np.nditer(res, op_flags=['readwrite']):
xr = np.round(x * 2 ** shiftbits)
xmax = 2 ** (totalbits - 1)
if xr == 0 and xr != 0:
logger.warning("One value was rounded off to zero: Increase "
"shiftbits in fpga design if this is a "
"problem!")
elif xr > xmax - 1:
xr = xmax - 1
logger.warning("One value saturates positively: Increase "
"totalbits or decrease gain!")
elif xr < -xmax:
xr = -xmax
logger.warning("One value saturates negatively: Increase "
"totalbits or decrease gain!")
x[...] = 2 ** (-shiftbits) * xr
return res
评论列表
文章目录