PyTorch mapping operators to functions
What are all the PyTorch operators, and what are their function equivalents?
Eg, is a @ b
equivalent to a.mm(b)
or a.matmul(b)
?
I'm after a canonical listing of operator -> function mappings.
I'd be happy to be given a PyTorch documentation link as an answer - my googlefu couldn't track it down.
pytorch
add a comment |
What are all the PyTorch operators, and what are their function equivalents?
Eg, is a @ b
equivalent to a.mm(b)
or a.matmul(b)
?
I'm after a canonical listing of operator -> function mappings.
I'd be happy to be given a PyTorch documentation link as an answer - my googlefu couldn't track it down.
pytorch
1
Got you! I will check and see if I find something, but I'm afraid there is no (official) doc link for this.
– blue-phoenox
Nov 19 '18 at 9:45
Even though it is not that clear as a Doc Link, here are the actual definitions of the operators i.e.+
and__add__
: github.com/pytorch/pytorch/blob/… is not the current version, I haven't found such a clear definition in the current version, but I guess there hasn't changed too much) So you can check what is called then.@
is defined by__matmul__
. For the rest you check on this python docs site Hope this is helpful.
– blue-phoenox
Nov 19 '18 at 10:31
@blue-phoenox Given those two links, how do I deduce that@
->matmul
?
– Tom Hale
Nov 19 '18 at 10:54
Strange, I've had two answers which were deleted, but no question upvotes yet. It's worth answering but not upvoting?
– Tom Hale
Nov 19 '18 at 10:55
Check this and check this: stackoverflow.com/questions/27385633/… And check for the__matmul__
function in the given (first) link.
– blue-phoenox
Nov 19 '18 at 10:56
add a comment |
What are all the PyTorch operators, and what are their function equivalents?
Eg, is a @ b
equivalent to a.mm(b)
or a.matmul(b)
?
I'm after a canonical listing of operator -> function mappings.
I'd be happy to be given a PyTorch documentation link as an answer - my googlefu couldn't track it down.
pytorch
What are all the PyTorch operators, and what are their function equivalents?
Eg, is a @ b
equivalent to a.mm(b)
or a.matmul(b)
?
I'm after a canonical listing of operator -> function mappings.
I'd be happy to be given a PyTorch documentation link as an answer - my googlefu couldn't track it down.
pytorch
pytorch
edited Nov 19 '18 at 11:25
Tom Hale
asked Nov 19 '18 at 7:22
Tom HaleTom Hale
6,6264152
6,6264152
1
Got you! I will check and see if I find something, but I'm afraid there is no (official) doc link for this.
– blue-phoenox
Nov 19 '18 at 9:45
Even though it is not that clear as a Doc Link, here are the actual definitions of the operators i.e.+
and__add__
: github.com/pytorch/pytorch/blob/… is not the current version, I haven't found such a clear definition in the current version, but I guess there hasn't changed too much) So you can check what is called then.@
is defined by__matmul__
. For the rest you check on this python docs site Hope this is helpful.
– blue-phoenox
Nov 19 '18 at 10:31
@blue-phoenox Given those two links, how do I deduce that@
->matmul
?
– Tom Hale
Nov 19 '18 at 10:54
Strange, I've had two answers which were deleted, but no question upvotes yet. It's worth answering but not upvoting?
– Tom Hale
Nov 19 '18 at 10:55
Check this and check this: stackoverflow.com/questions/27385633/… And check for the__matmul__
function in the given (first) link.
– blue-phoenox
Nov 19 '18 at 10:56
add a comment |
1
Got you! I will check and see if I find something, but I'm afraid there is no (official) doc link for this.
– blue-phoenox
Nov 19 '18 at 9:45
Even though it is not that clear as a Doc Link, here are the actual definitions of the operators i.e.+
and__add__
: github.com/pytorch/pytorch/blob/… is not the current version, I haven't found such a clear definition in the current version, but I guess there hasn't changed too much) So you can check what is called then.@
is defined by__matmul__
. For the rest you check on this python docs site Hope this is helpful.
– blue-phoenox
Nov 19 '18 at 10:31
@blue-phoenox Given those two links, how do I deduce that@
->matmul
?
– Tom Hale
Nov 19 '18 at 10:54
Strange, I've had two answers which were deleted, but no question upvotes yet. It's worth answering but not upvoting?
– Tom Hale
Nov 19 '18 at 10:55
Check this and check this: stackoverflow.com/questions/27385633/… And check for the__matmul__
function in the given (first) link.
– blue-phoenox
Nov 19 '18 at 10:56
1
1
Got you! I will check and see if I find something, but I'm afraid there is no (official) doc link for this.
– blue-phoenox
Nov 19 '18 at 9:45
Got you! I will check and see if I find something, but I'm afraid there is no (official) doc link for this.
– blue-phoenox
Nov 19 '18 at 9:45
Even though it is not that clear as a Doc Link, here are the actual definitions of the operators i.e.
+
and __add__
: github.com/pytorch/pytorch/blob/… is not the current version, I haven't found such a clear definition in the current version, but I guess there hasn't changed too much) So you can check what is called then. @
is defined by __matmul__
. For the rest you check on this python docs site Hope this is helpful.– blue-phoenox
Nov 19 '18 at 10:31
Even though it is not that clear as a Doc Link, here are the actual definitions of the operators i.e.
+
and __add__
: github.com/pytorch/pytorch/blob/… is not the current version, I haven't found such a clear definition in the current version, but I guess there hasn't changed too much) So you can check what is called then. @
is defined by __matmul__
. For the rest you check on this python docs site Hope this is helpful.– blue-phoenox
Nov 19 '18 at 10:31
@blue-phoenox Given those two links, how do I deduce that
@
-> matmul
?– Tom Hale
Nov 19 '18 at 10:54
@blue-phoenox Given those two links, how do I deduce that
@
-> matmul
?– Tom Hale
Nov 19 '18 at 10:54
Strange, I've had two answers which were deleted, but no question upvotes yet. It's worth answering but not upvoting?
– Tom Hale
Nov 19 '18 at 10:55
Strange, I've had two answers which were deleted, but no question upvotes yet. It's worth answering but not upvoting?
– Tom Hale
Nov 19 '18 at 10:55
Check this and check this: stackoverflow.com/questions/27385633/… And check for the
__matmul__
function in the given (first) link.– blue-phoenox
Nov 19 '18 at 10:56
Check this and check this: stackoverflow.com/questions/27385633/… And check for the
__matmul__
function in the given (first) link.– blue-phoenox
Nov 19 '18 at 10:56
add a comment |
2 Answers
2
active
oldest
votes
This defines tensor operations for 0.3.1 (it does also contain the definitions of the other operators):
https://pytorch.org/docs/0.3.1/_modules/torch/tensor.html
The code for the current stable has been rearranged (I guess they do more in C now), but since the behaviour of matrix multiplication hasn't changed, I think it is save to assume that this is still valid.
See for the definition of __matmul__
:
def __matmul__(self, other):
if not torch.is_tensor(other):
return NotImplemented
return self.matmul(other)
and
def matmul(self, other):
r"""Matrix product of two tensors.
See :func:`torch.matmul`."""
return torch.matmul(self, other)
The operator @
was introduced with PEP 465 and is mapped to __matmul__
.
See also here for this:
What is the '@=' symbol for in Python?
1
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
add a comment |
The Python documentation table Mapping Operators to Functions provides canonical mappings from:
operator -> __function__()
Eg:
Matrix Multiplication a @ b matmul(a, b)
Elsewhere on the page, you will see the __matmul__
name as an alternate to matmul
.
The definitions of the PyTorch __functions__
are found either in:
The
torch.Tensor
module documentationpython_variable_methods.cpp
You can look up the documentation for the named functions at:
https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370003%2fpytorch-mapping-operators-to-functions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This defines tensor operations for 0.3.1 (it does also contain the definitions of the other operators):
https://pytorch.org/docs/0.3.1/_modules/torch/tensor.html
The code for the current stable has been rearranged (I guess they do more in C now), but since the behaviour of matrix multiplication hasn't changed, I think it is save to assume that this is still valid.
See for the definition of __matmul__
:
def __matmul__(self, other):
if not torch.is_tensor(other):
return NotImplemented
return self.matmul(other)
and
def matmul(self, other):
r"""Matrix product of two tensors.
See :func:`torch.matmul`."""
return torch.matmul(self, other)
The operator @
was introduced with PEP 465 and is mapped to __matmul__
.
See also here for this:
What is the '@=' symbol for in Python?
1
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
add a comment |
This defines tensor operations for 0.3.1 (it does also contain the definitions of the other operators):
https://pytorch.org/docs/0.3.1/_modules/torch/tensor.html
The code for the current stable has been rearranged (I guess they do more in C now), but since the behaviour of matrix multiplication hasn't changed, I think it is save to assume that this is still valid.
See for the definition of __matmul__
:
def __matmul__(self, other):
if not torch.is_tensor(other):
return NotImplemented
return self.matmul(other)
and
def matmul(self, other):
r"""Matrix product of two tensors.
See :func:`torch.matmul`."""
return torch.matmul(self, other)
The operator @
was introduced with PEP 465 and is mapped to __matmul__
.
See also here for this:
What is the '@=' symbol for in Python?
1
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
add a comment |
This defines tensor operations for 0.3.1 (it does also contain the definitions of the other operators):
https://pytorch.org/docs/0.3.1/_modules/torch/tensor.html
The code for the current stable has been rearranged (I guess they do more in C now), but since the behaviour of matrix multiplication hasn't changed, I think it is save to assume that this is still valid.
See for the definition of __matmul__
:
def __matmul__(self, other):
if not torch.is_tensor(other):
return NotImplemented
return self.matmul(other)
and
def matmul(self, other):
r"""Matrix product of two tensors.
See :func:`torch.matmul`."""
return torch.matmul(self, other)
The operator @
was introduced with PEP 465 and is mapped to __matmul__
.
See also here for this:
What is the '@=' symbol for in Python?
This defines tensor operations for 0.3.1 (it does also contain the definitions of the other operators):
https://pytorch.org/docs/0.3.1/_modules/torch/tensor.html
The code for the current stable has been rearranged (I guess they do more in C now), but since the behaviour of matrix multiplication hasn't changed, I think it is save to assume that this is still valid.
See for the definition of __matmul__
:
def __matmul__(self, other):
if not torch.is_tensor(other):
return NotImplemented
return self.matmul(other)
and
def matmul(self, other):
r"""Matrix product of two tensors.
See :func:`torch.matmul`."""
return torch.matmul(self, other)
The operator @
was introduced with PEP 465 and is mapped to __matmul__
.
See also here for this:
What is the '@=' symbol for in Python?
answered Nov 19 '18 at 11:08
blue-phoenoxblue-phoenox
4,04691543
4,04691543
1
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
add a comment |
1
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
1
1
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
Cheers! FYI, I think I found the canonical answer
– Tom Hale
Nov 19 '18 at 11:24
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
@TomHale That's of course preferable! :)
– blue-phoenox
Nov 19 '18 at 11:27
add a comment |
The Python documentation table Mapping Operators to Functions provides canonical mappings from:
operator -> __function__()
Eg:
Matrix Multiplication a @ b matmul(a, b)
Elsewhere on the page, you will see the __matmul__
name as an alternate to matmul
.
The definitions of the PyTorch __functions__
are found either in:
The
torch.Tensor
module documentationpython_variable_methods.cpp
You can look up the documentation for the named functions at:
https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>
add a comment |
The Python documentation table Mapping Operators to Functions provides canonical mappings from:
operator -> __function__()
Eg:
Matrix Multiplication a @ b matmul(a, b)
Elsewhere on the page, you will see the __matmul__
name as an alternate to matmul
.
The definitions of the PyTorch __functions__
are found either in:
The
torch.Tensor
module documentationpython_variable_methods.cpp
You can look up the documentation for the named functions at:
https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>
add a comment |
The Python documentation table Mapping Operators to Functions provides canonical mappings from:
operator -> __function__()
Eg:
Matrix Multiplication a @ b matmul(a, b)
Elsewhere on the page, you will see the __matmul__
name as an alternate to matmul
.
The definitions of the PyTorch __functions__
are found either in:
The
torch.Tensor
module documentationpython_variable_methods.cpp
You can look up the documentation for the named functions at:
https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>
The Python documentation table Mapping Operators to Functions provides canonical mappings from:
operator -> __function__()
Eg:
Matrix Multiplication a @ b matmul(a, b)
Elsewhere on the page, you will see the __matmul__
name as an alternate to matmul
.
The definitions of the PyTorch __functions__
are found either in:
The
torch.Tensor
module documentationpython_variable_methods.cpp
You can look up the documentation for the named functions at:
https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>
edited Nov 19 '18 at 11:23
answered Nov 19 '18 at 11:17
Tom HaleTom Hale
6,6264152
6,6264152
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370003%2fpytorch-mapping-operators-to-functions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Got you! I will check and see if I find something, but I'm afraid there is no (official) doc link for this.
– blue-phoenox
Nov 19 '18 at 9:45
Even though it is not that clear as a Doc Link, here are the actual definitions of the operators i.e.
+
and__add__
: github.com/pytorch/pytorch/blob/… is not the current version, I haven't found such a clear definition in the current version, but I guess there hasn't changed too much) So you can check what is called then.@
is defined by__matmul__
. For the rest you check on this python docs site Hope this is helpful.– blue-phoenox
Nov 19 '18 at 10:31
@blue-phoenox Given those two links, how do I deduce that
@
->matmul
?– Tom Hale
Nov 19 '18 at 10:54
Strange, I've had two answers which were deleted, but no question upvotes yet. It's worth answering but not upvoting?
– Tom Hale
Nov 19 '18 at 10:55
Check this and check this: stackoverflow.com/questions/27385633/… And check for the
__matmul__
function in the given (first) link.– blue-phoenox
Nov 19 '18 at 10:56