<p dir="auto">e.g. <code class="notranslate">torch.sin(1)</code> or <code class="notranslate">torch.sin([1,2,3])</code></p>
<p dir="auto">Numpy supports this feature, which makes programming very convenient.</p>
<p dir="auto">Thx!</p>
<p dir="auto">Numpy automatically casts inputs to ndarrays when doing operations on them.  For example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; np.sum([1, 2])
3
&gt;&gt;&gt; np.sqrt(9)
3.0"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; np.sum([1, 2])
3
&gt;&gt;&gt; np.sqrt(9)
3.0
</code></pre></div>
<p dir="auto">Pytorch fails instead:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; torch.sum([1, 2])
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: sum(): argument 'input' (position 1) must be Tensor, not list
&gt;&gt;&gt; torch.sqrt(9)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: sqrt(): argument 'input' (position 1) must be Tensor, not int"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; torch.sum([1, 2])
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: sum(): argument 'input' (position 1) must be Tensor, not list
&gt;&gt;&gt; torch.sqrt(9)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: sqrt(): argument 'input' (position 1) must be Tensor, not int
</code></pre></div>
<p dir="auto">It would be nice for Pytorch to do type-casting internally like numpy does.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/mruberry/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/mruberry">@mruberry</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rgommers/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rgommers">@rgommers</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/heitorschueroff/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/heitorschueroff">@heitorschueroff</a></p>