Skip to content
This repository
Browse code

added known bugs and pitfalls file

  • Loading branch information...
commit 313bec43b14603f93b930d0f1da6594a89d65ee8 1 parent 684c15c
Sebastian F. Walter authored

Showing 1 changed file with 54 additions and 0 deletions. Show diff stats Hide diff stats

  1. +54 0 KNOWN_BUGS_AND_PITFALLS.rst
54 KNOWN_BUGS_AND_PITFALLS.rst
Source Rendered
... ... @@ -0,0 +1,54 @@
  1 +Rationale:
  2 +
  3 + This text collects common pitfalls and known bugs that may lead to incorrect computation of derivatives.
  4 +
  5 +
  6 +Pitfalls
  7 +========
  8 +
  9 + 1. Inplace Numpy Array Operations
  10 +
  11 + One has to be caerful with the operations `+=` , `*=`, ... of numpy arrays.
  12 + The problem is best explained at an example::
  13 +
  14 + In [1]: import numpy
  15 +
  16 + In [2]: x = numpy.ones(2,dtype=int)
  17 +
  18 + In [3]: y = 1.3 * numpy.ones(2,dtype=float)
  19 +
  20 + In [4]: z = x * y
  21 +
  22 + In [5]: z
  23 + Out[5]: array([ 1.3, 1.3])
  24 +
  25 + In [6]: x *= y
  26 +
  27 + In [7]: x
  28 + Out[7]: array([1, 1])
  29 +
  30 + In [8]: x.dtype
  31 + Out[8]: dtype('int32')
  32 +
  33 + that means that the inplace operation `x *= y ` is *not* the same as `x = x * y`.
  34 + It is inconsistent to the Python behaviour and therefore a little surprising::
  35 +
  36 + In [9]: a = 1
  37 +
  38 + In [10]: b = 1.3
  39 +
  40 + In [11]: c = a * b
  41 +
  42 + In [12]: c
  43 + Out[12]: 1.3
  44 +
  45 + In [13]: a *= b
  46 +
  47 + In [14]: a
  48 + Out[14]: 1.3
  49 +
  50 + This is intended behaviour of numpy, but it leads to incorrect computations since no exception or
  51 + warning is raised by numpy. For more info see
  52 + http://www.mail-archive.com/numpy-discussion@lists.sourceforge.net/msg03236.html
  53 +
  54 +

0 comments on commit 313bec4

Please sign in to comment.
Something went wrong with that request. Please try again.