{ "info": { "author": "Patrick Hohenecker", "author_email": "mail@paho.at", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "torch-test-case\n===============\n\n\nUsing Python's [`unittest`](https://docs.python.org/3/library/unittest.html) package turns out to be cumbersome when we\nare working with [PyTorch](http://pytorch.org/) and need to write assertions that include tensors, parameters, and so\nforth.\nThe main reason for this is that PyTorch tensors are compared element-wise by default, which is why assertions provided\nby the class [`unittest.TestCase`](https://docs.python.org/3/library/unittest.html#unittest.TestCase) do not work\nout-of-the-box.\nA possible workaround is to use\n[`TestCase.assertTrue`](https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertTrue) for any assertion\nthat we need to make, yet this commonly leads to convoluted code that is hard to read and maintain.\n\nThe module `torchtestcase` defines the class `TorchTestCase`, which extends `unittest.TestCase` such that many\nassertions support instances of various PyTorch classes.\n\n**Updates**:\n- Version 2018.1 has been released, and supports PyTorch 0.4 now.\n- Version 2018.2 has been released, and introduces the specification of a permissible deviation for tensor equality\n assertions.\n\n\nInstallation\n------------\n\nThis module can be installed from PyPI:\n```\npip install torchtestcase\n```\n\n\nPyTorch Assertions\n------------------\n\nThis section describes those assertions provided by the class `TorchTestCase` that support PyTorch.\nIf you are not familiar with the package `unittest`, then read about it first\n[here](https://docs.python.org/3/library/unittest.html).\n\n**Notice**:\nWith the release of PyTorch 0.4.0, tensors and variables have been merged, which means that `Variable`s are treated just\nlike any other tensors, and thus there is no need to make use of the class `torch.autograd.Variable` anymore.\nAccordingly, assertions for `Variable`s in particular have been removed in version 2018.1 of `torchtestcase`.\n\n\n### 1. Equality Assertions\n\n(`assertEqual`, `assertNotEqual`)\n\nEquality assertions support objects that are any kind of PyTorch tensors as well as instances of `torch.nn.Parameter`\nand `torch.nn.utils.rnn.PackedSequence`.\nNotice, however, that an `AssertionError` is raised if the compared objects are instances of different types:\n```python\nself.assertEqual(torch.zeros(4), nn.Parameter(torch.zeros(4))) # -> AssertionError\n```\n\nOccasionally, we do not expect two tensors to match each other exactly, which is the case if we anticipate numerical\ninstabilities, for example.\nFor any such case, `TorchTestCase` provides the possibility to specify a certain tolerance:\n\n```python\nself.eps = 0.001 # specify tolerance for equality assertions\nself.assertEqual(torch.zeros(3), 0.001 * torch.ones(3)) # -> no AssertionError\nself.assertEqual(torch.zeros(3), 0.0011 * torch.ones(3)) # -> AssertionError\n```\nNotice that a specified tolerance is taken into account for **equality assertions** between **two tensors** only. \n\n\n### 2. Order Assertions\n\n(`assertGreater`, `assertGreaterEqual`, `assertLess`, `assertLessEqual`)\n\nIn general, order assertions are assumed to be fulfilled if they hold element-wise.\nFor example:\n```pyhton\nx = torch.FloatTensor([0, 0, 1])\ny = torch.FloatTensor([1, 1, 1])\nself.assertLessEqual(x, y) # -> no AssertionError\nself.assertLess(x, y) # -> AssertionError\n```\nIn addition, it is possible to compare tensors or `Parameters` to a number, in which case each element of the considered\ndata tensor is compared to the same.\nFor example, if we want to ensure that every element of a tensor lies in the unit interval, then we may use the\nfollowing assertions:\n```python\nself.assertGreaterEqual(some_tensor, 0)\nself.assertLessEqual(some_tensor, 1)\n```\nWhen we make order assertions, then we usually do not care about the actual types of the objects involved.\nTherefore, it is possible to compare different kinds of tensors with each other as well as with `Parameter`s:\n```python\nself.assertLess(torch.zeros(3), nn.Parameter(torch.ones(3))) # -> no AssertionError\n```", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/phohenecker/torch-test-case/archive/v2018.2.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/phohenecker/torch-test-case", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "torchtestcase", "package_url": "https://pypi.org/project/torchtestcase/", "platform": "", "project_url": "https://pypi.org/project/torchtestcase/", "project_urls": { "Download": "https://github.com/phohenecker/torch-test-case/archive/v2018.2.tar.gz", "Homepage": "https://github.com/phohenecker/torch-test-case" }, "release_url": "https://pypi.org/project/torchtestcase/2018.2/", "requires_dist": null, "requires_python": "", "summary": "Extends unittest.TestCase such that assertions support PyTorch tensors and parameters.", "version": "2018.2" }, "last_serial": 4301967, "releases": { "2017.1": [ { "comment_text": "", "digests": { "md5": "9852d74cb9359fe1624483c28369069b", "sha256": "f8bb0c4e3216087130f80c4237bb5e4c1e6de629d553f25fd7b85f6e33bf9b34" }, "downloads": -1, "filename": "torchtestcase-2017.1.tar.gz", "has_sig": false, "md5_digest": "9852d74cb9359fe1624483c28369069b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6552, "upload_time": "2017-11-25T17:01:04", "url": "https://files.pythonhosted.org/packages/c6/57/d3e662878691420824b49f09f3bb6aa7c5dfb2148072bce2ec004fd48960/torchtestcase-2017.1.tar.gz" } ], "2018.1": [ { "comment_text": "", "digests": { "md5": "065b5eaa2426fc377eea44f2e9e4ffb0", "sha256": "691b053b0466aed40201e1b41f5a903b4df889a64272a18bcab4b1c8e9091cb4" }, "downloads": -1, "filename": "torchtestcase-2018.1.tar.gz", "has_sig": false, "md5_digest": "065b5eaa2426fc377eea44f2e9e4ffb0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6607, "upload_time": "2018-08-18T11:05:04", "url": "https://files.pythonhosted.org/packages/8b/a8/fee75b874ca3737a456b60f46a797ce46225c7c7f59addf2e8015658efc1/torchtestcase-2018.1.tar.gz" } ], "2018.2": [ { "comment_text": "", "digests": { "md5": "91c8128b64c76bde7ca1033b764a2497", "sha256": "0061cde2eb79f09c9501fae675c52c799371606d52afcff8753c44e1a6254a00" }, "downloads": -1, "filename": "torchtestcase-2018.2.tar.gz", "has_sig": false, "md5_digest": "91c8128b64c76bde7ca1033b764a2497", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7345, "upload_time": "2018-09-23T14:50:05", "url": "https://files.pythonhosted.org/packages/14/4f/947e1332e8f8047feec6da338b976e242cd7c7edbc514bbd72c38e3792c0/torchtestcase-2018.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "91c8128b64c76bde7ca1033b764a2497", "sha256": "0061cde2eb79f09c9501fae675c52c799371606d52afcff8753c44e1a6254a00" }, "downloads": -1, "filename": "torchtestcase-2018.2.tar.gz", "has_sig": false, "md5_digest": "91c8128b64c76bde7ca1033b764a2497", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7345, "upload_time": "2018-09-23T14:50:05", "url": "https://files.pythonhosted.org/packages/14/4f/947e1332e8f8047feec6da338b976e242cd7c7edbc514bbd72c38e3792c0/torchtestcase-2018.2.tar.gz" } ] }