<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1448" rel="nofollow">http://projects.scipy.org/numpy/ticket/1448</a> on 2010-04-08 by trac user themiwi, assigned to unknown.</em></p>
<p dir="auto">Running the version_cmd (as in numpy/distutils/ccompiler.py) results in</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ /usr/bin/ifort -FI -V -c test.f -o test.o 
Intel(R) Fortran Intel(R) 64 Compiler Professional for applications running on Intel(R) 64, Version 11.1    Build 20090827 Package ID: m_cprof_p_11.1.067
Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.

 Intel(R) Fortran 11.1-2582"><pre class="notranslate"><code class="notranslate">$ /usr/bin/ifort -FI -V -c test.f -o test.o 
Intel(R) Fortran Intel(R) 64 Compiler Professional for applications running on Intel(R) 64, Version 11.1    Build 20090827 Package ID: m_cprof_p_11.1.067
Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.

 Intel(R) Fortran 11.1-2582
</code></pre></div>
<p dir="auto">Using the following patch fixes things for me, but probably will break other platforms, so somebody with a better knowledge of the whole compiler-detection code should take care of this.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Index: numpy/distutils/fcompiler/intel.py
===================================================================
--- numpy/distutils/fcompiler/intel.py  (revision 8324)
+++ numpy/distutils/fcompiler/intel.py  (working copy)
@@ -24,8 +24,8 @@

     compiler_type = 'intel'
     compiler_aliases = ('ifort',)
-    description = 'Intel Fortran Compiler for 32-bit apps'
-    version_match = intel_version_match('32-bit|IA-32')
+    description = 'Intel Fortran Compiler for 32/64-bit apps'
+    version_match = intel_version_match('(32-bit|64)|IA-(32|64)')

     possible_executables = ['ifort', 'ifc']"><pre class="notranslate"><code class="notranslate">Index: numpy/distutils/fcompiler/intel.py
===================================================================
--- numpy/distutils/fcompiler/intel.py  (revision 8324)
+++ numpy/distutils/fcompiler/intel.py  (working copy)
@@ -24,8 +24,8 @@

     compiler_type = 'intel'
     compiler_aliases = ('ifort',)
-    description = 'Intel Fortran Compiler for 32-bit apps'
-    version_match = intel_version_match('32-bit|IA-32')
+    description = 'Intel Fortran Compiler for 32/64-bit apps'
+    version_match = intel_version_match('(32-bit|64)|IA-(32|64)')

     possible_executables = ['ifort', 'ifc']
</code></pre></div>
<p dir="auto">I am passing a very benign array of <code class="notranslate">float32</code> values to <code class="notranslate">np.histogram(...)</code> which raises a <code class="notranslate">ValueError: The first argument of bincount must be non-negative</code>. The values contain no NaN or infinite values. I think this is a bug, and it is due to incorrect handling of single-precision values in the histogram function. Specifically, values that are <em>equal</em> to the bin limits when compared as single-precision but are <em>outside them</em> when compared as doubles.</p>
<p dir="auto">First, a quick test code that works for me with 64-bit floats but raises the error with 32-bit floats on the last line:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
a64=np.array([25552.234, 26000])

# Make a histogram from these two values. Put the lower bin limit just above the lower value.
bin_limits = (a64[0]+0.0005, 26200)
np.histogram(a64, 10, bin_limits)

# That worked. But repeat the exercise with the data converted to float32...
a32=a64.astype(np.float32)

# ... The following raises a ValueError:
np.histogram(a32, 10, bin_limits)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">a64</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">25552.234</span>, <span class="pl-c1">26000</span>])

<span class="pl-c"># Make a histogram from these two values. Put the lower bin limit just above the lower value.</span>
<span class="pl-s1">bin_limits</span> <span class="pl-c1">=</span> (<span class="pl-s1">a64</span>[<span class="pl-c1">0</span>]<span class="pl-c1">+</span><span class="pl-c1">0.0005</span>, <span class="pl-c1">26200</span>)
<span class="pl-s1">np</span>.<span class="pl-en">histogram</span>(<span class="pl-s1">a64</span>, <span class="pl-c1">10</span>, <span class="pl-s1">bin_limits</span>)

<span class="pl-c"># That worked. But repeat the exercise with the data converted to float32...</span>
<span class="pl-s1">a32</span><span class="pl-c1">=</span><span class="pl-s1">a64</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)

<span class="pl-c"># ... The following raises a ValueError:</span>
<span class="pl-s1">np</span>.<span class="pl-en">histogram</span>(<span class="pl-s1">a32</span>, <span class="pl-c1">10</span>, <span class="pl-s1">bin_limits</span>)</pre></div>
<p dir="auto">The full output in iPython looks like this:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [29]: a64=np.array([25552.234, 26000])

