<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1044" rel="nofollow">http://projects.scipy.org/numpy/ticket/1044</a> on 2009-03-09 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pv/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pv">@pv</a>, assigned to unknown.</em></p>
<p dir="auto">--- Continuation of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="7726510" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/1440" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/1440/hovercard" href="https://github.com/numpy/numpy/issues/1440">#1440</a>.</p>
<p dir="auto">Ufuncs return array scalars for 0D array input:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; type(np.conjugate(np.array(1+2j)))
&lt;type 'numpy.complex128'&gt;
&gt;&gt;&gt; type(np.sum(np.array(3.), np.array(5.)))
&lt;type 'numpy.float64'&gt;"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; type(np.conjugate(np.array(1+2j)))
&lt;type 'numpy.complex128'&gt;
&gt;&gt;&gt; type(np.sum(np.array(3.), np.array(5.)))
&lt;type 'numpy.float64'&gt;
</code></pre></div>
<p dir="auto">Should they return 0D arrays instead?</p>
<p dir="auto">I have a unit test failing on <code class="notranslate">np.divide.accumulate</code> with numpy 1.15.0 compiled with the Intel compiler. The same code is fine with a local build of GCC.</p>
<p dir="auto">Perhaps this is related to ENH: umath: don't make temporary copies for in-place accumulation (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="300055790" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/10665" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/10665/hovercard" href="https://github.com/numpy/numpy/pull/10665">#10665</a>) where <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/juliantaylor/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/juliantaylor">@juliantaylor</a> fixed <code class="notranslate">numpy/core/src/umath/loops.c.src</code> for GCC's <code class="notranslate">ivdep</code> pragma. That was reviewed by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/eric-wieser/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/eric-wieser">@eric-wieser</a> .</p>
<h3 dir="auto">Reproducing code example</h3>
<p dir="auto">Source code was 1.15.0 compiled with the Intel compiler 2018.1.163.  where np.divide.accumulate fails in the numpy unit tests.</p>
<p dir="auto">I can reproduce with this Python 2.7 test case for <code class="notranslate">float64</code> dtype. It runs correctly for <code class="notranslate">float32</code> and <code class="notranslate">float128</code> on the Intel compiler. It also runs correctly for <code class="notranslate">float64</code> using GCC instead of Intel.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python -c &quot;import numpy as np; acc = np.divide.accumulate;  
  a = np.ones(8, dtype=np.float64);  
  print acc(a, out=2*np.ones_like(a)); print acc(a); print acc(a); print acc(a); 
  print acc(a, out=2*np.ones_like(a))&quot;
[1. 1. 2. 2. 2. 2. 2. 2.]
[1. 1. 1. 1. 2. 2. 2. 2.]
[1. 1. 1. 1. 1. 1. 2. 2.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 2. 2. 2. 2. 2. 2.]"><pre class="notranslate"><code class="notranslate">$ python -c "import numpy as np; acc = np.divide.accumulate;  
  a = np.ones(8, dtype=np.float64);  
  print acc(a, out=2*np.ones_like(a)); print acc(a); print acc(a); print acc(a); 
  print acc(a, out=2*np.ones_like(a))"
[1. 1. 2. 2. 2. 2. 2. 2.]
[1. 1. 1. 1. 2. 2. 2. 2.]
[1. 1. 1. 1. 1. 1. 2. 2.]
[1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 2. 2. 2. 2. 2. 2.]
</code></pre></div>
<p dir="auto">Notice how only the next two elements are set each time <code class="notranslate">np.divide.accumulate</code> runs. That suggests the <code class="notranslate">float64</code>s are being processed in pairs. Then in the final line, specifying the output array again returns to the first line's incorrect behavior.</p>
<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">numpy 1.15.0 build with ICC 2018.1.163.<br>
python 2.7.11 built with GCC 4.9.3.</p>