
ʽXc           @   s^  d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 m Z m Z m Z m Z d  d l m Z m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z d d  Z d d  Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d d  Z% d   Z& d e' f d     YZ( d e' f d     YZ) d   Z* e+ e j,    e* g Z- d e' f d     YZ. d  e' f d!     YZ/ d" e' f d#     YZ0 d$ e' f d%     YZ1 d& e. e/ e0 e1 f d'     YZ2 d( e. e/ e0 e1 f d)     YZ3 d* e. f d+     YZ4 d,   Z5 e6 d- k rZe
   n  d S(.   i(   t   division(   t   productN(   t   norm(   t   run_module_suitet   assert_t   assert_allcloset   assert_raisest   assert_equal(   t   issparset
   lil_matrix(   t   aslinearoperator(   t   least_squares(   t   IMPLEMENTED_LOSSES(   t   EPSt   make_strictly_feasiblei    c         C   s   |  | d d S(   Ni   g      @(    (   t   xt   a(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   fun_trivial   s    g        c         C   s   d |  | S(   Ni   (    (   R   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   jac_trivial   s    c         C   s   t  j |  d |  d g  S(   Ni    i   (   t   npt   array(   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   fun_2d_trivial   s    c         C   s   t  j d  S(   Ni   (   R   t   identity(   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   jac_2d_trivial   s    c         C   s/   t  j d |  d |  d d d |  d g  S(   Ni
   i   i    i   (   R   R   (   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   fun_rosenbrock#   s    c         C   s'   t  j d |  d d g d d g g  S(   Nii    i
   i(   R   R   (   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   jac_rosenbrock'   s    c         C   s0   t  j d |  d d g d d g d d g g  S(   Nii    i
   ig        (   R   R   (   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   jac_rosenbrock_bad_dim.   s    	c         C   s   t  |   d S(   Ni    (   R   (   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   fun_rosenbrock_cropped6   s    c         C   s   t  |   d S(   Ni    (   R   (   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   jac_rosenbrock_cropped:   s    c         C   s   t  j |  |  d |  d g  S(   Ni   i   (   R   R   (   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   fun_wrong_dimensions?   s    c         C   s   t  j t |  d |  S(   NR   (   R   t
   atleast_3dR   (   R   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   jac_wrong_dimensionsC   s    c         C   s   t  t j |  j d   } t j | d | d f  } |  j | | f  }  |  | d d  d d  f <| d  d  d d  f | d d   d d  f | d d  d  d  f | d d  d d   f d |  |  d } | j   S(   Ni    i   i   iii   i   (   t   intR   t   sqrtt   shapet   zerost   reshapet   ravel(   R   t   nt   ut   y(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   fun_bvpG   s    zt   BroydenTridiagonalc           B   s)   e  Z d  d d  Z d   Z d   Z RS(   id   t   sparsec            s  t  j j d  |   _ t  j |    _ t  j d d |    _ t  j d d |    _   j d t  j j	 |  7_   j d t  j j	 |  7_   j d t  j j	 |  7_ t
   j   j   j    _ | d k rt | | f d t   _ t  j |  } d	   j | | f <t  j d	 |  } d	   j | | d	 f <t  j | d	  } d	   j | | d	 f <  j   _ nU | d
 k r  f d     _ n4 | d k rd    _   f d     _ n
 t t  d  S(   Ni    ig      gg        g?R+   t   dtypei   t   operatorc            s   t    j |    S(   N(   R
   t   _jac(   R   (   t   self(    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   <lambda>k   s    t   densec            s     j  |   j   S(   N(   R.   t   toarray(   R   (   R/   (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR0   n   s    (   R   t   randomt   seedR&   t   onest   x0t   linspacet   lbt   ubt   randnR   R	   R    t   sparsityt   arangeR.   t   jact   NoneR   t   False(   R/   R&   t   modet   i(    (   R/   sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   __init__Q   s0    		c         C   sB   d | | d } | d c | d  8)| d c  d | d 8*| S(   Ni   i   ii   (    (   R/   R   t   f(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   funr   s    c         C   s   t  |  j |  j f  } t j |  j  } d d | | | | f <t j d |  j  } d | | | d f <t j |  j d  } d | | | d f <| S(   Ni   i   i   ii(   R	   R&   R   R<   (   R/   R   t   JRA   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR.   x   s    (   t   __name__t
   __module__RB   RD   R.   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR*   P   s   !	t   ExponentialFittingProblemc           B   s5   e  Z d  Z d d d d d  Z d   Z d   Z RS(	   s]   Provide data and function for exponential fitting in the form
    y = a + exp(b * x) + noise.i   ii   c   	      C   s   t  j j |  | |  _ d |  _ t  j d  |  _ t  j | d | d |  |  _ | t  j	 | |  j  |  _
 |  j
 | t  j j |  j  7_
 t  j j d |  j |  } |  j
 | c d | t  j j |  7<t  j | | g  |  _ d  S(   Ni   i    i   i2   (   R   R3   R4   t   mR&   R#   t   p0R7   R   t   expR(   R:   t   randintt   randR   t   p_opt(	   R/   R   t   bt   noiset
   n_outlierst   x_ranget   n_pointst   random_seedt   outliers(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyRB      s    		 "'c         C   s'   | d t  j | d |  j  |  j S(   Ni    i   (   R   RK   R   R(   (   R/   t   p(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyRD      s    c         C   sf   t  j |  j |  j f  } d | d  d   d f <|  j t  j | d |  j  | d  d   d f <| S(   Ni   i    (   R   t   emptyRI   R&   R   RK   (   R/   RV   RE   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR=      s    1(   ii   N(   RF   RG   t   __doc__R>   RB   RD   R=   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyRH      s
   	c         C   s\   t  j d |  j f  } d |  } d | d d | d <| d | d <d	 | d
 | d <| S(   Ni   i   i    iii   gUUUUUU?gUUUUUUgUUUUUUg(   R   RW   t   size(   t   zt   rhot   t(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   cubic_soft_l1   s    
t	   BaseMixinc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   sK   t  t d d |  j } t | j d d d t | j t | j   d  S(   Ng       @t   methodi    t   atolg-C6?(   R   R   R_   R   R   RD   (   R/   t   res(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt
   test_basic   s    c         C   s  d } x d d d t  g D] } t j    t j d t  t t d | d | f d |  j } t | j	 | d	 d
 t
 t t t d d d d |  j t t d | d i | d 6d |  j } t | j	 | d	 d
 t
 t t t d d i d d 6d |  j Wd  QXq Wd  S(   Ng      @s   2-points   3-pointt   cst   ignoreg       @t   argsR_   t   rtolg-C6?i   i   t   kwargsR   t   kaboom(   i   i   (   R   t   warningst   catch_warningst   simplefiltert   UserWarningR   R   R_   R   R   R   t	   TypeError(   R/   R   R=   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_args_kwargs   s    c         C   s   t  j   c t  j d t  xK d d d t g D]7 } t t d | d |  j } t | j	 d d d	 q0 WWd  QXt
 t t t d d
 d d |  j d  S(   NRd   s   2-points   3-pointRc   g       @R_   i    R`   g-C6?R=   t   oops(   Ri   Rj   Rk   Rl   R   R   R   R_   R   R   R   t
   ValueError(   R/   R=   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_jac_options   s     c         C   sO   xH d  d g D]: } t t d d | d |  j } t | j d d d q Wd  S(   Ni   g       @t   max_nfevR_   i    R`   g-C6?(   R>   R   R   R_   R   R   (   R/   Rr   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_nfev_options   s    c      	   C   s   xH d t  j d g  d g D]+ } t t d d | } t | j d  q Wt t t t d d d d |  j t t t t d d d	 d |  j t t t t d d d  d |  j t t t t d d d d |  j d  S(   Ng      ?g      ?R=   g       @t   x_scalei    t   autoR_   g      y               @y      ?       @(
   R   R   R   R   R   R   R   Rp   R_   R>   (   R/   Rt   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_x_scale_options   s    "c         C   s   t  t d d d d |  j } t  t d d d d |  j } t  t d d d  d |  j } t | j d d d t | j d d d t | j d d d t | j | j  t | j | j  t | j | j k  d  S(	   Ng       @t	   diff_stepg?R_   gi    R`   g-C6?(	   R   R   R_   R>   R   R   R   t   nfevR   (   R/   t   res1t   res2t   res3(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_diff_step   s    c         C   sV   t  t t t d d |  j d i d d 6t  t t t d d |  j d i d d 6d  S(   Ng       @R_   t   optionsid   t   no_such_optionRr   (   R   Rm   R   R   R_   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_incorrect_options_usage   s    c         C   s"  t  t d d |  j } t | j d d d t | j d  t | j d  t | j d d d t | j d d d t | j	 d d d t
 | j d  |  j d	 k r t | j d
 k   t | j d  k  n& t | j d k   t | j d k   t | j d k  t | j  d  S(   Ng       @R_   i    R`   g-C6?g      )@i   g{Gz?t   lmi   i
   (   R   R   R_   R   R   t   costRD   R=   t   gradt
   optimalityR   t   active_maskR   Rx   t   njevR>   t   statust   success(   R/   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_full_result   s    c         C   s$  |  j  d k r d  St t d d |  j  d d } t | j t j d g   t | j d  t | j t j d g   t | j	 t j d	 g g   t | j
 t j d
 g   t | j d
  t | j t j d g   t | j d  t | j d  t | j d  t | j d  d  S(   NR   g       @R_   Rr   i   i   g     @D@i	   i   i$   i    (   R_   R   R   R   R   R   R   R   RD   R=   R   R   R   Rx   R   R   R   (   R/   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_full_result_single_fev  s    	c         C   s   d d g } d d g } t  j    t  j d t  x t d d d t g d t j d d g  d	 g d
 d g  D]F \ } } } t t	 | | d | d | d |  j
 } t | j |  qr WWd  QXd  S(   Nii   Rd   s   2-points   3-pointRc   g      ?g?R=   t   exactt   lsmrRt   t	   tr_solverR_   (   Ri   Rj   Rk   Rl   R   R   R   R   R   R   R_   R   R   (   R/   R6   t   x_optR=   Rt   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_rosenbrock%  s    c         C   s   d d g } |  j  d k r7 t t t t | d d n x t d d d t g d t j d d	 g  d
 g d d g  D]L \ } } } t t | | d | d | d |  j  } t	 | j
 d d d qt Wd  S(   Nii   R   R_   s   2-points   3-pointRc   g      ?g?R=   R   R   Rt   R   i    R`   g+=(   R_   R   Rp   R   R   R   R   R   R   R   R   (   R/   R6   R=   Rt   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_rosenbrock_cropped2  s    c         C   s    t  t t t d d |  j d  S(   Ng       @R_   (   R   Rp   R   R   R_   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_fun_wrong_dimensionsA  s    c         C   s#   t  t t t d t d |  j d  S(   Ng       @R_   (   R   Rp   R   R   R   R_   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_jac_wrong_dimensionsE  s    c         C   s/   d d g } t  t t t | t d |  j d  S(   Ni   i   R_   (   R   Rp   R   R   R   R_   (   R/   R6   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt(   test_fun_and_jac_inconsistent_dimensionsI  s    c         C   s;   t  j d  j d d  } t t t t | d |  j d  S(   Ni   i   R_   (   R   R5   R$   R   Rp   R   R   R_   (   R/   R6   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_x0_multidimensionalN  s    c         C   s*   d d } t  t t t | d |  j d  S(   Ng       @g        y              ?R_   y                (   R   Rp   R   R   R_   (   R/   R6   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_x0_complex_scalarS  s    
c         C   s0   d d d g } t  t t t | d |  j d  S(   Ng      ?g       @g        y              ?R_   y                (   R   Rp   R   R   R_   (   R/   R6   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_x0_complex_arrayX  s    c      	   C   s   d } t  j | d  } |  j d k r1 d } n d } t t | d d d |  j d	 | } t | j | k   t | j d
 k   d  S(   Ni
   i   R   i  id   t   ftolg{Gz?R_   Rr   g      ?(   R   R5   R_   R   R)   R   Rx   R   (   R/   R&   R6   Rr   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_bvp]  s    		(   RF   RG   Rb   Rn   Rq   Rs   Rv   R|   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR^      s$   			
														t   BoundsMixinc           B   sG   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c      	   C   s&   t  t t t d d d d |  j d  S(   Ng       @t   boundsg      $@g        R_   (   g      $@g        (   R   Rp   R   R   R_   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_inconsistentp  s    c      	   C   s&   t  t t t d d d d |  j d  S(   Ng       @R   g      @i   R_   (   g      @i   (   R   Rp   R   R   R_   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_infeasiblet  s    c      	   C   s&   t  t t t d d d d |  j d  S(   Ng       @R   g      ?i   i   R_   (   g      ?i   i   (   R   Rp   R   R   R_   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_wrong_numberx  s    c      	   C   si   t  t t t d d d d d g f d |  j t  t t t d d g d d g d d g f d |  j d  S(   Ng       @R   g      ?g      @R_   g        g      @(   R   Rp   R   R   R_   R   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_inconsistent_shape|  s    c         C   s  x d d d t  g D] } t t d d | d d d	 |  j } t | j d
 d d t | j d g  t d | j k o d k n  t t d d | d d d	 |  j } t | j d d d t | j d g  t d | j k o d k n  q Wd  S(   Ns   2-points   3-pointRc   g       @R=   R   g      g      @R_   g        R`   g-C6?i    ii   g      ?(   g      g      @(   g      ?g      @(	   R   R   R   R_   R   R   R   R   R   (   R/   R=   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_in_bounds  s    #c      
   C   s6  x/d d d t  g D]} d d g } t t | d | } t | j d d g  t t | d | d d d	 d	 g f d
 |  j } t | j d d g  t t | d | d d d g d f d
 |  j } t | j d d g  t t | d | d d d g d d g f d
 |  j } t | j d d g d d q Wd  S(   Ns   2-points   3-pointRc   g      ?R=   g        R   g      ?g       @R_   g333333?g?g      @iR`   gh㈵>(   R   R   R   R   R   R_   (   R/   R=   R6   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_bounds_shape  s    'c         C   s  t  j d d g  } t  j d d g  } t  j d d g  } t  j d d g  } t  j d d g  } | t  j d g t  j f f | t  j d g t  j f f | t  j d g t  j f f | t  j d g d t  j g f f | d d g d d g f f | d	 d g d
 d g f f g } x | D] \ } } x t d d d t g d d d
 g d g d d g  D]O \ }	 }
 } t t | |	 | d |
 d | d |  j } t | j	 d d d qbWq"Wd  S(   Ng       g      ?g       @g        g333333g      g      ?g      @g      Ig      ?id   s   2-points   3-pointRc   R=   R   R   Rt   R   R_   R`   gh㈵>(
   R   R   t   infR   R   R   R   R_   R   R   (   R/   t   x0_1t   x0_2t   x0_3t   x0_4t   x0_5t   problemsR6   R   R=   Rt   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_rosenbrock_bounds  s(    "!(	   RF   RG   R   R   R   R   R   R   R   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR   o  s   						t   SparseMixinc           B   sb   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   c         C   sl   t    } t t t | j | j | j d d d |  j t t t | j | j d d d | j d |  j d  S(   NR   R   R_   t   jac_sparsity(	   R*   R   Rp   R   RD   R6   R=   R_   R;   (   R/   RV   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_exact_tr_solver  s    	c         C   s   t  d d  } t  d d  } t j    t j d t  t | j | j d | j d |  j	 } t | j | j d | j d |  j	 } t
 | j | j  t | j | j d d t | j d	 d d t | j d	 d d Wd  QXd  S(
   NR@   R+   R1   Rd   R=   R_   R`   g#B;i    (   R*   Ri   Rj   Rk   Rl   R   RD   R6   R=   R_   R   Rx   R   R   R   (   R/   R+   R1   t
   res_sparset	   res_dense(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_equivalence  s    c      
   C   sT   t    } t | j | j | j d |  j d i d d 6} t | j d d d d  S(   NR_   t
   tr_optionsg|=t   btoli    R`   g#B;(   R*   R   RD   R6   R=   R_   R   R   (   R/   RV   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_tr_options  s    	!c         C   sm   t    } t t t | j | j | j d d d |  j t t t | j | j | j d d d i d d 6d  S(   NR   t   bestR_   R   R   g|=t   tol(	   R*   R   Rp   R   RD   R6   R=   R_   Rm   (   R/   RV   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_wrong_parameters  s
    	c         C   s   t  d d  } t  d d  } t | j | j d | j d |  j } t | j | j d | j d |  j } t | j d d d t | j d d d t t	 | j   t t
 | j t j   d  S(	   NR@   R+   R1   R=   R_   i    R`   g#B;(   R*   R   RD   R6   R=   R_   R   R   R   R   t
   isinstanceR   t   ndarray(   R/   R+   R1   R   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_solver_selection  s    c         C   s   t    } t j    t j d t  x d d d g D] } t | j | j | d |  j } t | j | j | d |  j d | j	 } t
 | j | j  t | j | j d d t | j d	 d d t | j d	 d d q6 WWd  QXd  S(
   NRd   s   2-points   3-pointRc   R_   R   R`   g#B;i    (   R*   Ri   Rj   Rk   Rl   R   RD   R6   R_   R;   R   Rx   R   R   R   (   R/   RV   R=   R   R   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_numerical_jac  s    	!c         C   sV  t    } t j   ;t j d t  x#t | j d d d g d  | j g  D] \ } } t	 | j
 | j | d | j t j f d |  j d | } t	 | j
 | j | d t j | j f d |  j d | } t	 | j
 | j | d | j | j f d |  j d | } t | j d d	 d
 t | j d d	 d
 t | j d d	 d
 qN WWd  QXd  S(   NRd   s   2-points   3-pointRc   R   R_   R   i    R`   g|=(   R*   Ri   Rj   Rk   Rl   R   R=   R>   R;   R   RD   R6   R8   R   R   R_   R9   R   R   (   R/   RV   R=   R   t   res_1t   res_2t   res_3(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_with_bounds  s"    	.$%$c      	   C   sB   t    } | j d  } t t t | j | j d | d |  j d  S(   NiR   R_   (   R*   R;   R   Rp   R   RD   R6   R_   (   R/   RV   R;   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_wrong_jac_sparsity  s    	c      
   C   s{   t  d d  } t | j | j | j d |  j } t | j d d d t t	 t | j | j | j d |  j d d d  S(	   NR@   R-   R_   g        R`   g#B;R   R   (
   R*   R   RD   R6   R=   R_   R   R   R   Rp   (   R/   RV   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_linear_operator  s
    $c      
   C   s   t    } t | j | j | j d |  j d d } t | j d d d t  d d  } t t	 t | j | j | j d |  j d d d  S(	   NR_   Rt   R=   g        R`   g#B;R@   R-   (
   R*   R   RD   R6   R=   R_   R   R   R   Rp   (   R/   RV   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_x_scale_jac_scale  s    	!	(   RF   RG   R   R   R   R   R   R   R   R   R   R   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR     s   									t   LossFunctionMixinc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c      	   C   sk   xB t  D]: } t t d d | d |  j } t | j d d d q Wt t t t d d d d |  j d  S(   Ng       @t   lossR_   i    R`   gV瞯<t   hinge(   t   LOSSESR   R   R_   R   R   R   Rp   (   R/   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_options%  s    c         C   sL   xE t  D]= } t t d d | d |  j } t | j t | j   q Wd  S(   Ng       @R   R_   (   R   R   R   R_   R   RD   R   (   R/   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_fun.  s    c      
   C   s  t  j d g  } t t | t d d d d d |  j } t | j d | | d d  t t | t d d	 d d d |  j } t | j d |  t t | t d d
 d d d |  j } t | j d | | d d d | d d d d  t t | t d d d d d |  j } t | j d | | d d d | d d d  t t | t d d d d d |  j } t | j d | | d d d | d d d  t t | t d t	 d d d |  j } t | j d | | d d d | d d d d  d  S(   Ng       @R   t   linearRr   i   R_   i   i   t   hubert   soft_l1g      ?t   cauchyt   arctani   i   gUUUUUU?(
   R   R   R   R   R   R_   R   R   R   R]   (   R/   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt	   test_grad6  s*     	/44	c         C   s  d } | d d } t  t | t d d d d d |  j } t | j d |  t  t | t d d	 d d d |  j } t | j d | t d
  t  t | t d d	 d d d d } t | j d |  t  t | t d d d d d |  j } t | j d | d | d d  t  t | t d d d d d |  j } t | j d | t d
  t  t | t d d d d d d d |  j } | d } t | j d | d | d d
 d | d  t  t | t d d d d d |  j } t | j d | t d
  t  t | t d d d d d d d |  j } | d } t | j d | d d | d d
 d | d  t  t | t d t d d } t | j d | t d
  t  t | t d t d d d d } | d } t | j d | d | d d d
 d | d d  d  S(   Ng       @i   i   R   R   Rr   i   R_   R   g      ?t   f_scalei
   R   g      R   R   g      4@i   i   i   i   ig(	   R   R   R   R_   R   R=   R   R   R]   (   R/   R   RC   Ra   t   fs(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_jacU  sH    	$
0
4	
	c         C   s&  xd d g D]} t  d d | d d } x d d d | j g D] } t | j | j d	 | d
 |  j } t | j d d d x t D] } | d k r q n  t | j | j d	 | d | d | d
 |  j } t | j d d d t	 t
 | j | j  t
 | j | j  k   q WqA Wq Wd  S(   Ng?g      ?i   RT   i    s   2-points   3-pointRc   R=   R_   R`   g{Gz?R   R   R   (   RH   R=   R   RD   RJ   R_   R   R   R   R   R   R   RN   (   R/   RP   RV   R=   t   res_lsqR   t
   res_robust(    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_robustness  s    !(   RF   RG   R   R   R   R   R   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR   $  s
   					Dt
   TestDogboxc           B   s   e  Z d  Z RS(   t   dogbox(   RF   RG   R_   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR     s   t   TestTRFc           B   s   e  Z d  Z d   Z RS(   t   trfc         C   sh   t    } xX t t g D]J } t | j | j | j d d d i | d 6} t | j d d d q Wd  S(   NR_   R   R   t
   regularizei    R`   g#B;(	   R*   t   TrueR?   R   RD   R6   R=   R   R   (   R/   RV   R   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_lsmr_regularization  s
    	(   RF   RG   R_   R   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR     s   t   TestLMc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   R   c      	   C   s#   t  t t t d d d d d d  S(   Ng       @R   g      g      @R_   R   (   g      g      @(   R   Rp   R   R   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_bounds_not_supported  s    c         C   s)   d d g } t  t t t | d d d  S(   Nii   R_   R   (   R   Rp   R   R   (   R/   R6   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_m_less_n_not_supported  s    c         C   s2   t    } t t t | j | j | j d d d  S(   NR_   R   (   R*   R   Rp   R   RD   R6   R=   (   R/   RV   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_sparse_not_supported  s    	c      	   C   s&   t  t t t d d d g d d d  S(   Ng       @R   i   R_   R   (   R   Rp   R   R   (   R/   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   test_jac_sparsity_not_supported  s    c         C   s8   t  d d  } t t t | j | j | j d d d  S(   NR@   R-   R_   R   (   R*   R   Rp   R   RD   R6   R=   (   R/   RV   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt!   test_LinearOperator_not_supported  s    c      	   C   sT   t  t d d d d d } t | j d d d t t t  t d d d d d	 d  S(
   Ng       @R   R   R_   R   g        R`   g-C6?R   (   R   R   R   R   R   Rp   (   R/   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt	   test_loss  s    (	   RF   RG   R_   R   R   R   R   R   R   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyR     s   					c          C   s)   t  t d  }  t |  j d d d d  S(   Ng       @i    R`   g|=(   R   R   R   R   (   Ra   (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyRb     s    t   __main__(7   t
   __future__R    t	   itertoolsR   Ri   t   numpyR   t   numpy.linalgR   t   numpy.testingR   R   R   R   R   t   scipy.sparseR   R	   t   scipy.sparse.linalgR
   t   scipy.optimizeR   t!   scipy.optimize._lsq.least_squaresR   t   scipy.optimize._lsq.commonR   R   R   R   R   R   R   R   R   R   R   R   R   R)   t   objectR*   RH   R]   t   listt   keysR   R^   R   R   R   R   R   R   Rb   RF   (    (    (    sF   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/tests/test_least_squares.pyt   <module>   sH   (										3	Jk"	