Where is the implementation of Tensor::slice?

username: markl
cooked: <p>I see Tensor::slice being called, for example, in this code.<a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Integration.cpp" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Integration.cpp</a></p>
<p>However, slice() is not listed in any of the following files<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/Tensor.h" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/Tensor.h" target="_blank" rel="nofollow noopener">pytorch/pytorch/blob/master/aten/src/ATen/Tensor.h</a></h4>
<pre><code class="lang-h">#pragma once

/*
 * We split Tensor.h into TensorBody.h and TensorMethods.h because we want
 * all TensorMethods to be inlined, but they depend on the Dispatcher,
 * which in turn depends on many other things, which then depend back on Tensor.
 *
 * We can break this dependency chain by having the dispatcher only depend on
 * TensorBody.h and not TensorMethods.h.
 */
#include &lt;ATen/core/TensorBody.h&gt;
#include &lt;ATen/core/TensorMethods.h&gt;
</code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorBody.h" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorBody.h" target="_blank" rel="nofollow noopener">pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorBody.h</a></h4>
<pre><code class="lang-h">#pragma once

#include &lt;c10/core/Device.h&gt;
#include &lt;c10/core/Layout.h&gt;
#include &lt;c10/core/MemoryFormat.h&gt;
#include &lt;c10/core/QScheme.h&gt;
#include &lt;c10/core/Scalar.h&gt;
#include &lt;c10/core/ScalarType.h&gt;
#include &lt;c10/core/Storage.h&gt;
#include &lt;ATen/core/TensorAccessor.h&gt;
#include &lt;c10/core/TensorImpl.h&gt;
#include &lt;c10/core/UndefinedTensorImpl.h&gt;
#include &lt;c10/util/Exception.h&gt;
#include &lt;c10/util/Deprecated.h&gt;
#include &lt;c10/util/Optional.h&gt;
#include &lt;c10/util/intrusive_ptr.h&gt;
#include &lt;ATen/core/DeprecatedTypePropertiesRegistry.h&gt;
#include &lt;ATen/core/DeprecatedTypeProperties.h&gt;
#include &lt;ATen/core/EnableNamedTensor.h&gt;
#include &lt;ATen/core/NamedTensor.h&gt;
</code></pre>

  This file has been truncated. <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorBody.h" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorMethods.h" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorMethods.h" target="_blank" rel="nofollow noopener">pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorMethods.h</a></h4>
<pre><code class="lang-h">#pragma once

#include &lt;c10/core/Scalar.h&gt;
#include &lt;c10/core/MemoryFormat.h&gt;
#include &lt;c10/core/QScheme.h&gt;
#include &lt;c10/macros/Macros.h&gt;
#include &lt;c10/core/TensorOptions.h&gt;
#include &lt;c10/util/intrusive_ptr.h&gt;
#include &lt;ATen/core/DeprecatedTypeProperties.h&gt;
#include &lt;ATen/core/ATenDispatch.h&gt;
#include &lt;ATen/core/dispatch/Dispatcher.h&gt;
#include &lt;ATen/core/NamedTensor.h&gt;
#include &lt;ATen/core/EnableNamedTensor.h&gt;

#ifdef USE_STATIC_DISPATCH
#include &lt;ATen/TypeDefault.h&gt;
#include &lt;ATen/CPUType.h&gt;
#include &lt;ATen/QuantizedCPUType.h&gt;
#include &lt;ATen/SparseCPUType.h&gt;
#endif
</code></pre>

  This file has been truncated. <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/templates/TensorMethods.h" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>
<p>I understand that there is some code generation that is happening, and maybe that the function is being injected by a python script.</p>

username: albanD
cooked: <p>I believe it’s implenented <a href="https://github.com/pytorch/pytorch/blob/3ad1bbe16a3c1d6bb9566f09229afd63022a82df/aten/src/ATen/native/TensorShape.cpp#L655" rel="nofollow noopener">here</a> <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: markl
cooked: <p>Thanks <a class="mention" href="/u/alband">@albanD</a>. Do you understand how the code generation mechanism works? How does it end up being a member function of Tensor? As it is declared in this file, it is a free standing function.</p>

username: tom
cooked: <p>The bindings (at::… and Tensor member functions) are generated from <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/native_functions.yaml" rel="nofollow noopener">native_functions.yaml</a> – look for variants: method for members.</p>

username: albanD
cooked: <p>Namely:</p>
<ul>
<li>
<code>function</code> means you get a <code>torch.xxx(t)</code> function</li>
<li>
<code>method</code> means you get a <code>t.xxx()</code> function</li>
</ul>

username: markl
cooked: <p>Thanks <a class="mention" href="/u/tom">@tom</a>. This is kind of a tangent, but what is the purpose of the overload_name</p>
<pre><code class="lang-auto">- func: func_name[.overload_name](ArgType arg0[=default], ArgType arg1[=default], ...) -&gt; Return
</code></pre>
<p>Shouldn’t the argument list be sufficient to uniquely identify an overloaded C++ function? If an overload_name is specified, does it need to also appear in the C++ source somewhere for the code generation to work?</p>

username: tom
cooked: <p>I am not aware of the overload name being used for C++, you  certainly can access the overloads as expected.</p>