PyTorch mapping operators to functions












1















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.










share|improve this question




















  • 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















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.










share|improve this question




















  • 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








1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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














2 Answers
2






active

oldest

votes


















2














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?






share|improve this answer



















  • 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



















2














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 documentation


  • python_variable_methods.cpp



You can look up the documentation for the named functions at:



https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>





share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    2














    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?






    share|improve this answer



















    • 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
















    2














    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?






    share|improve this answer



















    • 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














    2












    2








    2







    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?






    share|improve this answer













    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?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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














    • 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













    2














    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 documentation


    • python_variable_methods.cpp



    You can look up the documentation for the named functions at:



    https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>





    share|improve this answer






























      2














      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 documentation


      • python_variable_methods.cpp



      You can look up the documentation for the named functions at:



      https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>





      share|improve this answer




























        2












        2








        2







        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 documentation


        • python_variable_methods.cpp



        You can look up the documentation for the named functions at:



        https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>





        share|improve this answer















        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 documentation


        • python_variable_methods.cpp



        You can look up the documentation for the named functions at:



        https://pytorch.org/docs/stable/torch.html?#torch.<FUNCTION-NAME>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 '18 at 11:23

























        answered Nov 19 '18 at 11:17









        Tom HaleTom Hale

        6,6264152




        6,6264152






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?