Fix math domain error with log10 (#12841)

fix math domain error with log10
This commit is contained in:
Chen Fu 2022-09-06 11:54:41 -04:00 committed by GitHub
parent 8cedafe250
commit 9ad5b95e4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -343,9 +343,11 @@ def compute_signal_to_quantization_noice_ratio(
left = numpy.concatenate(xlist).flatten()
right = numpy.concatenate(ylist).flatten()
Ps = numpy.linalg.norm(left)
Pn = numpy.linalg.norm(left - right) + numpy.finfo("float").eps
return 20 * math.log10(Ps / Pn)
epsilon = numpy.finfo("float").eps
tensor_norm = max(numpy.linalg.norm(left), epsilon)
diff_norm = max(numpy.linalg.norm(left - right), epsilon)
res = tensor_norm / diff_norm
return 20 * math.log10(res)
def compute_weight_error(