Last active
August 20, 2016 08:37
-
-
Save dela3499/cb226b47d8c9296b8020395be7fb0c0c to your computer and use it in GitHub Desktop.
Pattern of error when reducing precision in floats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
figsize(10,5) | |
x = np.linspace(-10,10,10000) | |
y1 = x.astype(np.float32) | |
y2 = x.astype(np.float16) | |
# plt.semilogy(np.abs(x - x)) | |
plt.semilogy(np.abs(x - y1)) | |
plt.semilogy(np.abs(x - y2)) | |
plt.legend(['32','16']) | |
label('Original value','Error','Error when reducing precision of 64-bit floats') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
execfile('/home/carlos/projects/utils/utils.py') | |
%matplotlib inline | |
figsize(50,10) | |
l = 1e-2 | |
alpha = 0.1 | |
x = np.linspace(-l,l,1000000) | |
y1 = x.astype(np.float32) | |
y2 = x.astype(np.float16) | |
plt.semilogy(np.abs(x - y1), '.', alpha = alpha) | |
plt.semilogy(np.abs(x - y2), '.', alpha = alpha) | |
plt.legend(['32','16']) | |
label('Original value','Error','Error when reducing precision of 64-bit floats') |
Author
dela3499
commented
Apr 19, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment