pbrod / numdifftools

Solve automatic numerical differentiation problems in one or more variables.
BSD 3-Clause "New" or "Revised" License
253 stars 44 forks source link

Allow fd_derivative to take complex valued functions #28

Closed rparini closed 7 years ago

rparini commented 7 years ago

At the moment the array which stores the derivatives, du, is always real so if the array of function evaluations, fx, is complex then the imaginary part gets discarded when the elements of du are assigned.

/usr/local/lib/python3.5/site-packages/numdifftools/fornberg.py:173: ComplexWarning: Casting complex values to real discards the imaginary part du[i] = np.dot(fd_weights(x[:size], x0=x[i], n=n), fx[:size])

The proposed change fixes this by matching the data type (as well as the shape) of du to fx.

PS thank you for working on this very useful module!

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 93.235% when pulling 21cf3c97e61aba50bca2bcd1d49f602a1e429173 on RParini:complex_fd_derivative into 3582063cde121046703327925fffb000bd1fc910 on pbrod:master.

pbrod commented 7 years ago

I will merge this. Thanks!

codecov-io commented 7 years ago

Codecov Report

Merging #28 into master will not change coverage. The diff coverage is 100%.

@@           Coverage Diff           @@
##           master      #28   +/-   ##
=======================================
  Coverage   91.79%   91.79%           
=======================================
  Files          21       21           
  Lines        2646     2646           
  Branches      251      251           
=======================================
  Hits         2429     2429           
  Misses        178      178           
  Partials       39       39
Impacted Files Coverage Δ
numdifftools/fornberg.py 72.13% <100%> (ø) :white_check_mark:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3582063...21cf3c9. Read the comment docs.