Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
scipy
/
optimize
/
__pycache__
/
File Content:
_numdiff.cpython-35.opt-1.pyc
�B�W�R � @ s d Z d d l m Z d d l Z d d l m Z m Z m Z m Z m Z d d l m Z m Z e j e j � j Z d d � Z d d � Z d d � Z d d d � Z d d d e j e j f d f i d d � Z d d � Z d d � Z e j e j f f i d d � Z d S)z'Routines for numerical differentiation.� )�divisionN� )�issparse� csc_matrix� csr_matrix� coo_matrix�find� )�group_dense�group_sparsec C s] | d k r$ t j | d t �} n? | d k rW t j | � } t j | d t �} n t d � � t j | t j k | t j k @� r� | | f S| | } | j � } | | } | | } | d k rf| | } | | k | | k B} t j | � t j | | � k } | | | @d 9<| | k | @} | | | | | <| | k | @} | | | | | <n� | d k rS| | k | | k @} | | k | @} t j | | d | | | � | | <d | | <| | k | @} t j | | d | | | � | | <d | | <t j | | � | } | t j | � | k @} | | | | <d | | <| | f S) a� Adjust final difference scheme to the presence of bounds. Parameters ---------- x0 : ndarray, shape (n,) Point at which we wish to estimate derivative. h : ndarray, shape (n,) Desired finite difference steps. num_steps : int Number of `h` steps in one direction required to implement finite difference scheme. For example, 2 means that we need to evaluate f(x0 + 2 * h) or f(x0 - 2 * h) scheme : {'1-sided', '2-sided'} Whether steps in one or both directions are required. In other words '1-sided' applies to forward and backward schemes, '2-sided' applies to center schemes. lb : ndarray, shape (n,) Lower bounds on independent variables. ub : ndarray, shape (n,) Upper bounds on independent variables. Returns ------- h_adjusted : ndarray, shape (n,) Adjusted step sizes. Step size decreases only if a sign flip or switching to one-sided scheme doesn't allow to take a full step. use_one_sided : ndarray of bool, shape (n,) Whether to switch to one-sided scheme. Informative only for ``scheme='2-sided'``. z1-sided�dtypez2-sidedz(`scheme` must be '1-sided' or '2-sided'.r g �?TF���)�npZ ones_like�bool�absZ zeros_like� ValueError�all�inf�copy�maximumZminimum)�x0�hZ num_steps�scheme�lb�ub� use_one_sidedZh_totalZ h_adjustedZ lower_distZ upper_dist�xZviolatedZfittingZforwardZbackwardZcentralZmin_distZadjusted_central� r �/_numdiff.py�_adjust_scheme_to_bounds sH & ! ! r c C s� | d k rc | d k r% t d } n>