In [30]: bin_limits = (a64[0]+0.0005, 26200)

In [31]: np.histogram(a64, 10, bin_limits)
Out[31]: 
(array([0, 0, 0, 0, 0, 0, 1, 0, 0, 0]),
 array([ 25552.2345 ,  25617.01105,  25681.7876 ,  25746.56415,
         25811.3407 ,  25876.11725,  25940.8938 ,  26005.67035,
         26070.4469 ,  26135.22345,  26200.     ]))

In [32]: a32=a64.astype(np.float32)

In [33]: np.histogram(a32, 10, bin_limits)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-33-0a3f12cea374&gt; in &lt;module&gt;()
----&gt; 1 np.histogram(a32, 10, bin_limits)

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/function_base.pyc in histogram(a, bins, range, normed, weights, density)
    778             else:
    779                 n += np.bincount(indices, weights=tmp_w,
--&gt; 780                                  minlength=bins).astype(ntype)
    781 
    782         # Rename the bin edges for return.

ValueError: The first argument of bincount must be non-negative

In [34]: np.version.version
Out[34]: '1.13.3'"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">29</span>]: <span class="pl-s1">a64</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">25552.234</span>, <span class="pl-c1">26000</span>])

<span class="pl-v">In</span> [<span class="pl-c1">30</span>]: <span class="pl-s1">bin_limits</span> <span class="pl-c1">=</span> (<span class="pl-s1">a64</span>[<span class="pl-c1">0</span>]<span class="pl-c1">+</span><span class="pl-c1">0.0005</span>, <span class="pl-c1">26200</span>)

<span class="pl-v">In</span> [<span class="pl-c1">31</span>]: <span class="pl-s1">np</span>.<span class="pl-en">histogram</span>(<span class="pl-s1">a64</span>, <span class="pl-c1">10</span>, <span class="pl-s1">bin_limits</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">31</span>]: 
(<span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>]),
 <span class="pl-en">array</span>([ <span class="pl-c1">25552.2345</span> ,  <span class="pl-c1">25617.01105</span>,  <span class="pl-c1">25681.7876</span> ,  <span class="pl-c1">25746.56415</span>,
         <span class="pl-c1">25811.3407</span> ,  <span class="pl-c1">25876.11725</span>,  <span class="pl-c1">25940.8938</span> ,  <span class="pl-c1">26005.67035</span>,
         <span class="pl-c1">26070.4469</span> ,  <span class="pl-c1">26135.22345</span>,  <span class="pl-c1">26200.</span>     ]))

<span class="pl-v">In</span> [<span class="pl-c1">32</span>]: <span class="pl-s1">a32</span><span class="pl-c1">=</span><span class="pl-s1">a64</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)

