Skip to content

Extends true_divide to be a method#34794

Closed
mruberry wants to merge 10 commits intomasterfrom
future_div
Closed

Extends true_divide to be a method#34794
mruberry wants to merge 10 commits intomasterfrom
future_div

Conversation

@mruberry
Copy link
Copy Markdown
Collaborator

@mruberry mruberry commented Mar 16, 2020

Per title. See related #34570.

In PyTorch 1.7 the plan is for torch.div and Python's division operator to perform "true" division, like Python 3, JAX, and NumPy. To facilitate this change, this PR expands true_divide to be a method so it can cover all of torch.div's use cases.

New true_divide tests are added to test_torch.py, test_type_promotion.py, and test_sparse.py.

@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Mar 16, 2020

💊 CircleCI build failures summary and remediations

As of commit e168911 (more details on the Dr. CI page):


None of the build failures appear to be your fault 💚


  • 1/1 broken upstream at merge base 3cd3f0b since Mar 23

    Please rebase on the viable/strict branch (expand for instructions)

    If your commit is newer than viable/strict, you can try basing on an older, stable commit:

    git fetch https://github.com/pytorch/pytorch viable/strict
    git rebase --onto FETCH_HEAD $(git merge-base origin/master HEAD)
    

    If your commit is older than viable/strict:

    git fetch https://github.com/pytorch/pytorch viable/strict
    git rebase FETCH_HEAD
    

    Check out the recency history of this "viable master" tracking branch.


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

This comment has been revised 33 times.

@mruberry mruberry requested a review from gchanan March 16, 2020 16:22
@mruberry mruberry added module: numpy Related to numpy support, and also numpy compatibility of our operators module: deprecation labels Mar 16, 2020
Comment thread test/test_torch.py Outdated
Comment thread torch/future_div.py Outdated
Mike Ruberry added 2 commits March 19, 2020 05:22
@mruberry mruberry changed the title Adds torch.future_div and extends true_divide to be a method Extends true_divide to be a method Mar 19, 2020
@mruberry mruberry requested a review from gchanan March 19, 2020 16:27
@float_double_default_dtype
def test_true_divide(self, device, dtype):
dividend = torch.randn(5, device=device).to(dtype)
dividend = (torch.randn(5, device=device) * 100).to(dtype)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you multiply by 100?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To make the division more interesting. Example dividends:

(torch.randn(100)).long()
: tensor([ 0,  0, -1, -2,  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1,  0,
         1, -1,  0, -1,  0,  0,  0,  0,  1,  0,  0,  0, -1,  1,  0,  0,  1,  0,
         0,  1,  0,  0,  0,  0, -1, -1,  0, -1,  0,  0,  0, -1,  0,  0, -2,  0,
         0,  0,  1, -1,  0,  0, -1,  0,  0,  0,  0, -1,  1,  0,  0,  0, -1, -1,
         0,  0, -1, -1,  0,  0,  0,  2,  0,  1,  0,  0,  0,  0,  0,  1,  0,  0,
         0,  0,  0,  1, -1,  0,  0,  1,  0,  1])

(torch.randn(100) * 100).long()
: tensor([  54,  113,    7,   69,    4,   98,  -32,  223,  -36,  285, -111,   -6,
         -36,  -43,  122,  -39, -164,  101, -100, -122,   -2,  -70,   40,  121,
          16,   21,    6,   21, -110,  -35, -186,  193,   15,  -21,   75,   61,
         -62,  -27, -116,  -32,  -17, -159, -111,   56,  -28,   59, -117,   63,
         -57,  -49,  210,   93,   11, -107,  -66,   32,   -8, -150,  -20,   46,
           6,   98,  -28,   87,    6, -124,  -81,   42,  -68,  -14,  -39, -149,
         117,   48,  -81, -120, -138,  183,  146,  -43,  -72,  -53,  -93,   67,
         -73, -161,  152,   57, -229,  -37,   59,  -85,   47,  178, -127, -110,
          34,  175,  -11,  -39])

@dtypes(torch.float, torch.double, torch.bool, torch.short, torch.uint8, torch.int, torch.long)
def test_true_divide_out(self, device, dtype):
dividend = torch.randn(5, device=device).to(dtype)
dividend = (torch.randn(5, device=device) * 100).to(dtype)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

See note above.

Comment thread torch/future_div.py Outdated
Comment thread test/test_torch.py Outdated
Comment thread test/test_torch.py Outdated
Comment thread test/test_torch.py Outdated
Comment thread test/test_torch.py Outdated
Comment thread test/test_type_promotion.py Outdated
Copy link
Copy Markdown
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.

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
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.

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
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.

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mruberry merged this pull request in 7c1ea73.

@mruberry mruberry deleted the future_div branch May 16, 2020 05:04
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Per title. See related pytorch#34570.

In PyTorch 1.7 the plan is for torch.div and Python's division operator to perform "true" division, like Python 3, JAX, and NumPy. To facilitate this change, this PR expands true_divide to be a method so it can cover all of torch.div's use cases.

New true_divide tests are added to test_torch.py, test_type_promotion.py, and test_sparse.py.
Pull Request resolved: pytorch#34794

Differential Revision: D20545507

Pulled By: mruberry

fbshipit-source-id: 55286f819716c8823d1930441a69008560ac2bd5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: deprecation module: numpy Related to numpy support, and also numpy compatibility of our operators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants