Skip to content

Conversation

@xmnlab
Copy link
Contributor

@xmnlab xmnlab commented Feb 7, 2019

This PR fixes #15683

@xmnlab xmnlab changed the title [WIP] Added scientific notation on set_printoptions Added scientific notation on set_printoptions Feb 8, 2019
@xmnlab
Copy link
Contributor Author

xmnlab commented Feb 8, 2019

It seems it is done for a review. I am just not sure where should I add tests for this and how to test it. I just find one usage of torch.set_printoptions one time and in just one file test_nn.

any thoughts?

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks a lot!

Could you just add some tests for this?
Probably following the same as in

pytorch/test/test_torch.py

Lines 8900 to 8903 in f032962

# test scientific notation
x = torch.tensor([1e28, 1e-28])
self.assertEqual(x.__repr__(), str(x))
self.assertExpectedInline(str(x), '''tensor([1.0000e+28, 1.0000e-28])''')

@xmnlab
Copy link
Contributor Author

xmnlab commented Feb 8, 2019

thanks @fmassa for the feedback! I just added the tests for the scientific notation options.

@xmnlab xmnlab force-pushed the allow_scientific_notation branch from 5bd84b1 to 2e934c7 Compare February 8, 2019 23:40
@ezyang
Copy link
Contributor

ezyang commented Feb 10, 2019

Test failures llook legit:

Feb 10 00:22:38 ======================================================================
Feb 10 00:22:38 FAIL: test_print (__main__.TestTorch)
Feb 10 00:22:38 ----------------------------------------------------------------------
Feb 10 00:22:38 Traceback (most recent call last):
Feb 10 00:22:38   File \"test_torch.py\", line 8937, in test_print
Feb 10 00:22:38     self.assertExpectedInline(str(x), expected_str)
Feb 10 00:22:38   File \"/var/lib/jenkins/workspace/test/expecttest.py\", line 195, in assertExpectedInline
Feb 10 00:22:38     self.assertMultiLineEqual(expect, actual, msg=help_text)
Feb 10 00:22:38 AssertionError: 'tensor([ 0.0000e+00, 9.8813e-324, 9.8813e-323, 1.0[62 chars]t64)' != 'tensor([     0.0000,      0.0000,      0.0000, 999[666 chars]t64)'
Feb 10 00:22:38 - tensor([ 0.0000e+00, 9.8813e-324, 9.8813e-323, 1.0000e+307, 1.0000e+308,
Feb 10 00:22:38 + tensor([     0.0000,      0.0000,      0.0000, 9999999999999999860310597602564577717002641838126363875249660735883565852672743849064846414228960666786379280392654615393353172850252103336275952370615397010730691664689375178569039851073146339641623266071126720011020169553304018596457812688561947201171488461172921822139066929851282122002676667750021070848.0000, 100000000000000001097906362944045541740492309677311846336810682903157585404911491537163328978494688899061249669721172515611590283743140088328307009198146046031271664502933027185697489699588559043338384466165001178426897626212945177628091195786707458122783970171784415105291802893207873272974885715430223118336.0000,
Feb 10 00:22:38                   inf], dtype=torch.float64) : To accept the new output, re-run test with envvar EXPECTTEST_ACCEPT=1 (we recommend staging/committing your changes before doing this)
Feb 10 00:22:38

Added tests for scientific notation options

Fixed scientific notation output.

Fixed issue when sci_mode==None
@xmnlab xmnlab force-pushed the allow_scientific_notation branch from 95b2c56 to 823a6b3 Compare February 10, 2019 21:18
@xmnlab
Copy link
Contributor Author

xmnlab commented Feb 10, 2019

thanks for the feedback @ezyang . It seems it is working now!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soumith is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow scientific notation to be enabled or disabled

4 participants