<span class="pl-v">In</span> [<span class="pl-c1">33</span>]: <span class="pl-s1">np</span>.<span class="pl-en">histogram</span>(<span class="pl-s1">a32</span>, <span class="pl-c1">10</span>, <span class="pl-s1">bin_limits</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">ValueError</span>                                <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">33</span><span class="pl-c1">-</span><span class="pl-c1">0</span><span class="pl-s1">a3f12cea374</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">np</span>.<span class="pl-en">histogram</span>(<span class="pl-s1">a32</span>, <span class="pl-c1">10</span>, <span class="pl-s1">bin_limits</span>)

<span class="pl-c1">/</span><span class="pl-s1">opt</span><span class="pl-c1">/</span><span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-v">Library</span><span class="pl-c1">/</span><span class="pl-v">Frameworks</span><span class="pl-c1">/</span><span class="pl-v">Python</span>.<span class="pl-s1">framework</span><span class="pl-c1">/</span><span class="pl-v">Versions</span><span class="pl-c1">/</span><span class="pl-c1">2.7</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">numpy</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">function_base</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">histogram</span>(<span class="pl-s1">a</span>, <span class="pl-s1">bins</span>, <span class="pl-s1">range</span>, <span class="pl-s1">normed</span>, <span class="pl-s1">weights</span>, <span class="pl-s1">density</span>)
    <span class="pl-c1">778</span>             <span class="pl-s1">else</span>:
    <span class="pl-c1">779</span>                 <span class="pl-s1">n</span> <span class="pl-c1">+=</span> <span class="pl-s1">np</span>.<span class="pl-en">bincount</span>(<span class="pl-s1">indices</span>, <span class="pl-s1">weights</span><span class="pl-c1">=</span><span class="pl-s1">tmp_w</span>,
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">780</span>                                  <span class="pl-s1">minlength</span><span class="pl-c1">=</span><span class="pl-s1">bins</span>).<span class="pl-en">astype</span>(<span class="pl-s1">ntype</span>)
    <span class="pl-c1">781</span> 
    <span class="pl-c1">782</span>         <span class="pl-c"># Rename the bin edges for return.</span>

<span class="pl-v">ValueError</span>: <span class="pl-v">The</span> <span class="pl-s1">first</span> <span class="pl-s1">argument</span> <span class="pl-s1">of</span> <span class="pl-s1">bincount</span> <span class="pl-s1">must</span> <span class="pl-s1">be</span> <span class="pl-s1">non</span><span class="pl-c1">-</span><span class="pl-s1">negative</span>

<span class="pl-v">In</span> [<span class="pl-c1">34</span>]: <span class="pl-s1">np</span>.<span class="pl-s1">version</span>.<span class="pl-s1">version</span>
<span class="pl-v">Out</span>[<span class="pl-c1">34</span>]: <span class="pl-s">'1.13.3'</span></pre></div>
<p dir="auto">Notice that <code class="notranslate">a32[0]</code> is equal to the lower bin limit or not, depending on whether we compare as float32 or as float:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [37]: a32==bin_limits[0]
Out[37]: array([ True, False], dtype=bool)

In [38]: a32[0]==bin_limits[0]
Out[38]: False
"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">37</span>]: <span class="pl-s1">a32</span><span class="pl-c1">==</span><span class="pl-s1">bin_limits</span>[<span class="pl-c1">0</span>]
<span class="pl-v">Out</span>[<span class="pl-c1">37</span>]: <span class="pl-en">array</span>([ <span class="pl-c1">True</span>, <span class="pl-c1">False</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">bool</span>)

<span class="pl-v">In</span> [<span class="pl-c1">38</span>]: <span class="pl-s1">a32</span>[<span class="pl-c1">0</span>]<span class="pl-c1">==</span><span class="pl-s1">bin_limits</span>[<span class="pl-c1">0</span>]
<span class="pl-v">Out</span>[<span class="pl-c1">38</span>]: <span class="pl-c1">False</span></pre></div>
<p dir="auto">Looking into <code class="notranslate">function_base.py</code>, we can see the problem:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="   740          for i in arange(0, len(a), BLOCK):
   741              tmp_a = a[i:i+BLOCK]
   742              if weights is None:
   743                  tmp_w = None
   744              else:
   745                  tmp_w = weights[i:i + BLOCK]
   746  
   747              # Only include values in the right range
   748              keep = (tmp_a &gt;= mn)
   749              keep &amp;= (tmp_a &lt;= mx)
   750              if not np.logical_and.reduce(keep):
   751                  tmp_a = tmp_a[keep]
   752                  if tmp_w is not None:
   753                      tmp_w = tmp_w[keep]
   754              tmp_a_data = tmp_a.astype(float)
   755              tmp_a = tmp_a_data - mn
   756              tmp_a *= norm
   757  
   758              # Compute the bin indices, and for values that lie exactly on mx we
   759              # need to subtract one
   760              indices = tmp_a.astype(np.intp)
   761              indices[indices == bins] -= 1
   762  
   763              # The index computation is not guaranteed to give exactly
   764              # consistent results within ~1 ULP of the bin edges.
   765              decrement = tmp_a_data &lt; bin_edges[indices]
   766              indices[decrement] -= 1
   767              # The last bin includes the right edge. The other bins do not.
   768              increment = ((tmp_a_data &gt;= bin_edges[indices + 1])
   769                           &amp; (indices != bins - 1))
   770              indices[increment] += 1
   771  
   772              # We now compute the histogram using bincount
   773              if ntype.kind == 'c':
   774                  n.real += np.bincount(indices, weights=tmp_w.real,
   775                                        minlength=bins)
   776                  n.imag += np.bincount(indices, weights=tmp_w.imag,
   777                                        minlength=bins)
   778              else:
   779                  n += np.bincount(indices, weights=tmp_w,
   780                                   minlength=bins).astype(ntype)
   781  "><pre class="notranslate">   <span class="pl-c1">740</span>          <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">arange</span>(<span class="pl-c1">0</span>, <span class="pl-en">len</span>(<span class="pl-s1">a</span>), <span class="pl-v">BLOCK</span>):
   <span class="pl-c1">741</span>              <span class="pl-s1">tmp_a</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span>[<span class="pl-s1">i</span>:<span class="pl-s1">i</span><span class="pl-c1">+</span><span class="pl-v">BLOCK</span>]
   <span class="pl-c1">742</span>              <span class="pl-k">if</span> <span class="pl-s1">weights</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
   <span class="pl-c1">743</span>                  <span class="pl-s1">tmp_w</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>
   <span class="pl-c1">744</span>              <span class="pl-k">else</span>:
   <span class="pl-c1">745</span>                  <span class="pl-s1">tmp_w</span> <span class="pl-c1">=</span> <span class="pl-s1">weights</span>[<span class="pl-s1">i</span>:<span class="pl-s1">i</span> <span class="pl-c1">+</span> <span class="pl-v">BLOCK</span>]
   <span class="pl-c1">746</span>  
   <span class="pl-c1">747</span>              <span class="pl-c"># Only include values in the right range</span>
   <span class="pl-c1">748</span>              <span class="pl-s1">keep</span> <span class="pl-c1">=</span> (<span class="pl-s1">tmp_a</span> <span class="pl-c1">&gt;=</span> <span class="pl-s1">mn</span>)
   <span class="pl-c1">749</span>              <span class="pl-s1">keep</span> &amp;= (<span class="pl-s1">tmp_a</span> <span class="pl-c1">&lt;=</span> <span class="pl-s1">mx</span>)
   <span class="pl-c1">750</span>              <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">np</span>.<span class="pl-s1">logical_and</span>.<span class="pl-en">reduce</span>(<span class="pl-s1">keep</span>):
   <span class="pl-c1">751</span>                  <span class="pl-s1">tmp_a</span> <span class="pl-c1">=</span> <span class="pl-s1">tmp_a</span>[<span class="pl-s1">keep</span>]
   <span class="pl-c1">752</span>                  <span class="pl-k">if</span> <span class="pl-s1">tmp_w</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>:
   <span class="pl-c1">753</span>                      <span class="pl-s1">tmp_w</span> <span class="pl-c1">=</span> <span class="pl-s1">tmp_w</span>[<span class="pl-s1">keep</span>]
   <span class="pl-c1">754</span>              <span class="pl-s1">tmp_a_data</span> <span class="pl-c1">=</span> <span class="pl-s1">tmp_a</span>.<span class="pl-en">astype</span>(<span class="pl-s1">float</span>)
   <span class="pl-c1">755</span>              <span class="pl-s1">tmp_a</span> <span class="pl-c1">=</span> <span class="pl-s1">tmp_a_data</span> <span class="pl-c1">-</span> <span class="pl-s1">mn</span>
   <span class="pl-c1">756</span>              <span class="pl-s1">tmp_a</span> <span class="pl-c1">*=</span> <span class="pl-s1">norm</span>
   <span class="pl-c1">757</span>  
   <span class="pl-c1">758</span>              <span class="pl-c"># Compute the bin indices, and for values that lie exactly on mx we</span>
   <span class="pl-c1">759</span>              <span class="pl-c"># need to subtract one</span>
   <span class="pl-c1">760</span>              <span class="pl-s1">indices</span> <span class="pl-c1">=</span> <span class="pl-s1">tmp_a</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">intp</span>)
   <span class="pl-c1">761</span>              <span class="pl-s1">indices</span>[<span class="pl-s1">indices</span> <span class="pl-c1">==</span> <span class="pl-s1">bins</span>] <span class="pl-c1">-=</span> <span class="pl-c1">1</span>
   <span class="pl-c1">762</span>  
   <span class="pl-c1">763</span>              <span class="pl-c"># The index computation is not guaranteed to give exactly</span>
   <span class="pl-c1">764</span>              <span class="pl-c"># consistent results within ~1 ULP of the bin edges.</span>
   <span class="pl-c1">765</span>              <span class="pl-s1">decrement</span> <span class="pl-c1">=</span> <span class="pl-s1">tmp_a_data</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">bin_edges</span>[<span class="pl-s1">indices</span>]
   <span class="pl-c1">766</span>              <span class="pl-s1">indices</span>[<span class="pl-s1">decrement</span>] <span class="pl-c1">-=</span> <span class="pl-c1">1</span>
   <span class="pl-c1">767</span>              <span class="pl-c"># The last bin includes the right edge. The other bins do not.</span>
   <span class="pl-c1">768</span>              <span class="pl-s1">increment</span> <span class="pl-c1">=</span> ((<span class="pl-s1">tmp_a_data</span> <span class="pl-c1">&gt;=</span> <span class="pl-s1">bin_edges</span>[<span class="pl-s1">indices</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>])
   <span class="pl-c1">769</span>                           <span class="pl-c1">&amp;</span> (<span class="pl-s1">indices</span> <span class="pl-c1">!=</span> <span class="pl-s1">bins</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>))
   <span class="pl-c1">770</span>              <span class="pl-s1">indices</span>[<span class="pl-s1">increment</span>] <span class="pl-c1">+=</span> <span class="pl-c1">1</span>
   <span class="pl-c1">771</span>  
   <span class="pl-c1">772</span>              <span class="pl-c"># We now compute the histogram using bincount</span>
   <span class="pl-c1">773</span>              <span class="pl-k">if</span> <span class="pl-s1">ntype</span>.<span class="pl-s1">kind</span> <span class="pl-c1">==</span> <span class="pl-s">'c'</span>:
   <span class="pl-c1">774</span>                  <span class="pl-s1">n</span>.<span class="pl-s1">real</span> <span class="pl-c1">+=</span> <span class="pl-s1">np</span>.<span class="pl-en">bincount</span>(<span class="pl-s1">indices</span>, <span class="pl-s1">weights</span><span class="pl-c1">=</span><span class="pl-s1">tmp_w</span>.<span class="pl-s1">real</span>,
   <span class="pl-c1">775</span>                                        <span class="pl-s1">minlength</span><span class="pl-c1">=</span><span class="pl-s1">bins</span>)
   <span class="pl-c1">776</span>                  <span class="pl-s1">n</span>.<span class="pl-s1">imag</span> <span class="pl-c1">+=</span> <span class="pl-s1">np</span>.<span class="pl-en">bincount</span>(<span class="pl-s1">indices</span>, <span class="pl-s1">weights</span><span class="pl-c1">=</span><span class="pl-s1">tmp_w</span>.<span class="pl-s1">imag</span>,
   <span class="pl-c1">777</span>                                        <span class="pl-s1">minlength</span><span class="pl-c1">=</span><span class="pl-s1">bins</span>)
   <span class="pl-c1">778</span>              <span class="pl-k">else</span>:
   <span class="pl-c1">779</span>                  <span class="pl-s1">n</span> <span class="pl-c1">+=</span> <span class="pl-s1">np</span>.<span class="pl-en">bincount</span>(<span class="pl-s1">indices</span>, <span class="pl-s1">weights</span><span class="pl-c1">=</span><span class="pl-s1">tmp_w</span>,
   <span class="pl-c1">780</span>                                   <span class="pl-s1">minlength</span><span class="pl-c1">=</span><span class="pl-s1">bins</span>).<span class="pl-en">astype</span>(<span class="pl-s1">ntype</span>)
   <span class="pl-c1">781</span>  </pre></div>
<p dir="auto">Up to line 753, we are discarding data that fall outside the given histogram limits. At lines 748 and 751, array <code class="notranslate">tmp_a</code> is still whatever type the user passes in (here, <code class="notranslate">float32), and the decision is made whether to keep data *based on the original float32 values*. But in line 755, the </code>tmp_a` is replaced with a (double-precision) float array. When the single-precision values are equal to the lowest bin edge <em>in single-precision comparisons</em> but then turn out to be just below the lowest edge in double-precision comparisons, then we get this error, erroneously.</p>
<p dir="auto">I could update and make a PR, but I'm completely new to numpy and don't know what approach you'd like best. Some ideas:</p>
<ol dir="auto">
<li>
<p dir="auto">You could just force values in the <code class="notranslate">indices</code> array to be in-range. This seems to be sort of what lines 760-770 do, so I'm not clear how it fails in the case I've raised. I think what we need is an analogue to line 761 but for the lower edge. Perhaps <code class="notranslate">indices[indices &lt; 0] = 0</code> ? This behavior means that we bin float32 data with float32 comparisons, which might or might not be what we want.</p>
</li>
<li>
<p dir="auto">Convert the input array to <code class="notranslate">float</code> before deciding which values to keep. This could be a performance problem in cases where most values will be outside the histogram limits, because you'd be converting all values. (The current approach only converts the ones that will be within limits, except that "within limits" is not quite correct for float32 values.)</p>
</li>
<li>
<p dir="auto">Replace the <code class="notranslate">tmp_a.astype(float)</code> (line 754) so that we convert not to <code class="notranslate">float</code> but to the input type. I think this would solve the problem for all floating-point inputs but likely create some new problem for integer inputs. This might require that handling floats and ints differently with separate branches.</p>
</li>
</ol>
<p dir="auto">I'd say that we want to go with the first idea but am hoping an expert can weigh in.</p>
<p dir="auto">I am using with numpy 1.13.1 on Mac OS 10.12.6 through the Macports system, with Python 2.7.14 and IPython 5.4.0.</p>