[NumPy-Tickets] [NumPy] #1546: function prod fails over arrays without warm

NumPy Trac numpy-tickets@scipy....
Thu Jul 15 09:12:10 CDT 2010


#1546: function prod fails over arrays without warm
-----------------------+----------------------------------------------------
  Reporter:  mmarquez  |       Owner:  somebody     
      Type:  defect    |      Status:  closed       
  Priority:  normal    |   Milestone:  2.0.0        
 Component:  Other     |     Version:               
Resolution:  wontfix   |    Keywords:  function prod
-----------------------+----------------------------------------------------
Changes (by pv):

  * status:  new => closed
  * resolution:  => wontfix


Comment:

 Numpy is intended for high-performance computing, and attempts to stay
 close to the hardware level. This includes following the integer
 arithmetic of current hardware. This is a conscious design decision.
 Possible discussion about changing this should be directed to the mailing
 list.

 Unlike for floating-point numbers, there is usually no hardware-level
 performance-efficient way to detect integer overflows. Numpy is the same
 boat as C and many other languages in this, and does not attempt to do
 trade safety over performance.

 The phrase "modular arithmetic" is perhaps a bit vague, probably should be
 corrected to "the modular hardware arithmetic". You can verify that the
 result coincides with modular arithmetic, exactly as claimed:
 {{{
 def modulo(x):
     x -= 2**32 * (x//(2**32))
     while x > 2**31 - 1:
         x -= 2**32
     while x < -2**31:
         x += 2**32
     return x

 def fact(n):
     # Python arbitrary-precision integers
     return reduce(lambda a, b: a*b, range(2, long(n)+1))

 def fact2(n):
     return reduce(lambda a, b: modulo(a*b), range(2, long(n)+1))

 for i in range(2,50,5):
     print "Fact of i %d is %d == %d" % (i, modulo(fact(i)), fact2(i))
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1546#comment:2>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list