New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serialization fails for double values when format = 'ascii' #3
Comments
wow, that's a big catch. |
Bug is from THDiskFile.c line 308ish Default print and scan precision of fscanf and fprint is 6 digits (actually there's no standard I think). It's better if we use %a for fprintf and fscanf so that the results will be exact. |
but I cant send in a simple pull request to fix this, because it would break existing saved files. |
I don't think ascii is appropriate for conserving precision. This could cause the size of exported files to explode. Isn't it better to use binary format if you want to conserve full precision? It is faster to read/write and much smaller file size. |
Ascii is needed for cross-platform compatibility (see other issues wrt On Thu, Feb 27, 2014 at 4:07 PM, koray kavukcuoglu <notifications@github.com
|
Note sure what to do here.
|
%a would be ideal but it is not C89. So maybe increasing the precision a bit makes sense. |
%f by default would be 6 digits I think unless you specify explicit number of digits to pick up for decimal and fractional parta |
Increasing the precision is probably enough at this point. Maybe twice as much as we have now? |
When serializing an object using format == 'ascii', the values of number objects are truncated to 6 significant digits. Thus the loaded value can differ from the saved value.
Example program to illustrate this:
require 'torch'
local x = 913062344
local file = 'test_torch_save_load.data'
local format = 'ascii'
torch.save(file, x, format)
local y = torch.load(file, format)
print(x, y)
assert(x == y)
print('ok')
The text was updated successfully, but these errors were encountered: