
    :[g1                       d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%Z&ddl'Z(d	d
l)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< d	dl=m>Z>m?Z?m@Z@mAZA d	dlBmCZC  G d deD      ZEe$deFdeGfd       ZHe$deeF   dej                  fd       ZHde"eFeeF   f   de"eGej                  f   fdZHde0de<deeF   fdZJdedeGfdZKdeFdeeeFeLf      fdZM e!deeeNeNf      eeNeNf         ZOdee    de deFfdZPdeGddfdZQdefd ZRd!ej                  deeNeNeNf   fd"ZTdeFfd#ZUd!ej                  ddfd$ZVdej                  fd%ZW eW       ZXd&eNddfd'ZYdeeFef   ddfd(ZZd)eeF   d*eNd+e[d,eFdeeF   f
d-Z\de]fd.Z^d/e e&j                     de e.   fd0Z`de3de[fd1Zade3deGfd2Zbd3e/deNd/e e&j                     de&j                  fd4Zdd3e1deNdeefd5Zfd6eFdej                  fd7Zhd8e e2   d9e+de"ej                  ej                  f   fd:Zjd;e]de:fd<Zkd=e/d>eeNd?f   d/e e&j                     d@e[deeFe"eNeldf   f   f
dAZmd>e/dBe<dCe-d@e[de:f
dDZn G dE dFe
      ZodGe[deed?e*f   ged?e*f   f   fdHZp epdI      Zqe G dJ dKe             Zr G dL dM      Zs G dN dOes      Zt G dP dQes      Zu G dR dSeu      Zvee&j                  esgee&j                  e&j                  f   f   Zwee&j                  esgeeFeLf   f   ZxdTe,de,fdUZy G dV dW      Zzy)XzCore XGBoost Library.    N)ABCabstractmethod)Mapping)IntEnumunique)wraps)	Parameter	signature)AnyCallableDict	GeneratorIterableListOptionalSequenceTupleTypeTypeVarUnioncastoverload   )_T	ArrayLikeBoosterParam	CFloatPtrCNumericCNumericPtrCStrPptrCStrPtrCTypeTDataTypeFeatureInfoFeatureNamesFeatureTypesIntegerIterationRangeModelInNumpyOrCupyTransformedDatac_bst_ulong)PANDAS_INSTALLED	DataFrameimport_cupypy_str)find_lib_pathc                       e Zd ZdZy)XGBoostErrorz Error thrown by xgboost trainer.N)__name__
__module____qualname____doc__     G/var/www/html/bid-api/venv/lib/python3.12/site-packages/xgboost/core.pyr3   r3   >   s    *r9   r3   datareturnc                      y Nr8   r;   s    r:   from_pystr_to_cstrr@   B   s    ,/r9   c                      y r>   r8   r?   s    r:   r@   r@   F   s    9<r9   c                     t        | t              rt        | d      S t        | t              r9| D cg c]  }t        |d       }}t	        j
                  t        |      z  | }|S t               c c}w )zConvert a Python str or list of Python str to C pointer

    Parameters
    ----------
    data
        str or list of str
    utf-8)
isinstancestrbyteslistctypesc_char_plen	TypeError)r;   ddata_as_bytespointerss       r:   r@   r@   J   sp     $T7##$AE%FAeAw&7%FOOc-003 
+ &Gs   A0lengthc                 F   g }t        |j                        D ]=  }	 |j                  t        t	        t
        | |         j                  d                   ? |S # t        $ r= |j                  t        t	        t
        | |         j                  d                   Y w xY w)zRevert C pointer to Python str

    Parameters
    ----------
    data :
        pointer to data
    length :
        pointer to length of data
    asciirC   )rangevalueappendrE   r   rF   decodeUnicodeDecodeError)r;   rO   resis       r:   from_cstr_to_pystrrY   ^   s     C6<< 	BJJs4tAw/66w?@A !
 J " 	BJJs4tAw/66w?@A	Bs   :AAB B kwargsc                  >    t        t        j                  |             S )z*Make JSON-based arguments for C functions.)r@   jsondumps)rZ   s    r:   make_jcargsr^   q   s    djj011r9   resultc                     | j                         dd }|D cg c]  }t        |j                  d             }}|D cg c]  \  }}|t        |      f }}}|S c c}w c c}}w )z-Parse an eval result string from the booster.r   N:)splittuplefloat)r_   splitedsmetric_score_strnmetric_scores         r:   _parse_eval_strrj   v   sf    llnQR G5<=Waggcl+W=.>?.>daQaM.>L? >?s   !A A!	IterRangeexpectationsgotc                     d}t        t        |       dz
        D ]  }|t        | |         z  }|dz  } |t        | d         z  }|dt        |      z   z  }|S )zTranslate input error into string.

    Parameters
    ----------
    expectations :
        a list of expected value.
    got :
        actual input

    Returns
    -------
    msg: str
    z
Expecting r   z or z.  Got )rR   rJ   rE   )rl   rm   msgts       r:   _expectrr      sl     C3|$q()s<?##v * 3|B  C9s3xCJr9   rp   c                     t        |       }|j                  d      dk7  rt        j                  |t               yt        |       y)z5Redirect logs from native library into Python consolezWARNING:ro   N)r0   findwarningswarnUserWarningprint)rp   smsgs     r:   _log_callbackrz      s4    #;Dyy"dK(	$Kr9   c                  b    t        j                  dt         j                        }  | t              S )z2Wrap log_callback() method in ctypes callback typeN)rH   	CFUNCTYPErI   rz   )
c_callbacks    r:   _get_log_callback_funcr~      s#    !!$8Jm$$r9   libc                 X   t        j                         }t        j                         }t        j                         }| j                  t        j                  |      t        j                  |      t        j                  |             |j                  |j                  |j                  fS )z2Get the XGBoost version from native shared object.)rH   c_intXGBoostVersionbyrefrS   )r   majorminorpatchs       r:   _lib_versionr      si    LLNELLNELLNEv||E*FLL,?eATU;;U[[00r9   c                     t         j                  j                  t         j                  j                  t              d      } t        | d      5 }|j                         j                         cddd       S # 1 sw Y   yxY w)z1Get the XGBoost version from Python version file.VERSIONrQ   encodingN)ospathjoindirname__file__openreadstrip)VERSION_FILEfs     r:   _py_versionr      sK    77<< 99EL	lW	-vvx~~ 
.	-	-s   A77B c                     t         j                  | j                  _        t	               | _        | j                  | j
                        dk7  rt        | j                               y Nr   )rH   rI   XGBGetLastErrorrestyper~   callbackXGBRegisterLogCallbackr3   )r   s    r:   _register_log_callbackr      sN    "(//C)+CL
!!#,,/143..011 5r9   c                  .   t               } | sy	 t        j                  d   j                  t        j                        }d}g }| D ]  }	 t        j                  j                  |t        j                  j                  |      gz         t        j                  d<   t        j                  j                  |      }t        |dt        j                  j                  |             d}	 t        j                  j                  |      t        j                  d<    n |s4t        j                  j#                  | d         }t%        d| d| d	      t'               d
t         dt(        t*        t*        t*        f   fd}t-        |      }	 |t/                     }
|
|	k7  rQdj                  d |
D              }dj                  d |	D              }d| d| d|j                   d}t1        |      |S # t
        $ r g }Y w xY w# t        $ rU}|j                  t!        |             Y d}~t        j                  j                  |      t        j                  d<   d}~ww xY w# t        j                  j                  |      t        j                  d<   w xY w)zLoad xgboost Library.NPATHFr   Tr   z
XGBoost Library (aZ  ) could not be loaded.
Likely causes:
  * OpenMP runtime is not installed
    - vcomp140.dll or libgomp-1.dll for Windows
    - libomp.dylib for Mac OSX
    - libgomp.so for Linux and other UNIX-like OSes
    Mac OSX users: Run `brew install libomp` to install OpenMP runtime.

  * You are running 32-bit Python on a 64-bit OS

Error message(s): 
verr<   c                     | j                  d      d   j                  d      \  }}}|j                  d      }|dk7  r|d| }t        |      t        |      t        |      fS )z(Avoid dependency on packaging (PEP 440).-r   .rcro   N)rb   rt   int)r   r   r   r   r   s        r:   parsez_load_lib.<locals>.parse   sa     "iinQ/55c:ueZZ8#2JE5z3u:s5z11r9   r   c              3   2   K   | ]  }t        |        y wr>   rE   .0vs     r:   	<genexpr>z_load_lib.<locals>.<genexpr>   s     4ec!fe   c              3   2   K   | ]  }t        |        y wr>   r   r   s     r:   r   z_load_lib.<locals>.<genexpr>   s     6v!s1vvr   zeMismatched version between the Python package and the native shared object.  Python package version: z. Shared object version: z . Shared object is loaded from: z.
Likely cause:
  * XGBoost is first installed with anaconda then upgraded with pip. To fix it please remove one of the installations.)r1   r   environrb   pathsepKeyErrorr   r   r   rH   cdllLoadLibrarysetattrnormpathOSErrorrT   rE   basenamer3   r   r   r   r   r   
ValueError)	lib_paths
pathBackuplib_successos_error_listlib_pathr   elibnamer   libverpyver	pyver_str
libver_strrp   s                 r:   	_load_libr      sH   IZZ'--bjj9
 KM	= "$bggooh788"BJJv ++))(3CC!1!1(!;<K
 "$!<BJJv   ''""9Q<0 
 !/ "
 	
 323 25c3/ 2 #F+- E HH4e45	XX6v67
22; =$%EchhZ P66 	 oJC  
  	  Q(!#!<BJJv		 "$!<BJJvs<   0G/ 	BH/G>=G>	I
I$I"II""2Jretc                 Z    | dk7  r&t        t        t        j                                     y)zCheck the return value of C API call

    This function will raise exception when error occurs.
    Wrap every API call with this function

    Parameters
    ----------
    ret :
        return value from API calls
    r   N)r3   r0   _LIBr   )r   s    r:   _check_callr     s)     ax6$"6"6"89:: r9   c                 0   | j                  dd      }|r:t        |t              s*d}|t        t        ft	        |            z  }t        |      |r|j                  d      dk7  rt        d      | j                  dd      dk(  rt        d	| d    d
      y)z0Validate parameters in distributed environments.deviceNz'Invalid type for the `device` parameterra   ro   zDistributed training doesn't support selecting device ordinal as GPUs are managed by the distributed frameworks. use `device=cuda` or `device=gpu` instead.boostergblinearz	booster `z,` is not supported for distributed training.)	getrD   rE   rr   typerK   rt   r   NotImplementedError)rZ   r   rp   s      r:   _check_distributed_paramsr     s    ZZ$'Fj-7wvtF|,,n&++c"b(
 	
 zz)T"j0!y)**VW
 	
 1r9   feature_info
n_featuresis_column_splitnamec                     t        | t              st        | t              st        d| dt	        |              t        |       } t        |       |k7  r(|dk7  r#|s!| dd| dt        |        f}t        |      | S )Nz$Expecting a sequence of strings for , got: r   z: must have the same length as the number of data columns, 	expected , got )rD   rE   r   rK   r   rG   rJ   r   )r   r   r   r   rp   s        r:   _validate_feature_infor   4  s     ,$J|X,N24&\@R?ST
 	
 %L
<J&:??fNO
|6#l*;)<=
 or9   c                  ,   t        j                         } t        t        j	                  t        j
                  |                    | j                  J t        j                  | j                  j                               }t        j                  |d<   |S )a2  Build information of XGBoost.  The returned value format is not stable. Also,
    please note that build time dependency is not the same as runtime dependency. For
    instance, it's possible to build XGBoost with older CUDA version but run it with the
    lastest one.

      .. versionadded:: 1.6.0

    
libxgboost)rH   rI   r   r   XGBuildInfor   rS   r\   loadsrU   r   )j_inforW   s     r:   
build_infor   E  sj     __F  f!567<<###
**V\\((*
+C		CJr9   dtypec                 F   t         j                  t        j                  t         j                  t        j
                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  i}t         j                  t         j                  ur$|t         j                     |t         j                  <   | |vrt        d|j!                          d|        ||    S )NzSupported types: r   )npfloat32rH   c_floatfloat64c_doubleuint32c_uintuint64c_uint64int32c_int32int64c_int64intcrK   keys)r   _NUMPY_TO_CTYPES_MAPPINGs     r:   _numpy2ctypes_typer   V  s    


FNN


FOO
		6==
		6??
&..
&..G 
wwbhh,DRXX,N ),, 8 = = ?@wO
 	
 $E**r9   c                 ^    t        | j                  d      xr | j                  j                  S )N	hasobject)hasattrr   r   r?   s    r:   _array_hasobjectr   h  s"    4::{+D

0D0DDr9   c                     t        |       rt        d      | j                  }d|v r|d   j                  |d<   t        t	        j
                  |      d      }|S )Nz<Input data contains `object` dtype.  Expecting numeric data.maskrC   )r   r   __cuda_array_interface__rF   r\   r]   )r;   	interfaceinterface_strs      r:   _cuda_array_interfacer   l  sY    WXX--I%f-FF	&$**Y/9Mr9   cptrc                 2   t        |      }t        | t        j                  |            st	        d| d      t        j                  ||      }t        j                  |j                  j                  | ||j                  d   z        st	        d      |S )z0Convert a ctypes pointer array to a numpy array.r   z pointerr   r   memmove failed)
r   rD   rH   POINTERRuntimeErrorr   zerosmemmover;   strides)r   rO   r   ctyperW   s        r:   ctypes2numpyr  v  sy    .u5EdFNN512YugX677
((6
'C>>#**//4#++a.1HI+,,Jr9   c                    t        | t        j                  t        j                              st	        d      t        |      }t        j                  |z  j                  |      }t        j                  || |      st	        d      |S )z&Convert ctypes pointer to buffer type.zexpected char pointerr  )rD   rH   r  c_charr  	bytearrayfrom_bufferr  )r   rO   rW   rptrs       r:   ctypes2bufferr    si    dFNN6==9:233
F
CMMF"//4D>>$f-+,,Jr9   stringc                 J    t        j                  | j                  d            S )z#Convert a python string to cstring.rC   )rH   rI   encode)r  s    r:   c_strr    s    ??6==122r9   r  valuesc                    t        |t        j                        rZ|j                  j                  t        j                  |       k(  r.|j
                  j                  t        j                  |             S  | t        |      z  | S )z"Convert a python array to c array.)
rD   r   ndarrayr   itemsizerH   sizeofdata_asr  rJ   )r  r  s     r:   c_arrayr    sa     &"**%&,,*?*?6==QVCW*W}}$$V^^E%:;;ECK&))r9   r   c                      G d d      } |       }d| v r$| |_         t               j                  |d      }|S | |_        t	        j                  |d      }|S )z.Convert array interface to numpy or cupy arrayc                       e Zd ZU dZdZee   ed<   edee   fd       Z	e	j                  deddfd       Z	edee   fd       Zej                  deddfd	       Zy)
#from_array_interface.<locals>.Arrayz3Wrapper type for communicating with numpy and cupy.N
_interfacer<   c                     | j                   S r>   )r  selfs    r:   __array_interface__z7from_array_interface.<locals>.Array.__array_interface__  s    ??"r9   r   c                 P   t        j                   |      | _        t        | j                  d         | j                  d<   t        | j                  d         | j                  d<   | j                  j                  dd       &t        | j                  d         | j                  d<   y y )Nshaper;   r  )copyr  rc   r   r   r   s     r:   r!  z7from_array_interface.<locals>.Array.__array_interface__  s    "ii	2DO',T__W-E'FDOOG$&+DOOF,C&DDOOF#""9d3?-24??93M-N	* @r9   c                     | j                   S r>   r!  r  s    r:   r   z<from_array_interface.<locals>.Array.__cuda_array_interface__  s    +++r9   c                     || _         y r>   r'  r%  s     r:   r   z<from_array_interface.<locals>.Array.__cuda_array_interface__  s
    '0D$r9   )r4   r5   r6   r7   r  r   dict__annotations__propertyr!  setterr   r8   r9   r:   Arrayr    s    A%)
HTN)		#$ 	# 
	# 
	#	#	O 	O$ 	O 
$	O 
	,htn 	, 
	, 
"	(	(	1d 	1t 	1 
)	1r9   r-  streamTr$  )r   r/   arrayr!  r   )r   r-  arrouts       r:   from_array_interfacer3    sb    1 14 'C9'0$m!!#D!1
 J #,hhs&Jr9   ptrr#  .is_cudac                    |r(t               j                  d|      }|j                  }n#t        j                  d|      }|j                  }t        j                  | t
        j                        j                  }t        t        j                  |            }||dk(  sJ ||S |df|d<   |rd|d<   ||d	<   d|d
<   |S )z2Make an __(cuda)_array_interface__ from a pointer.)r   )r#  r   Nr   Tr;      r.  r#  r  )r/   emptyr   r   r!  rH   r   c_void_prS   r   prod)r4  r#  r   r5  r8  r0  addrrO   s           r:   make_array_interfacer<    s    
 ##$e#<..t51));;sFOO,22D Fv{**|4LE&MhE'NE)Lr9   dimspredtsc                     t        t        | |j                  t        j                        j                               }t        t        ||t        j                  |            }|S r>   )	rc   r  rS   r   r   flattenr3  r<  r   )r#  r=  r>  r5  	arr_shaper0  s         r:   _prediction_outputrB    sK     l5$**bii@HHJKI VY

GDE Lr9   c                       e Zd ZdZ	 ddee   deddfdZdedee	e	f   fdZ
edd	       Zd
e	dedefdZddZddZddZdddefdZedd       Zede	defd       Zy)DataItera  The interface for user defined data iterator. The iterator facilitates
    distributed training, :py:class:`QuantileDMatrix`, and external memory support using
    :py:class:`DMatrix`. Most of time, users don't need to interact with this class
    directly.

    .. note::

        The class caches some intermediate results using the `data` input (predictor
        `X`) as key. Don't repeat the `X` for multiple batches with different meta data
        (like `label`), make a copy if necessary.

    Parameters
    ----------
    cache_prefix :
        Prefix to the cache files, only used in external memory.
    release_data :
        Whether the iterator should release the data during iteration. Set it to True if
        the data transformation (converting data to np.float32 type) is memory
        intensive. Otherwise, if the transformation is computation intensive then we can
        keep the cache.

    Ncache_prefixrelease_datar<   c                 v    || _         t               | _        d | _        d| _        || _        d | _        d | _        y )NF)rE  _ProxyDMatrix_handle
_exception_enable_categorical_release_temporary_data	_data_ref)r   rE  rF  s      r:   __init__zDataIter.__init__  s:     )$/3#( $:>:>r9   enable_categoricalc                 f   t        | d      sJ d        t        j                  dt        j                        | j                        | _         t        j                  t        j                  t        j                        | j                        | _        || _	        | j
                  | j                  fS )zHGet callback functions for iterating in C. This is an internal function.rE  z__init__ is not called.N)
r   rH   r|   r9  _reset_wrapper_reset_callbackr   _next_wrapper_next_callbackrK  )r   rP  s     r:   get_callbackszDataIter.get_callbacks  s    t^,G.GG,Fv//fooF 

f..LLOO
 

 $6 ##T%8%888r9   c                     | j                   S )zHandle of DMatrix proxy.)rI  r  s    r:   proxyzDataIter.proxy  s     ||r9   fndft_retc                     | j                   |S 	  |       S # t        $ r8}t        j                         d   }|j	                  |      | _         Y d }~|S d }~ww xY w)Nr7  )rJ  	Exceptionsysexc_infowith_traceback)r   rY  rZ  r   tbs        r:   _handle_exceptionzDataIter._handle_exception!  sZ    ??&N		34K 	3 "B  ..r2DOO	3s    	A-AAc                 T    d| _         | j                  | j                  }d| _        |y)z.Reraise the exception thrown during iteration.NrM  rJ  )r   excs     r:   reraisezDataIter.reraise1  s0    #??& //C"DOI 'r9   c                 <    | j                   J | j                  J y r>   rc  r  s    r:   __del__zDataIter.__del__;  s$    ##+++&&&r9   thisc                 b    | j                   rd| _        | j                  | j                  d       y)z,A wrapper for user defined `reset` function.N)rL  rM  ra  reset)r   rh  s     r:   rR  zDataIter._reset_wrapper?  s'     ==#'D tzz40r9   c                      t        d      ddddt        dt        t           dt        t           dt        ddf
 fd	        j
                  rd _         j                   fd
d      S )zA wrapper for user defined `next` function.

        `this` is not used in Python.  ctypes can handle `self` of a Python
        member function automatically when converting it to c function
        pointer.

        TNfeature_namesfeature_typesr;   rm  rn  rZ   r<   c                 ~   ddl m}m} 	 t        j                  |       }	j                  "| |	j                  u r	j                  \  }}}}n || ||	j                        \  }}}}||||f	_         |	j                  ||        	j                  j                  d||d| |	_        y # t
        $ r d }Y w xY w)Nr   )_proxy_transformdispatch_proxy_set_datarl  r8   )r;   rp  rq  weakrefrefrK   rM  rN  rK  rX  set_info)
r;   rm  rn  rZ   rp  rq  rs  new	cat_codesr   s
            r:   
input_dataz*DataIter._next_wrapper.<locals>.input_dataO  s     Hkk$' $$0O4>>)?C?S?S<Y}?O!!,,	@<Y} %(M=#QD #DJJY?DJJ ++ 
 !DN/  s   B. .B<;B<c                  &    j                         S r>   )next)rw  r   s   r:   <lambda>z(DataIter._next_wrapper.<locals>.<lambda>}  s    dii
.Cr9   r   )require_keyword_argsr   r   r%   r&   rL  rM  ra  )r   rh  rw  s   ` @r:   rT  zDataIter._next_wrapperF  s     
d	# 5948	'	!'	! $L1'	! $L1	'	!
 '	! '	! 
$'	!T ==#'D %%&CQGGr9   c                     t               )z>Reset the data iterator.  Prototype for user defined function.r   r  s    r:   rj  zDataIter.reset  s     "##r9   rw  c                     t               )a  Set the next batch of data.

        Parameters
        ----------

        input_data:
            A function with same data fields like `data`, `label` with
            `xgboost.DMatrix`.

        Returns
        -------
        0 if there's no more batch, otherwise 1.

        r}  )r   rw  s     r:   ry  zDataIter.next  s      "##r9   )NT)r<   rH  r<   N)rh  Nr<   N)r4   r5   r6   r7   r   rE   boolrO  r   r   rV  r+  rX  r   ra  re  rg  rR  r   rT  r   rj  ry  r8   r9   r:   rD  rD    s    0 HL?$SM?@D?	?9 9x?Q9R 9  H r b  '17H$ 7H3 7Hr $ $ $x $C $ $r9   rD  errorc                 P     dt         dt        f   dt         dt        f   f fd}|S )am  Decorator for methods that issues warnings for positional arguments

    Using the keyword-only argument syntax in pep 3102, arguments after the
    * will issue a warning or error when passed as a positional argument.

    Modified from sklearn utils.validation.

    Parameters
    ----------
    error :
        Whether to throw an error or raise a warning.
    func.r<   c                     t               g g j                  j                         D ]c  \  }}|j                  t        j
                  k(  rj                  |       5|j                  t        j                  k(  sSj                  |       e t               dt        dt        dt        f fd       }|S )zThrow an error/warning if there are positional arguments after the asterisk.

        Parameters
        ----------
        f :
            function to check arguments on.

        argsrZ   r<   c                     t        |       t        	      z
  }	s|dkD  rt        d      |dkD  rmt        d | | | d        D cg c]  \  }}| 
 }}}dj                  dj	                  |            }
rt        |      t        j                  |t               t        j                  |       D ]
  \  }}|||<     di |S c c}}w )Nr   zKeyword argument is required.zPass `{}` as keyword args., r8   )	rJ   rK   zipformatr   ru   rv   FutureWarning
parameters)r  rZ   
extra_argsr   _args_msgrp   kargall_argsr  r  kwonly_argssigs            r:   inner_fz7require_keyword_args.<locals>.throw_if.<locals>.inner_f  s    TS]2J
Q ?@@A~ $'{;J'?zklAS#T#Ta fI#T  
 399$))H:MN#C.(c=1cnnd33q	 4>&>!s   C)r
   r  itemskindr	   POSITIONAL_OR_KEYWORDrT   KEYWORD_ONLYr   r   r   )r  r   paramr  r  r  r  r  s   `   @@@r:   throw_ifz&require_keyword_args.<locals>.throw_if  s     o>>//1KD%zzY<<<%y555""4(	 2 
t	"3 	"# 	"" 	" 	" 
	"( r9   )r   r   )r  r  s   ` r:   r{  r{    s0     (xR( (Xc2g-> (T Or9   Fc                       e Zd ZdZdZdZy)DataSplitModez&Supported data split mode for DMatrix.r   r   N)r4   r5   r6   r7   ROWCOLr8   r9   r:   r  r    s    0
C
Cr9   r  c            %          e Zd ZdZe	 d:dddddddddddddej                  ddedee	   dee	   dee	   d	ee
   d
edee   dee   dee   dee	   dee	   dee	   dee	   dee	   dededdf"d       ZdededdfdZd;dZeddddddddddd
dee	   dee	   dee	   dee	   dee	   dee	   dee	   dee   dee   dee	   ddfd       Zdedej,                  fdZdedej,                  fdZdede	ddfdZdede	ddfd Zdede	ddfd!Zd<d"eeej<                  f   d
eddfd#Zde	ddfd$Z de	ddfd%Z!d&e	ddfd'Z"de	ddfd(Z#dej,                  fd)Z$dej,                  fd*Z%dej,                  fd+Z&dej,                  fd,Z'de(jR                  jT                  fd-Z+de,ej,                  ej,                  f   fd.Z-defd/Z.defd0Z/defd1Z0defd2Z1	 d=d3ee2e   ej,                  f   d4edd fd5Z3e4dee   fd6       Z5e5jl                  dee   ddfd7       Z5e4dee   fd8       Z7e7jl                  dee   ddfd9       Z7y)>DMatrixzData Matrix used in XGBoost.

    DMatrix is an internal data structure that is used by XGBoost, which is optimized
    for both memory efficiency and training speed.  You can construct DMatrix from
    multiple different sources of data.

    NF)weightbase_marginmissingsilentrm  rn  nthreadgroupqidlabel_lower_boundlabel_upper_boundfeature_weightsrP  data_split_moder;   labelr  r  r  r  rm  rn  r  r  r  r  r  r  rP  r  r<   c          
         |
|t        d      ||nt        j                  | _        |	|	nd| _        || _        t        |t        j                        r|| _	        yddl
m}m}  ||      r!| j                  ||       | j                  J y ||| j                  | j                  ||||      \  }}}|J || _	        | j                  ||||
||||       ||| _        ||| _        yy)a  Parameters
        ----------
        data :
            Data source of DMatrix. See :ref:`py-data` for a list of supported input
            types.
        label :
            Label of the training data.
        weight :
            Weight for each instance.

             .. note::

                 For ranking task, weights are per-group.  In ranking task, one weight
                 is assigned to each group (not each data point). This is because we
                 only care about the relative ordering of data points within each group,
                 so it doesn't make sense to assign weights to individual data points.

        base_margin :
            Global bias for each instance. See :doc:`/tutorials/intercept` for details.
        missing :
            Value in the input data which needs to be present as a missing value. If
            None, defaults to np.nan.
        silent :
            Whether print messages during construction
        feature_names :
            Set names for features.
        feature_types :

            Set types for features. If `data` is a DataFrame type and passing
            `enable_categorical=True`, the types will be deduced automatically
            from the column types.

            Otherwise, one can pass a list-like input with the same length as number
            of columns in `data`, with the following possible values:

            - "c", which represents categorical columns.
            - "q", which represents numeric columns.
            - "int", which represents integer columns.
            - "i", which represents boolean columns.

            Note that, while categorical types are treated differently from
            the rest for model fitting purposes, the other types do not influence
            the generated model, but have effects in other functionalities such as
            feature importances.

            For categorical features, the input is assumed to be preprocessed and
            encoded by the users. The encoding can be done via
            :py:class:`sklearn.preprocessing.OrdinalEncoder` or pandas dataframe
            `.cat.codes` method. This is useful when users want to specify categorical
            features without having to construct a dataframe as input.

        nthread :
            Number of threads to use for loading data when parallelization is
            applicable. If -1, uses maximum threads available on the system.
        group :
            Group size for all ranking group.
        qid :
            Query ID for data samples, used for ranking.
        label_lower_bound :
            Lower bound for survival training.
        label_upper_bound :
            Upper bound for survival training.
        feature_weights :
            Set feature weights for column sampling.
        enable_categorical :

            .. versionadded:: 1.3.0

            .. note:: This parameter is experimental

            Experimental support of specializing for categorical features.

            If passing 'True' and 'data' is a data frame (from supported libraries such
            as Pandas, Modin or cuDF), columns of categorical types will automatically
            be set to be of categorical type (feature_type='c') in the resulting
            DMatrix.

            If passing 'False' and 'data' is a data frame with categorical columns,
            it will result in an error being thrown.

            If 'data' is not a data frame, this argument is ignored.

            JSON/UBJSON serialization format is required for this.

        Nz.Either one of `group` or `qid` should be None.ro   r   )_is_iterdispatch_data_backend)r  threadsrm  rn  rP  r  )r  r  r  r  r  r  r  r  )r   r   nanr  r  r  rD   rH   r9  handler;   r  r  _init_from_iterrt  rm  rn  )r   r;   r  r  r  r  r  rm  rn  r  r  r  r  r  r  rP  r  r  r  r  s                       r:   rO  zDMatrix.__init__  s   T MNN")"5w266")"5w2dFOO,DK9D>  '9:;;***/DLLLL''1+0
,} !!!#//+ 	 		
 $!.D$!.D %r9   iteratorc           
         |}| j                   | j                  |j                  r|j                  ndd}t        t	        j
                  |            }t        j                         }|j                  |      \  }}t        j                  d |j                  j                  |||t        j                  |            }	|j                          t        |	       || _        y )N )r  r  rE  )r  r  rE  r@   r\   r]   rH   r9  rV  r   XGDMatrixCreateFromCallbackrX  r  r   re  r   )
r   r  rP  itr  	args_cstrr  reset_callbacknext_callbackr   s
             r:   r  zDMatrix._init_from_iter  s    ||||/1BOOB

 'tzz$'78	"(*(8(89K(L%..HHOOLL 
 	

Cr9   c                     t        | d      r9| j                  J t        t        j	                  | j                               | `y y Nr  )r   r  r   r   XGDMatrixFreer  s    r:   rg  zDMatrix.__del__  s=    4";;*****4;;78 #r9   )
r  r  r  r  r  r  r  rm  rn  r  c       
         `   ddl m} || j                  |       || j                  |       || j	                  |       || j                  |       || j                  d|       || j                  d|       || j                  d|       ||| _        |	|	| _	        |
 || |
d       yy)	zISet meta info for DMatrix.  See doc string for :py:obj:`xgboost.DMatrix`.r   dispatch_meta_backendNr  r  r  r  )matrixr;   r   )
r;   r  	set_label
set_weightset_base_margin	set_groupset_uint_infoset_float_inform  rn  )r   r  r  r  r  r  r  r  rm  rn  r  r  s               r:   rt  zDMatrix.set_info  s      	0NN5!OOF#"  -NN5!?uc*( 35FG( 35FG$!.D$!.D&!/8I 'r9   fieldc           
      d   t               } t        j                  t        j                               }t	        t
        j                  | j                  t        |      t        j                  |      t        j                  |                   t        ||j                  t        j                        S )a  Get float property from the DMatrix.

        Parameters
        ----------
        field: str
            The field name of the information

        Returns
        -------
        info : array
            a numpy array of float information of the data
        )r,   rH   r  r   r   r   XGDMatrixGetFloatInfor  r  r   r  rS   r   r   r   r  rO   r   s       r:   get_float_infozDMatrix.get_float_info  st     ,fnnV^^,.&&U5\6<<+?cAR	

 Crzz::r9   c           
      d   t               } t        j                  t        j                               }t	        t
        j                  | j                  t        |      t        j                  |      t        j                  |                   t        ||j                  t        j                        S )a  Get unsigned integer property from the DMatrix.

        Parameters
        ----------
        field: str
            The field name of the information

        Returns
        -------
        info : array
            a numpy array of unsigned integer information of the data
        )r,   rH   r  r   r   r   XGDMatrixGetUIntInfor  r  r   r  rS   r   r   r  s       r:   get_uint_infozDMatrix.get_uint_info  st     +fnnV]]+-%%U5\6<<+?cAR	

 Cryy99r9   c                 &    ddl m}  || ||d       y)zSet float type property into the DMatrix.

        Parameters
        ----------
        field: str
            The field name of the information

        data: numpy array
            The array of data to be set
        r   r  rd   Nr;   r  r   r  r;   r  s       r:   r  zDMatrix.set_float_info  s     	0dD%9r9   c                 &    ddl m}  || ||d       y)a   Set float type property into the DMatrix
           for numpy 2d array input

        Parameters
        ----------
        field: str
            The field name of the information

        data: numpy array
            The array of data to be set
        r   r  rd   Nr  r  s       r:   set_float_info_npy2dzDMatrix.set_float_info_npy2d  s     	0dD%9r9   c                 &    ddl m}  || ||d       y)zSet uint type property into the DMatrix.

        Parameters
        ----------
        field: str
            The field name of the information

        data: numpy array
            The array of data to be set
        r   r  r   Nr  r  s       r:   r  zDMatrix.set_uint_info  s     	0dD%:r9   fnamec           	          t        j                  t         j                  j                  |            }t	        t
        j                  | j                  t        |      t        j                  |                   y)aj  Save DMatrix to an XGBoost buffer.  Saved binary can be later loaded
        by providing the path to :py:func:`xgboost.DMatrix` as input.

        Parameters
        ----------
        fname : string or os.PathLike
            Name of the output buffer file.
        silent : bool (optional; default: True)
            If set, the output is suppressed.
        N)r   fspathr   
expanduserr   r   XGDMatrixSaveBinaryr  r  rH   r   )r   r  r  s      r:   save_binaryzDMatrix.save_binary*  sL     		"'',,U34$$T[[%,V@TU	
r9   c                 &    ddl m}  || |dd       y)zSet label of dmatrix

        Parameters
        ----------
        label: array like
            The label information to be set into DMatrix
        r   r  r  rd   Nr  )r   r  r  s      r:   r  zDMatrix.set_label:  s     	0dE7G<r9   c                 &    ddl m}  || |dd       y)a  Set weight of each instance.

        Parameters
        ----------
        weight : array like
            Weight for each data point

            .. note:: For ranking task, weights are per-group.

                In ranking task, one weight is assigned to each group (not each
                data point). This is because we only care about the relative
                ordering of data points within each group, so it doesn't make
                sense to assign weights to individual data points.

        r   r  r  rd   Nr  )r   r  r  s      r:   r  zDMatrix.set_weightF  s      	0dFHg>r9   marginc                 &    ddl m}  || |dd       y)a  Set base margin of booster to start from.

        This can be used to specify a prediction value of existing model to be
        base_margin However, remember margin is needed, instead of transformed
        prediction e.g. for logistic regression: need to put in value before
        logistic transformation see also example/demo.py

        Parameters
        ----------
        margin: array like
            Prediction margin of each datapoint

        r   r  r  rd   Nr  )r   r  r  s      r:   r  zDMatrix.set_base_marginZ  s     	0dFM7Cr9   c                 &    ddl m}  || |dd       y)zSet group size of DMatrix (used for ranking).

        Parameters
        ----------
        group : array like
            Group size of each group
        r   r  r  r   Nr  )r   r  r  s      r:   r  zDMatrix.set_groupl  s     	0dE7H=r9   c                 $    | j                  d      S )z]Get the label of the DMatrix.

        Returns
        -------
        label : array
        r  r  r  s    r:   	get_labelzDMatrix.get_labelx  s     ""7++r9   c                 $    | j                  d      S )z_Get the weight of the DMatrix.

        Returns
        -------
        weight : array
        r  r  r  s    r:   
get_weightzDMatrix.get_weight  s     ""8,,r9   c                 $    | j                  d      S )zaGet the base margin of the DMatrix.

        Returns
        -------
        base_margin
        r  r  r  s    r:   get_base_marginzDMatrix.get_base_margin  s     ""=11r9   c                 N    | j                  d      }t        j                  |      S )zUGet the group of the DMatrix.

        Returns
        -------
        group
        	group_ptr)r  r   diff)r   r  s     r:   	get_groupzDMatrix.get_group  s#     &&{3	wwy!!r9   c           	         t        j                  | j                         dz   t         j                        }t        j                  | j	                         t         j
                        }t        j                  | j	                         t         j                        }|j                  j                  t        j                  t                    }|j                  j                  t        j                  t        j                              }|j                  j                  t        j                  t        j                              }t        t        j                  i             }t!        t"        j%                  | j&                  ||||             t(        j*                  j-                  |||f| j                         | j/                         f      }|S )zGet the predictors from DMatrix as a CSR matrix. This getter is mostly for
        testing purposes. If this is a quantized DMatrix then quantized values are
        returned instead of input values.

        .. versionadded:: 1.7.0

        r   r   )r#  )r   r8  num_rowr   num_nonmissingr   r   rH   r  r  r,   c_uint32r   r@   r\   r]   r   r   XGDMatrixGetDataAsCSRr  scipysparse
csr_matrixnum_col)	r   indptrindicesr;   c_indptr	c_indicesc_dataconfigr   s	            r:   get_datazDMatrix.get_data  s0    $,,.1,BII>((4..0		Bxx++-RZZ@==(()DENN**6>>&//+JK	$$V^^FNN%CD#DJJrN3&&t{{FHiQWX	
 ll%%7F#DLLNDLLN+K & 
 
r9   c           
         | j                         }t        j                         }t        j                         }t               }t	        t
        j                  | j                  |t        j                  |      t        j                  |                   |j                  J |j                  J t        j                  |j                        }t        |      }|j                  |dz   k(  sJ |j                  t        j                   k(  sJ t        j                  |j                        }t        |      }|j                  |d   k(  sJ |j                  t        j"                  k(  sJ ||fS )zNGet quantile cuts for quantization.

        .. versionadded:: 2.0.0

        r   ro   )r  rH   rI   r^   r   r   XGDMatrixGetQuantileCutr  r   rS   r\   r   r3  sizer   r   r   r   )	r   r   	c_sindptrc_sdatar  i_indptrr  i_datar;   s	            r:   get_quantile_cutzDMatrix.get_quantile_cut  s    \\^
OO%	//#((VV\\)%<fll7>S	

 ***}}(((::ioo.%h/{{j1n,,,||ryy(((GMM*#F+yyF2J&&&zzRZZ'''t|r9   c                     t               }t        t        j                  | j                  t        j                  |                   |j                  S )z&Get the number of rows in the DMatrix.)r,   r   r   XGDMatrixNumRowr  rH   r   rS   r   r   s     r:   r  zDMatrix.num_row  5    mD((fll36GHIyyr9   c                     t               }t        t        j                  | j                  t        j                  |                   |j                  S )z4Get the number of columns (features) in the DMatrix.)r,   r   r   XGDMatrixNumColr  rH   r   rS   r  s     r:   r  zDMatrix.num_col  r  r9   c                     t               }t        t        j                  | j                  t        j                  |                   |j                  S )z_Get the number of non-missing values in the DMatrix.

        .. versionadded:: 1.7.0

        )r,   r   r   XGDMatrixNumNonMissingr  rH   r   rS   r  s     r:   r  zDMatrix.num_nonmissing  s7     mD//V\\#=NOPyyr9   c                     t               }t        t        j                  | j                  t        j                  |                   t        |j                        S )zRGet the data split mode of the DMatrix.

        .. versionadded:: 2.1.0

        )	r,   r   r   XGDMatrixDataSplitModer  rH   r   r  rS   r  s     r:   r  zDMatrix.data_split_mode  s<     mD//V\\#=NOPSYY''r9   rindexallow_groupsc                 |   ddl m} t        j                         } ||t        j
                        }t        t        j                  | j                  t        t        j                  |      t        t        |            t        j                  |      t        j                  |rdnd                   t        |      S )an  Slice the DMatrix and return a new DMatrix that only contains `rindex`.

        Parameters
        ----------
        rindex
            List of indices to be selected.
        allow_groups
            Allow slicing of a matrix with a groups attribute

        Returns
        -------
        res
            A new DMatrix containing only selected indices.
        r   )_maybe_np_slicer   r   )r;   r  rH   r9  r   r   r   r   XGDMatrixSliceDMatrixExr  r  r   r,   rJ   r   r  )r   r  r  r  r  s        r:   slicezDMatrix.slice  s    " 	*" rxx8((f-CK(V$,QA6	
 vr9   c           
      <   t               } t        j                  t        j                               }t	        t
        j                  | j                  t        d      t        j                  |      t        j                  |                   t        ||      }|sy|S )zmLabels for features (column labels).

        Setting it to ``None`` resets existing feature names.

        feature_nameNr,   rH   r  rI   r   r   XGDMatrixGetStrFeatureInfor  r  r   rY   )r   rO   sarrrm  s       r:   rm  zDMatrix.feature_names  sy     .v~~foo.0++n%V$T"		
 +48r9   c                 "   |>t        t        j                  | j                  t	        d      d t        d                   y t        || j                         | j                         t        j                  k(  d      }t        |      t        t        |            k7  rNt        j                  |ddd      \  }}t        ||      D cg c]  \  }}|dkD  s| }}}t!        d|       t#        d	 |D              st!        d
      |D cg c]  }t%        |d       }}t'        j(                  t        |      z  | }	t        t        j                  | j                  t	        d      |	t        t        |                         y c c}}w c c}w )Nr  r   zfeature namesFT)return_indexreturn_inversereturn_countsr   z0feature_names must be unique. Duplicates found: c              3   l   K   | ]+  t        t              xr t        fd dD                - yw)c              3   &   K   | ]  }|v  
 y wr>   r8   )r   xr   s     r:   r   z2DMatrix.feature_names.<locals>.<genexpr>.<genexpr>J  s     *K?a16?s   )[]<N)rD   rE   any)r   r   s    @r:   r   z(DMatrix.feature_names.<locals>.<genexpr>I  s6      
" q#Ks*K?*K'K#KK"s   14z;feature_names must be string, and may not contain [, ] or <rC   r   )r   r   XGDMatrixSetStrFeatureInfor  r  r,   r   r  r  r  r  rJ   setr   r   r  r   allrF   rH   rI   )
r   rm  r  countsr   cnt
duplicatesr   feature_names_bytesc_feature_namess
             r:   rm  zDMatrix.feature_names+  s    //KK~!6k!n
  /LLN  "m&7&77	
 }S%7!88YY"$"	NFF 14FF0CO0C94sQw$0CJOB:,O 
  
"
 
 M  DQQ=auQ9=Q!??S1D-EE 
 	++n%C./		
% P Rs   FFFc           
      <   t               } t        j                  t        j                               }t	        t
        j                  | j                  t        d      t        j                  |      t        j                  |                   t        ||      }|sy|S )zType of features (column types).

        This is for displaying the results and categorical data support. See
        :py:class:`DMatrix` for details.

        Setting it to ``None`` resets existing feature types.

        feature_typeNr  )r   rO   r  rW   s       r:   rn  zDMatrix.feature_types^  sx     .v~~foo.0++n%V$T"		
 !v.
r9   c                     |>t        t        j                  | j                  t	        d      d t        d                   y t        || j                         | j                         t        j                  k(  d      }|D cg c]  }t        |d       }}t        j                  t        |      z  | }t        t        j                  | j                  t	        d      |t        t        |                         y c c}w )Nr.  r   zfeature typesrC   r   )r   r   r%  r  r  r,   r   r  r  r  r  rF   rH   rI   rJ   )r   rn  r   feature_types_bytesc_feature_typess        r:   rn  zDMatrix.feature_typesw  s     //KK~!6k!n
 .LLN  "m&7&77	
 DQQ=auQ9=Q!??S1D-EE 
 	++n%C./		
	 Rs    C;r>   r  )T)F)8r4   r5   r6   r7   _deprecate_positional_argsr  r  r#   r   r   rd   r  r%   r&   r   rO  rD  r  rg  rt  rE   r   r  r  r  r  r  r  r   r   PathLiker  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r   r  r+  rm  r,  rn  r8   r9   r:   r  r    s      &*V/
 '++/#'0404!%%)#'1515/3#()6):):%V/V/ 	"V/
 #V/ i(V/ %V/ V/  -V/  -V/ #V/ 	"V/ i V/ $I.V/ $I.V/  "),!V/" !#V/$ '%V/& 
'V/  V/p d t .   &*&*+/%)#'15150404/3& 	"& #	&
 i(& 	"& i & $I.& $I.&  -&  -& "),& 
&  &P;C ;BJJ ;,:3 :2:: :,:C :y :T ::# :Y :4 : ;3 ;i ;D ;
sBKK'7!8 
$ 
RV 
 
=y 
=T 
=? ?t ?(Di DD D$
>y 
>T 
>,2:: ,-BJJ -2 2"2:: "%,,11 2%

BJJ(>"? <   ( ( JODIrzz12BF	B x5  * 0
8L+A 0
d 0
 0
d x5  0 
8L+A 
d 
 
r9   r  c                       e Zd ZdZddZdeddfdZdededdfdZde	j                  ddfd	Zdeddfd
Zdej                  j                  ddfdZy)rH  zdA placeholder class when DMatrix cannot be constructed (QuantileDMatrix,
    inplace_predict).

    r<   Nc                     t        j                         | _        t        t        j                  t        j                  | j                                     y r>   )rH   r9  r  r   r   XGProxyDMatrixCreater   r  s    r:   rO  z_ProxyDMatrix.__init__  s0    oo'D--fll4;;.GHIr9   r;   c                     |j                   }t        t        j                  |      d      }t	        t
        j                  | j                  |             y)z)Reference data from CUDA array interface.rC   N)r   rF   r\   r]   r   r   'XGProxyDMatrixSetDataCudaArrayInterfacer  )r   r;   r   r   s       r:   _ref_data_from_cuda_interfacez+_ProxyDMatrix._ref_data_from_cuda_interface  s>    11	djj3W=88mT	
r9   rv  c                 t    ddl m}  |||      }t        t        j	                  | j
                  |             y)z)Reference data from CUDA columnar format.r   )_cudf_array_interfacesN)r;   r;  r   r   !XGProxyDMatrixSetDataCudaColumnarr  )r   r;   rv  r;  interfaces_strs        r:   _ref_data_from_cuda_columnarz*_ProxyDMatrix._ref_data_from_cuda_columnar  s*    0/i@D::4;;WXr9   c                 n    ddl m} t        t        j	                  | j
                   ||                   y)z Reference data from numpy array.r   _array_interfaceN)r;   rA  r   r   XGProxyDMatrixSetDataDenser  )r   r;   rA  s      r:   _ref_data_from_arrayz"_ProxyDMatrix._ref_data_from_array  s'    *++DKK9I$9OP	
r9   c                 r    t        t        j                  | j                  |j	                                      y)zRReference data from a pandas DataFrame. The input is a PandasTransformed instance.N)r   r   XGProxyDMatrixSetDataColumnarr  array_interface)r   r;   s     r:   _ref_data_from_pandasz#_ProxyDMatrix._ref_data_from_pandas  s'    ..t{{D<P<P<RS	
r9   csrc           
          ddl m} t        j                  | j                   ||j
                         ||j                         ||j                         t        j                  |j                  d                y)zReference data from scipy csr.r   r@  N)
r;   rA  r   XGProxyDMatrixSetDataCSRr  r  r  rH   c_size_tr#  )r   rH  rA  s      r:   _ref_data_from_csrz _ProxyDMatrix._ref_data_from_csr  sR    *%%KKSZZ(S[[)SXX&OOCIIaL)	
r9   r  )r4   r5   r6   r7   rO  r#   r9  rG   r>  r   r  rC  rG  r  r  r  rL  r8   r9   r:   rH  rH    s    
J
( 
t 
Y Yd Yt Y
 
 

( 
t 


ell&=&= 

$ 

r9   rH  c            )           e Zd ZdZe	 ddddddddddddddddej                  ddedee	   dee	   dee	   d	ee
   d
edee   dee   dee   dee   dee   dee	   dee	   dee	   dee	   dee	   dededdf&d       Zdedee   dededdf
dZy)QuantileDMatrixac  A DMatrix variant that generates quantilized data directly from input for the
    ``hist`` tree method. This DMatrix is primarily designed to save memory in training
    by avoiding intermediate storage. Set ``max_bin`` to control the number of bins
    during quantisation, which should be consistent with the training parameter
    ``max_bin``. When ``QuantileDMatrix`` is used for validation/test dataset, ``ref``
    should be another ``QuantileDMatrix``(or ``DMatrix``, but not recommended as it
    defeats the purpose of saving memory) constructed from training dataset.  See
    :py:obj:`xgboost.DMatrix` for documents on meta info.

    .. note::

        Do not use ``QuantileDMatrix`` as validation/test dataset without supplying a
        reference (the training dataset) ``QuantileDMatrix`` using ``ref`` as some
        information may be lost in quantisation.

    .. versionadded:: 1.7.0

    Parameters
    ----------
    max_bin :
        The number of histogram bin, should be consistent with the training parameter
        ``max_bin``.

    ref :
        The training dataset that provides quantile information, needed when creating
        validation/test dataset with ``QuantileDMatrix``. Supplying the training DMatrix
        as a reference means that the same quantisation applied to the training data is
        applied to the validation/test data

    NF)r  r  r  r  rm  rn  r  max_binrs  r  r  r  r  r  rP  r  r;   r  r  r  r  r  rm  rn  r  rO  rs  r  r  r  r  r  rP  r  r<   c                t   |
| _         ||nt        j                  | _        |	|	nd| _        || _        t        |t        j                        r|| _	        y ||t        d      t        |t              r't        d ||||||||||f
D              rt        d      | j                  |||||||||||||       y )Nro   zVOnly one of the eval_qid or eval_group for each evaluation dataset should be provided.c              3   $   K   | ]  }|d u 
 y wr>   r8   )r   infos     r:   r   z+QuantileDMatrix.__init__.<locals>.<genexpr>  s!      D D s   zYIf data iterator is used as input, data like label should be specified as batch argument.)rs  r  r  r  r  r  r  r  r  rm  rn  rP  )rO  r   r  r  r  _silentrD   rH   r9  r  r   rD  r$  _init)r   r;   r  r  r  r  r  rm  rn  r  rO  rs  r  r  r  r  r  rP  r  s                      r:   rO  zQuantileDMatrix.__init__  s    . ")"5w266")"5w2dFOO,DK?u0.  dH%  !!%%#  !3 
 	

#//+''1 	 	
r9   metac                     ddl m}m}m}m}  ||      r ||      } ||      r|}	n
 |dd|i|}	t        j                         }
|	j                  |      \  }}|	j                  t        d      t        | j                  | j                  | j                        }t        j                  d |	j                   j"                  ||j"                  n||||t        j$                  |
            }|	j'                          t)        |       |
| _        y )Nr   )SingleBatchInternalIter
_is_dlpackr  _transform_dlpackr;   zZQuantileDMatrix doesn't cache data, remove the cache_prefix in iterator to fix this error.)r  r  rO  r8   )r;   rW  rX  r  rY  rH   r9  rV  rE  r   r^   r  r  rO  r   #XGQuantileDMatrixCreateFromCallbackrX  r  r   re  r   )r   r;   rs  rP  rU  rW  rX  r  rY  r  r  r  r  r  r   s                  r:   rT  zQuantileDMatrix._init5  s    	
 	
 d %T*DD>B(;d;d;B"(*(8(89K(L%??&1 
 LL$,,
 66HHOO/CJJsLL 
 	

Cr9   r>   )r4   r5   r6   r7   r2  r  r  r#   r   r   rd   r  r%   r&   r   r  rO  r   rT  r8   r9   r:   rN  rN    s   >   &*G

 '++/#'0404!%!%!%%)#'1515/3#()6):):)G
G
 	"G

 #G
 i(G
 %G
 G
  -G
  -G
 #G
 #G
 gG
 	"G
 i G
  $I.!G
" $I.#G
$ "),%G
& !'G
( ')G
* 
+G
  G
R.. g. !	.
 . 
.r9   rN  c                   0     e Zd ZdZdededdf fdZ xZS )DeviceQuantileDMatrixz\Use `QuantileDMatrix` instead.

    .. deprecated:: 1.7.0

    .. versionadded:: 1.1.0

    r  rZ   r<   Nc                 X    t        j                  dt               t        |   |i | y )Nz%Please use `QuantileDMatrix` instead.)ru   rv   r  superrO  )r   r  rZ   	__class__s      r:   rO  zDeviceQuantileDMatrix.__init__o  s$    =}M$)&)r9   )r4   r5   r6   r7   r   rO  __classcell__)r_  s   @r:   r\  r\  f  s'    *c *S *T * *r9   r\  paramsc                     t        | t              rXd| v rTt        | d   t              rA| d   }| j                  dd        t        | j	                               }|D ]
  }|d|fgz  } |S | S )Neval_metric)rD   r)  rG   popr  )ra  eval_metricsparams_listrc  s       r:   _configure_metricsrg  x  sr    64 V#vm,d3m,

=$'6<<>*'K]K899K (Mr9   c                      e Zd ZdZ	 	 	 dedee   deee      deed e	e
j                  ef      ddfdZdeeeef   eeed	f   f   deeed	f   ef   fd
Zdeeee      ef   deeeee      f   fdZdedefdZdfdZdefdZdeddfdZdeeeef   dd fdZded   fdZdefdZdeddfdZdgdZ de!dd fdZ"dgdZ#dedee   fdZ$deeee   f   fdZ%dee!   ddfd Z&d!edee'   fd"Z(d#ee'   d!eddfd$Z)e*dee+   fd%       Z,e,jZ                  d#ee+   ddfd&       Z,e*dee.   fd'       Z/e/jZ                  d#ee.   ddfd(       Z/	 dhdeee0eee!f      ef   dee   ddfd)Z1	 dhd*ed+ed,ee2   ddfd-Z3d*ed+ed.e4d/e4ddf
d0Z5	 	 	 did2eeeef      d+ed3ee6   d4e7def
d5Z8djd6ed7ed+edefd8Z9	 	 	 	 	 	 	 	 	 dkd6ed4e7d;e7d<e7d=e7d>e7d?e7d@e7dAe:dBe7de;jx                  fdCZ=d:de;j|                  d1dd9fd6e?dAe:dDedEe@d?e7dFe!dBe7de4fdGZAdHeee
j                  f   ddfdIZBdldJede	fdKZCdHeDddfdLZEe*defdM       ZFeFjZ                  d+eddfdN       ZFe*de@fdO       ZGeGjZ                  dPeddfdQ       ZGdefdRZHdefdSZI	 	 	 dmdTeee
j                  f   dUeee
j                  f   dVe7dWeddf
dXZJ	 	 	 dmdUeee
j                  f   dVe7dWedee   fdYZK	 dndUeee
j                  f   deeee@ee@   f   f   fdZZL	 dodUeee
j                  f   d[edeeee@ee@   f   f   fd\ZMdndUeee
j                  f   deNfd]ZOd6eddfd^ZPd_ee.   ddfd`ZQ	 	 	 dpdaedUee
j                  ef   dbee   dce7dee;jx                  eNf   f
ddZRy)qBoosterzA Booster of XGBoost.

    Booster is the model of xgboost, that contains low level routines for
    training, prediction and evaluation.
    Nra  cache
model_filer<   c           
         ||ng }|D ]4  }t        |t              rt        dt        |      j                   |       t        t        j                  |D cg c]  }|j                   c}      }t        j                         | _        t        t        j                  |t        t        |            t        j                  | j                                     |D ]  }| j                  |        t        |t               r| j                  J |j#                         }|d   }|d= t        j$                  t        |      z  j'                  |      }t        t        |            }	t        t        j)                  | j                  ||	             | j*                  j-                  |       nFt        |t.        t0        j2                  t4        f      r| j7                  |       n|nt        d|      |xs i }t9        |j;                               }
| j=                  |
      }
t        |
t>              r|
jA                  d       nd|
d<   | jC                  |
xs i        yc c}w )z
        Parameters
        ----------
        params :
            Parameters for boosters.
        cache :
            List of cache items.
        model_file :
            Path to the model file if it's string or PathLike.
        Nzinvalid cache item: r  zUnknown type:)validate_parametersTTrm  )"rD   r  rK   r   r4   r  rH   r9  r  r   r   XGBoosterCreater,   rJ   r   _assign_dmatrix_featuresri  __getstate__r
  r  XGBoosterUnserializeFromBuffer__dict__updaterE   r   r3  r  
load_modelrg  r$  _configure_constraintsrG   rT   	set_param)r   ra  rj  rk  rL   dmatsstater  r4  rO   params_processeds              r:   rO  zBooster.__init__  s   " *Aa)"6tAw7G7G6H I5QQ  E)BEq!((E)BC171B  {3u:.T[[0I	

 A))!,  j'*;;*** ++-E8_Fh==3v;.;;FCC V-F;;DKKfUVMM  '
S"++y$ABOOJ'OZ882-fkkm<667GH&-##$AB6:23'-2.K *Cs   I 
rS   .c                    t        t              rS t        t              rS t        j	                               }| j
                  xs g }|j                  t        |            st        d      t        fd|D              S )NDConstrained features are not a subset of training data feature namesc              3   B   K   | ]  }j                  |d         yw)r   N)r   )r   r   rS   s     r:   r   z9Booster._transform_monotone_constrains.<locals>.<genexpr>  s     BMDUYYtQ'Ms   )rD   rE   rc   r&  r   rm  issubsetr   )r   rS   constrained_featuresrm  s    `  r:   _transform_monotone_constrainsz&Booster._transform_monotone_constrains  sz     eS!LeU#L"5::<0**0b#,,S-?@V  BMBBBr9   c                 *   t        |t              r|S t        | j                  xs g       D ci c]  \  }}||
 }}}	 g }|D ]$  }|j	                  |D cg c]  }||   	 c}       & |S c c}}w c c}w # t
        $ r}t        d      |d }~ww xY w)Nr{  )rD   rE   	enumeraterm  rT   r   r   )	r   rS   idxr   feature_idx_mappingr_   
constraintr  r   s	            r:   "_transform_interaction_constraintsz*Booster._transform_interaction_constraints  s     eS!L'01C1C1Ir'J
'J)#tD#I'J 	 

	F#
KUV:<(6:V $ M
 W  	V	s/   A- A8 A3
"
A8 3A8 8	BBBc                     t        |t              rt        |j                               }t	        |      D ]E  \  }}|\  }}||dk(  r|| j                  |      f||<   *|dk(  s0|| j                  |      f||<   G |S )Nmonotone_constraintsinteraction_constraints)rD   r)  rG   r  r  r  r  )r   ra  r  r  r   rS   s         r:   ru  zBooster._configure_constraints  s    fd# &,,.)F#F+JCKD%}--#T%H%H%OPs22#T%L%LU%STs , r9   c                     t        | d      r=| j                  0t        t        j	                  | j                               d | _        y y y r  )r   r  r   r   XGBoosterFreer  s    r:   rg  zBooster.__del__  s;    4"t{{'>**4;;78DK (?"r9   c           	         | j                   j                         }|d   }|t               } t        j                  t        j
                               }t        t        j                  | j                  t        j                  |      t        j                  |                   t        ||j                        }||d<   |S r  )rr  r$  r,   rH   r  r
  r   r   XGBoosterSerializeToBufferr  r   r  rS   )r   rh  r  rO   r   bufs         r:   rp  zBooster.__getstate__  s    }}!!#h ]F06>>&--02D//KKf!5v||D7I
  fll3C DNr9   rx  c           	         |d   }||}t        t        j                  g       }t        j                         }t        t        j                  |t        d      t        j                  |                   t        t        |            }t        j                  t        |      z  j                  |      }t        t        j                  |||             ||d<   | j                  j                  |       y )Nr  r   )r  rH   r9  r   r   rn  r,   r   rJ   r
  r  rq  rr  rs  )r   rx  r  r  rw  rO   r4  s          r:   __setstate__zBooster.__setstate__  s    xCFOOR0E__&F$$UKNFLL<PQ !S*F==3s8+88=C;;FCPQ$E(OU#r9   valc           	         t        |t        j                  t        f      r!t	        t        |      t        |dz               }t        |t        t                    rt	        dd      }t        |t              rt        d      t        |t              sGt        t        t        t        j                  t        t              ft        |            }t        |      t        |j                  t        t                    s|j                  d}n|j                  }t        |j                  t        t                    s|j                  d}n|j                  }||k  rt        d|      |j                  |j                  nd}t        j                  |      }t        j                  |      }t        j                  |      }t        j                          }	t"        j%                  | j&                  |||t        j(                  |	            }
|
dk(  rt+        d      t-        |
       t/               }t-        t"        j1                  |j&                               |	|_        |S )zOGet a slice of the tree-based model.

        .. versionadded:: 1.3.0

        r   r   z*Only supports slicing through 1 dimension.zInvalid slicezLayer index out of range)rD   r   integerr   r  r   Ellipsisrc   r   rr   rK   startstopsteprH   r   r9  r   XGBoosterSlicer  r   
IndexErrorr   ri  r  )r   r  rp   r  r  r  c_startc_stopc_stepsliced_handlestatussliceds               r:   __getitem__zBooster.__getitem__(  s    cBJJ,-C#cAg,/Cc4>*1+Cc5!IJJ #u%3rzz4>BDINCC. ciih0CII4EEIIEchhX/3883CD88De| #6688/sxxQ,,u%d#d#)$$KK&&&,,}2M
 R<788FD&&v}}56%r9   )ri  NNc              #   X   K   t        d| j                               D ]	  }| |     yw)zXIterator method for getting individual trees.

        .. versionadded:: 2.0.0

        r   N)rR   num_boosted_rounds)r   rX   s     r:   __iter__zBooster.__iter__Y  s+      q$1134Aq'M 5s   (*c           	      2   t        j                         }t               }t        t        j                  | j                  t        j                  |      t        j                  |                   |j                  J |j                  j                         }|S )zwOutput internal parameter configuration of Booster as a JSON
        string.

        .. versionadded:: 1.0.0

        )
rH   rI   r,   r   r   XGBoosterSaveJsonConfigr  r   rS   rU   )r   json_stringrO   r_   s       r:   save_configzBooster.save_configb  sw     oo'((V\\&16<<3L	

   ,,,""))+r9   r  c                     t        |t              sJ t        t        j	                  | j
                  t        |                   y)zWLoad configuration returned by `save_config`.

        .. versionadded:: 1.0.0
        N)rD   rE   r   r   XGBoosterLoadJsonConfigr  r  )r   r  s     r:   load_configzBooster.load_configt  s1    
 &#&&&D00eFmLMr9   c                 $    | j                  d       S r>   )__deepcopy__r  s    r:   __copy__zBooster.__copy__|  s      &&r9   r  c                     t        |       S )zReturn a copy of booster.)rk  )ri  )r   r  s     r:   r  zBooster.__deepcopy__  s    $''r9   c                 ,    t        j                   |       S )zwCopy the booster object.

        Returns
        -------
        booster :
            A copied booster model
        r/  r  s    r:   r$  zBooster.copy  s     yyr9   keyc           
      \   t        j                         }t        j                         }t        t        j                  | j                  t        |      t        j                  |      t        j                  |                   |j                  dk7  r|j                  }|sJ t        |      S y)a  Get attribute string from the Booster.

        Parameters
        ----------
        key :
            The key to get attribute from.

        Returns
        -------
        value :
            The attribute value of the key, returns None if attribute do not exist.
        r   N)rH   rI   r   r   r   XGBoosterGetAttrr  r  r   rS   r0   )r   r  r   successrS   s        r:   attrzBooster.attr  s     oo,,.!!U3Zc):FLL<Q	

 ==AIIEL5%= r9   c           	      h   t               } t        j                  t        j                               }t	        t
        j                  | j                  t        j                  |      t        j                  |                   t        ||      }|D ci c]  }|| j                  |       c}S c c}w )zGet attributes stored in the Booster as a dictionary.

        Returns
        -------
        result : dictionary of  attribute_name: attribute_value pairs of strings.
            Returns an empty dict if there's no attributes.
        )r,   rH   r  rI   r   r   XGBoosterGetAttrNamesr  r   rY   r  )r   rO   r  
attr_namesrh   s        r:   
attributeszBooster.attributes  s     .v~~foo.0&&V\\&16<<3E	

 (f5
)34A499Q<444s   B/rZ   c           	          |j                         D ]P  \  }}d}|t        t        |            }t        t        j                  | j                  t        |      |             R y)zSet the attribute of the Booster.

        Parameters
        ----------
        **kwargs
            The attributes to set. Setting a value to None deletes an attribute.
        N)r  r  rE   r   r   XGBoosterSetAttrr  )r   rZ   r  rS   c_values        r:   set_attrzBooster.set_attr  sP     !,,.JCG E
+--dkk5:wOP	 )r9   r  c           
      p   t               } t        j                  t        j                               }t	        | d      r| j
                  y t        t        j                  | j
                  t        |      t        j                  |      t        j                  |                   t        ||      }|r|S d S r  )r,   rH   r  rI   r   r  r   r   XGBoosterGetStrFeatureInfor  r   rY   )r   r  rO   r  r   s        r:   _get_feature_infozBooster._get_feature_info  s    .v~~foo.0tX&$++*=++eV$T"		
 *$7+|55r9   featuresc                    |t        |t              sJ |D cg c]  }t        |d       }}t        j                  t        |      z  | }t        t        j                  | j                  t        |      |t        t        |                         y t        t        j                  | j                  t        |      d t        d                   y c c}w )NrC   r   r   )rD   rG   rF   rH   rI   rJ   r   r   XGBoosterSetStrFeatureInfor  r  r,   )r   r  r  r   feature_info_bytesc_feature_infos         r:   _set_feature_infozBooster._set_feature_info  s    h---FN!Oh%G"<h!O$oo4F0GG#N //KK%L"H.	 //KKut[^ "Ps   Cc                 $    | j                  d      S )zFeature types for this booster.  Can be directly set by input data or by
        assignment.  See :py:class:`DMatrix` for details.

        r.  r  r  s    r:   rn  zBooster.feature_types       %%n55r9   c                 (    | j                  |d       y )Nr.  r  r   r  s     r:   rn  zBooster.feature_types      x8r9   c                 $    | j                  d      S )zfFeature names for this booster.  Can be directly set by input data or by
        assignment.

        r  r  r  s    r:   rm  zBooster.feature_names  r  r9   c                 (    | j                  |d       y )Nr  r  r  s     r:   rm  zBooster.feature_names  r  r9   c                    t        |t              r|j                         }nt        |t              r|||fg}t	        t
        t        t        t        f      |      D ]w  \  }}t        |t        j                        r|j                         }|3t        t        j                  | j                  t        |      t        t        |                         y y)a   Set parameters into the Booster.

        Parameters
        ----------
        params :
           list of key,value pairs, dict of key to value or simply str key
        value :
           value of the specified parameter, when params is str key
        N)rD   r   r  rE   r   r   r   r   r  tolistr   r   XGBoosterSetParamr  r  )r   ra  rS   r  r  s        r:   rv  zBooster.set_param  s     fg&\\^F$):uo&FXeCHo6?HC#rzz*jjl**4;;c
E#c(OT	 @r9   dtrain	iterationfobjc                    t        |t              s!t        dt        |      j                         | j                  |       |Ht        t        j                  | j                  t        j                  |      |j                               y| j                  |dd      } |||      \  }}| j                  ||||       y)aX  Update for one iteration, with objective function calculated
        internally.  This function should not be called directly by users.

        Parameters
        ----------
        dtrain :
            Training data.
        iteration :
            Current iteration number.
        fobj :
            Customized objective function.

        zinvalid training matrix: NT)output_margintraining)r  gradhess)rD   r  rK   r   r4   ro  r   r   XGBoosterUpdateOneIterr  rH   r   predictboost)r   r  r  r  predr  r  s          r:   rs  zBooster.update  s      &'*7V8M8M7NOPP%%f-<++KKi!8&-- <<dT<JDdF+JD$JJvDJIr9   r  r  c                   	
 ddl mmmm	 | j                         dt        dt        fd
dt        dt        f	
fd}t        t        j                  | j                  j                  | ||       ||                   y)a  Boost the booster for one iteration with customized gradient statistics.
        Like :py:func:`xgboost.Booster.update`, this function should not be called
        directly by users.

        Parameters
        ----------
        dtrain :
            The training DMatrix.
        grad :
            The first order of gradient.
        hess :
            The second order of gradient.

        r   )rA  r   _ensure_np_dtype_is_cupy_aliker0  r<   c                 Z    t        | j                        dk(  xs | j                  d   dk(  S )Nr   )rJ   r#  )r0  s    r:   
is_flattenz!Booster.boost.<locals>.is_flattenX  s(    u{{#q(?EKKNa,??r9   c                    dt        |        }t        | t        j                        s |       st	        |      	j                         }| j                  d   |k7  rA 
|       r9t        j                  dt               | j                  || j                  |z        } t        | t        j                        r  | | j                        \  } } |       }|S  |       r
 |       }|S t	        |      )NzHExpecting `np.ndarray` or `cupy.ndarray` for gradient and hessian. Got: r   zvSince 2.1.0, the shape of the gradient and hessian is required to be (n_samples, n_targets) or (n_samples, n_classes).)r   rD   r   r  rK   r  r#  ru   rv   r  reshaper  r   )r0  rp   	n_samplesr  r   rA  r   r  r  r  r  s        r:   rF  z&Booster.boost.<locals>.array_interface[  s    e'  eRZZ09Nn$(I{{1~*z%/@L!
 iy1HI%,+E5;;?q,U3	   &1%8	   n$r9   N)r;   rA  r   r  r  ro  r*   r  rF   r   r   XGBoosterTrainOneIterr  )r   r  r  r  r  rF  rA  r   r  r  r  s    `    @@@@@r:   r  zBooster.boost>  s    "	
 	
 	%%f-	@k 	@d 	@	; 	5 	 	8 	&&%%	
r9   Tevalsfevalr  c                    |D ]  }t        |d   t              s$t        dt        |d         j                         t        |d   t
              s$t        dt        |d         j                         | j                  |d           t        t        j                  |D cg c]  }|d   j                   c}      }t        t        j                  |D cg c]  }t        |d          c}      }t        j                         }t        t        j                  | j                  t        j                   |      ||t#        t%        |            t        j&                  |                   |j(                  J |j(                  j+                         }	|[|D ]V  \  }
} || j-                  |
d|      |
      }t        |t.              r|D ]  \  }}|	d|||fz  z  }	 G|\  }}|	d|||fz  z  }	X |	S c c}w c c}w )aH  Evaluate a set of data.

        Parameters
        ----------
        evals :
            List of items to be evaluated.
        iteration :
            Current iteration.
        feval :
            Custom evaluation function.

        Returns
        -------
        result: str
            Evaluation result string.
        r   zexpected DMatrix, got r   zexpected string, got F)r  r  z		%s-%s:%f)rD   r  rK   r   r4   rE   ro  r  rH   r9  r  rI   r  r   r   XGBoosterEvalOneIterr   r,   rJ   r   rS   rU   r  rG   )r   r  r  r  r  rL   rw  evnamesrp   rW   dmatevname	feval_retr   r  s                  r:   eval_setzBooster.eval_set  s   0 AadG,"8ad9L9L8M NOOadC("7QqT
8K8K7L MNN))!A$/  u)Eu!!A$++u)EF&//+GAE!A$K+GHoo%%Y'CJ'S!		
 yy$$$ii  %f!LL]LS	 i.%.	c|vtS.AAA &/ !*ID#<64*===C !& 
; *F+Gs   "G3
G8
r;   r   c                 N    | j                  |       | j                  ||fg|      S )aS  Evaluate the model on mat.

        Parameters
        ----------
        data :
            The dmatrix storing the input.

        name :
            The name of the dataset.

        iteration :
            The current iteration number.

        Returns
        -------
        result: str
            Evaluation result string.
        )ro  r  )r   r;   r   r  s       r:   evalzBooster.eval  s)    & 	%%d+}}tTl^Y77r9   Fr   r   	pred_leafpred_contribsapprox_contribspred_interactionsvalidate_featuresr  iteration_rangestrict_shapec                    t        |t              st        dt        |            |r|j                  }| j                  |       d|t        |	d         t        |	d         |
ddt        ddffd}|r |d       |r ||sd	nd
       |r ||sdnd       |r |d        t        j                  t        j                               } t        j                  t                     }t               }t        t        j                  | j                  |j                  t        t!        j"                              t        j$                  |      t        j$                  |      t        j$                  |                   t'        |||d      S )a*  Predict with data.  The full model will be used unless `iteration_range` is
        specified, meaning user have to either slice the model or use the
        ``best_iteration`` attribute to get prediction from best model returned from
        early stopping.

        .. note::

            See :doc:`Prediction </prediction>` for issues like thread safety and a
            summary of outputs from this function.

        Parameters
        ----------
        data :
            The dmatrix storing the input.

        output_margin :
            Whether to output the raw untransformed margin value.

        pred_leaf :
            When this option is on, the output will be a matrix of (nsample,
            ntrees) with each record indicating the predicted leaf index of
            each sample in each tree.  Note that the leaf index of a tree is
            unique per tree, so you may find leaf 1 in both tree 1 and tree 0.

        pred_contribs :
            When this is True the output will be a matrix of size (nsample,
            nfeats + 1) with each record indicating the feature contributions
            (SHAP values) for that prediction. The sum of all feature
            contributions is equal to the raw untransformed margin value of the
            prediction. Note the final column is the bias term.

        approx_contribs :
            Approximate the contributions of each feature.  Used when ``pred_contribs`` or
            ``pred_interactions`` is set to True.  Changing the default of this parameter
            (False) is not recommended.

        pred_interactions :
            When this is True the output will be a matrix of size (nsample,
            nfeats + 1, nfeats + 1) indicating the SHAP interaction values for
            each pair of features. The sum of each row (or column) of the
            interaction values equals the corresponding SHAP value (from
            pred_contribs), and the sum of the entire matrix equals the raw
            untransformed margin value of the prediction. Note the last row and
            column correspond to the bias term.

        validate_features :
            When this is True, validate that the Booster's and data's
            feature_names are identical.  Otherwise, it is assumed that the
            feature_names are the same.

        training :
            Whether the prediction value is used for training.  This can effect `dart`
            booster, which performs dropouts during training iterations but use all trees
            for inference. If you want to obtain result with dropouts, set this parameter
            to `True`.  Also, the parameter is set to true when obtaining prediction for
            custom objective function.

            .. versionadded:: 1.0.0

        iteration_range :
            Specifies which layer of trees are used in prediction.  For example, if a
            random forest is trained with 100 rounds.  Specifying `iteration_range=(10,
            20)`, then only the forests built during [10, 20) (half open set) rounds are
            used in this prediction.

            .. versionadded:: 1.4.0

        strict_shape :
            When set to True, output shape is invariant to whether classification is used.
            For both value and margin prediction, the output shape is (n_samples,
            n_groups), n_groups == 1 when multi-class is not used.  Default to False, in
            which case the output shape can be (n_samples, ) if multi-class is not used.

            .. versionadded:: 1.4.0

        Returns
        -------
        prediction : numpy array

        z,Expecting data to be a DMatrix object, got: r   r   )r   r  iteration_beginiteration_endr  rq   r<   Nc                 6    d   dk7  rt        d      | d<   y )Nr   r   z!One type of prediction at a time.)r   )rq   r  s    r:   assign_typez$Booster.predict.<locals>.assign_type@	  s$    F|q  !DEEDLr9   r7              F)rD   r  rK   r   rm  _validate_featuresr   rH   r  r   r,   r   r   XGBoosterPredictFromDMatrixr  r@   r\   r]   r   rB  )r   r;   r  r  r  r  r  r  r  r  r  rY  r  predsr#  r=  r  s                   @r:   r  zBooster.predict  sM   z $(JDQUJWW##B##B' "?1#56 !34(
	3 	4 	
 Na8a8N.v~~.0+{+-},,"4::d#34U#T"U#		
 "%ue<<r9   predict_typer  r  c                     t        j                  t         j                               }t        |dk(  rdnddt	        |d         t	        |d         ||d      }	 t        j                  t
                     }
t               }|-t               }|J |j                  |       |j                  }nd}t        j                         }|t        |t              sJ ddlm}m}m}m}m}m}m}m}m}m}m}m}m}  ||      r|j2                  }d	} ||      r ||      } ||      rddl}|j7                  |      } ||      r  |||      \  }}}|r| j9                  |        ||      s ||      rt;        j<                  |      }|r{t?        |d
      stA        d      tC        |jD                        dk7  rL| jG                         |jD                  d   k7  r,tI        d| jG                          d|jD                  d           ||      rddlm%}  |||jL                        \  }}tO        tP        jS                  | j                   ||      |	|t        jT                  |
      t        jT                  |      t        jT                  |                   tW        |
||d      S t        ||      rtO        tP        jY                  | j                  |j[                         |	|t        jT                  |
      t        jT                  |      t        jT                  |                   tW        |
||d      S t        |t\        j^                  j`                        rddlm1}   | |d	      }tO        tP        je                  | j                   ||jf                         ||jh                         ||j                        t        |jD                  d         |	|t        jT                  |
      t        jT                  |      t        jT                  |      
             tW        |
||d      S  ||      rddlm5}!  |!|      }tm        |      }"tO        tP        jo                  | j                  |"|	|t        jT                  |
      t        jT                  |      t        jT                  |                   tW        |
||d	      S  ||      rddlm8}#m9}$  |$|dd|      \  }}%}} |#||%      }&|r| j9                  |       tO        tP        ju                  | j                  |&|	|t        jT                  |
      t        jT                  |      t        jT                  |                   tW        |
||d	      S tA        dtw        ty        |            z   dz         )a  Run prediction in-place when possible, Unlike :py:meth:`predict` method,
        inplace prediction does not cache the prediction result.

        Calling only ``inplace_predict`` in multiple threads is safe and lock
        free.  But the safety does not hold when used in conjunction with other
        methods. E.g. you can't train the booster in one thread and perform
        prediction in the other.

        .. note::

            If the device ordinal of the input data doesn't match the one configured for
            the booster, data will be copied to the booster device.

        .. code-block:: python

            booster.set_param({"device": "cuda:0"})
            booster.inplace_predict(cupy_array)

            booster.set_param({"device": "cpu"})
            booster.inplace_predict(numpy_array)

        .. versionadded:: 1.1.0

        Parameters
        ----------
        data :
            The input data.
        iteration_range :
            See :py:meth:`predict` for details.
        predict_type :
            * `value` Output model prediction values.
            * `margin` Output the raw untransformed margin value.
        missing :
            See :py:obj:`xgboost.DMatrix` for details.
        validate_features:
            See :py:meth:`xgboost.Booster.predict` for details.
        base_margin:
            See :py:obj:`xgboost.DMatrix` for details.

            .. versionadded:: 1.4.0

        strict_shape:
            See :py:meth:`xgboost.Booster.predict` for details.

            .. versionadded:: 1.4.0

        Returns
        -------
        prediction : numpy.ndarray/cupy.ndarray
            The prediction result.  When input data is on GPU, prediction result is
            stored in a cupy array.

        r  r   r   F)r   r  r  r  r  r  cache_idN)r  )PandasTransformedrA  _arrow_transform	_is_arrow_is_cudf_df_is_cudf_pandasr  _is_list_is_np_array_like_is_pandas_df_is_pandas_series	_is_tuple_transform_pandas_dfTr#  z?`shape` attribute is required when `validate_features` is True.z"Feature shape mismatch, expected: r   )r  )transform_scipy_sparse)_transform_cupy_array)r;  _transform_cudf_dfz
Data type:z% not supported by inplace prediction.)=rH   r  r   r^   r   r,   rH  rt  r  r9  rD   r;   r	  rA  r
  r  r  r  r  r  r  r  r  r  r  _fsproxy_fastpandasr.   r  r   r0  r   rK   rJ   r#  num_featuresr   r  r   r   r   XGBoosterPredictFromDenser   rB  XGBoosterPredictFromColumnarrF  r  r  r  r  XGBoosterPredictFromCSRr  r  r  r   XGBoosterPredictFromCudaArrayr;  r   XGBoosterPredictFromCudaColumnarrE   r   )'r   r;   r  r  r  r  r  r  r  r  r#  r=  rX  p_handler	  rA  r
  r  r  r  r  r  r  r  r  r  r  rP  pdfnsr  r  r  r  r   r;  r  rv  r=  s'                                          r:   inplace_predictzBooster.inplace_predict]	  s   ~ /v~~.0 "h.A 23oa01%
 ,{+-}"-:_E$$$NN{N3||HE(H}
5- @@@	
 	
 	
 	
  4 %%D!T?#D)DT"<<%D/6HILD#q '',D>Yt_88D>D4)U  4::!#(9(9(;tzz!}(L 89J9J9L8M N::a=/+ 
 T".&tTZZ8GD!..KK$T*LL'LL&LL'
 &eT5%@@d-.11KK((*LL'LL&LL'
 &eT5%@@dELL3344)$5D,,KK$T[[1$T\\2$TYY/

1.LL'LL&LL' &eT5%@@$3(.D1$7M22KK!LL'LL&LL'
 &eT5$??tH&8dD"4'#D)S! 4D)DN '',55KK"LL'LL&LL'
 &eT5$??3tDz?*-TT
 	
r9   r  c                 "   t        |t        t        j                  f      ret        j                  t        j
                  j                  |            }t        t        j                  | j                  t        |                   yt        d      )aE  Save the model to a file.

        The model is saved in an XGBoost internal format which is universal among the
        various XGBoost interfaces. Auxiliary attributes of the Python Booster object
        (such as feature_names) are only saved when using JSON or UBJSON (default)
        format. See :doc:`Model IO </tutorials/saving_model>` for more info.

        .. code-block:: python

          model.save_model("model.json")
          # or
          model.save_model("model.ubj")

        Parameters
        ----------
        fname :
            Output file name

        z%fname must be a string or os PathLikeN)rD   rE   r   r3  r  r   r  r   r   XGBoosterSaveModelr  r  rK   )r   r  s     r:   
save_modelzBooster.save_model<
  s]    ( ec2;;/0IIbgg0078E//U5\JKCDDr9   
raw_formatc           
      L   t               } t        j                  t        j                               }t	        |      }t        t        j                  | j                  |t        j                  |      t        j                  |                   t        ||j                        S )az  Save the model to a in memory buffer representation instead of file.

        The model is saved in an XGBoost internal format which is universal among the
        various XGBoost interfaces. Auxiliary attributes of the Python Booster object
        (such as feature_names) are only saved when using JSON or UBJSON (default)
        format. See :doc:`Model IO </tutorials/saving_model>` for more info.

        Parameters
        ----------
        raw_format :
            Format of output buffer. Can be `json`, `ubj` or `deprecated`.

        Returns
        -------
        An in memory buffer representation of the model
        )r  )r,   rH   r  r
  r^   r   r   XGBoosterSaveModelToBufferr  r   r  rS   )r   r&  rO   r   r  s        r:   save_rawzBooster.save_rawV
  st    " ,v~~fmm,.J/++VV\\&%96<<;M	

 T6<<00r9   c                    t        |t        t        j                  f      ret        j                  t        j
                  j                  |            }t        t        j                  | j                  t        |                   yt        |t              rl|}t        t        |            }t        j                   t        |      z  j#                  |      }t        t        j%                  | j                  ||             yt'        d|      )ay  Load the model from a file or a bytearray.

        The model is saved in an XGBoost internal format which is universal among the
        various XGBoost interfaces. Auxiliary attributes of the Python Booster object
        (such as feature_names) are only saved when using JSON or UBJSON (default)
        format. See :doc:`Model IO </tutorials/saving_model>` for more info.

        .. code-block:: python

          model.load_model("model.json")
          # or
          model.load_model("model.ubj")

        Parameters
        ----------
        fname :
            Input file name or memory buffer(see also save_raw)

        zUnknown file type: N)rD   rE   r   r3  r  r   r  r   r   XGBoosterLoadModelr  r  r  r,   rJ   rH   r
  r  XGBoosterLoadModelFromBufferrK   )r   r  r  rO   r4  s        r:   rt  zBooster.load_modelq
  s    ( ec2;;/0 IIbgg0078E//U5\JKy)C S*F==3s8+88=C99$++sFST1599r9   c                 T    | j                  d      }|t        |      S t        d      )z#The best iteration during training.best_iterationz=`best_iteration` is only defined when early stopping is used.)r  r   AttributeErrorr   bests     r:   r.  zBooster.best_iteration
  s3     yy)*t9K
 	
r9   c                 (    | j                  |       y )N)r.  r  )r   r  s     r:   r.  zBooster.best_iteration
  s    Y/r9   c                 T    | j                  d      }|t        |      S t        d      )z*The best evaluation score during training.
best_scorez9`best_score` is only defined when early stopping is used.)r  rd   r/  r0  s     r:   r5  zBooster.best_score
  s2     yy&;G
 	
r9   scorec                 (    | j                  |       y )N)r5  r3  )r   r6  s     r:   r5  zBooster.best_score
  s    'r9   c                     t        j                         }| j                  J t        t        j                  | j                  t        j                  |                   |j                  S )zmGet number of boosted rounds.  For gblinear this is reset to 0 after
        serializing the model.

        )rH   r   r  r   r   XGBoosterBoostedRoundsr   rS   )r   roundss     r:   r  zBooster.num_boosted_rounds
  sK    
 {{&&&D//V\\&=QRS||r9   c                     t               }| j                  J t        t        j	                  | j                  t        j                  |                   |j                  S )zNumber of features in booster.)r,   r  r   r   XGBoosterGetNumFeaturerH   r   rS   r  s     r:   r  zBooster.num_features
  sE    ={{&&&D//V\\(=STU~~r9   foutfmap
with_statsdump_formatc                 n   t        |t        t        j                  f      rCt        j                  t        j
                  j                  |            }t        |dd      }d}n|}d}| j                  |||      }|dk(  rj|j                  d       t        |      D ]9  \  }}	|j                  |	       |t        |      dz
  k  s)|j                  d	       ; |j                  d
       n9t        |      D ]+  \  }}	|j                  d| d       |j                  |	       - |r|j                          yy)a1  Dump model into a text or JSON file.  Unlike :py:meth:`save_model`, the
        output format is primarily used for visualization or interpretation,
        hence it's more human readable but cannot be loaded back to XGBoost.

        Parameters
        ----------
        fout :
            Output file name.
        fmap :
            Name of the file containing feature map names.
        with_stats :
            Controls whether the split statistics are output.
        dump_format :
            Format of model dump file. Can be 'text' or 'json'.
        wrC   r   TFr\   z[
r   z,
z
]zbooster[z]:
N)rD   rE   r   r3  r  r   r  r   get_dumpwriter  rJ   close)
r   r=  r>  r?  r@  fout_obj
need_closer   rX   r  s
             r:   
dump_modelzBooster.dump_model
  s   , dS"++./99RWW//56DD#8HJHJmmD*k:& NN5!#C.3s#s3x!|#NN5) ) NN5!#C.3!D12s# ) NN r9   c                    t        j                  t         j                  j                  |            }t	               } t        j                  t
        j                               }t        t        j                  | j                  t        |      t        j                  |      t        |      t        j                  |      t        j                  |                   t        ||      }|S )a  Returns the model dump as a list of strings.  Unlike :py:meth:`save_model`,
        the output format is primarily used for visualization or interpretation, hence
        it's more human readable but cannot be loaded back to XGBoost.

        Parameters
        ----------
        fmap :
            Name of the file containing feature map names.
        with_stats :
            Controls whether the split statistics are output.
        dump_format :
            Format of model dump. Can be 'text', 'json' or 'dot'.

        )r   r  r   r  r,   rH   r  rI   r   r   XGBoosterDumpModelExr  r  r   r   rY   )r   r>  r?  r@  rO   r  rW   s          r:   rC  zBooster.get_dump
  s    ( yy++D12.v~~foo.0%%dZ(k"V$T"		
 !v.
r9   c                 (    | j                  |d      S )au  Get feature importance of each feature.

        .. note:: Zero-importance features will not be included

           Keep in mind that this function does not include zero-importance feature, i.e.
           those features that have not been used in any split conditions.

        Parameters
        ----------
        fmap :
           The name of feature map file
        r  )importance_type)	get_score)r   r>  s     r:   
get_fscorezBooster.get_fscore  s      ~~dH~==r9   rL  c                    t        j                  t         j                  j                  |            } t	        j
                  t        j                               } t	        j
                  t        j                               }t               }t               } t	        j
                  t                     }t        t        j                  | j                  t        ||      t	        j                  |      t	        j                  |      t	        j                  |      t	        j                  |      t	        j                  |                   t        ||      }t!        |||d      }	i }
t#        |	j$                        dkD  rD|	j$                  d   dkD  r2t'        ||	      D ]!  \  }}|D cg c]  }t)        |       c}|
|<   # |
S t'        ||	      D ]  \  }}t)        |      |
|<    |
S c c}w )a'  Get feature importance of each feature.
        For tree model Importance type can be defined as:

        * 'weight': the number of times a feature is used to split the data across all trees.
        * 'gain': the average gain across all splits the feature is used in.
        * 'cover': the average coverage across all splits the feature is used in.
        * 'total_gain': the total gain across all splits the feature is used in.
        * 'total_cover': the total coverage across all splits the feature is used in.

        .. note::

           For linear model, only "weight" is defined and it's the normalized coefficients
           without bias.

        .. note:: Zero-importance features will not be included

           Keep in mind that this function does not include zero-importance feature, i.e.
           those features that have not been used in any split conditions.

        Parameters
        ----------
        fmap :
           The name of feature map file.
        importance_type :
            One of the importance types defined above.

        Returns
        -------
        A map between feature names and their scores.  When `gblinear` is used for
        multi-class classification the scores for each feature is a list with length
        `n_classes`, otherwise they're scalars.
        )rL  feature_mapFr   )r   r  r   r  rH   r  rI   r   r,   r   r   XGBoosterFeatureScorer  r^   r   rY   rB  rJ   r#  r  rd   )r   r>  rL  r  scoresn_out_featuresout_dimr#  features_arr
scores_arrresultsfeatr6  rf   s                 r:   rM  zBooster.get_score$  s   F yy++D1226>>&//24//1$-+{+-&&ON^,X&W%U#V$
	
 *(NC'wF
8:z 1$)9)9!)<q)@"<<e38 95aq5 9  =
   #<<e %e  =	 !:s   )G)c                 	   t        j                  t         j                  j                  |            }t        st        d      t        j                  | j                               d   d   d   }|dvrt        d|       g }g }g }g }g }g }g }	g }
g }g }| j                  |d      }t        |      D ]x  \  }}|j                  d	      D ]]  }|j                  d
      }t        |      dk(  rH|dgk(  r+|d   j                  d      }t        j                  d|d         }|j                  |       |j                  t!        t        j"                  d|d         d                |j                  d       |j                  t%        d             |j                  t%        d             |j                  t%        d             |	j                  t%        d             |
j                  t%        d             |j                  t%        |d                |j                  t%        |d                l|d   j                  d      }|d   j'                  d      dk7  rC|d   j                  d      }|j                  t%        |d                |j                  d       n|d   j'                  d      dk7  r]|d   j                  d      }|d   dd }|j                  d      }|j                  t%        d             |j                  |r|nd       nt        d      t        j                  d|d         }|j                  |       |j                  t!        t        j"                  d|d         d                |j                  |d          t)        |      }|j                  |dz   |d   z          |	j                  |dz   |d   z          |
j                  |dz   |d   z          |j                  t%        |d                |j                  t%        |d                ` { t+        ||      D cg c]  \  }}t)        |      dz   t)        |      z   ! }}}t-        |||||||	|
|||d      }t/        t1        |d d            r#|j3                  d!d"g      j5                  d#      S |j7                  d!d"g      j5                  d#      S c c}}w )$a  Parse a boosted tree model text dump into a pandas DataFrame structure.

        This feature is only defined when the decision tree model is chosen as base
        learner (`booster in {gbtree, dart}`). It is not defined for other base learner
        types, such as linear learners (`booster=gblinear`).

        Parameters
        ----------
        fmap :
           The name of feature map file.
        zPpandas must be available to use this method.Install pandas before calling again.learnergradient_boosterr   >   dartgbtreez,This method is not defined for Booster type T)r?  r   r!  r   r  r   ra   z=|,z\b\d+\bLeafNANr  r"  r#  ro   Nz:{,z Failed to parse model text dump.r   r     	   )TreeNodeIDFeatureSplitYesNoMissingGainCoverCategorysort_valuesrc  rd  )drop)r   r  r   r  r-   ImportErrorr\   r   r  r   rC  r  rb   rJ   rerT   r   findallrd   rt   rE   r  r.   callablegetattrrn  reset_indexsort)r   r>  r   tree_idsnode_idsfidssplits
categories	y_directs	n_directsmissingsgainscoverstreesrX   treeliner1  r   statsfidcats
cats_splitstr_it_idn_ididsdfs                               r:   trees_to_dataframezBooster.trees_to_dataframef  sV    yy++D12;  **T--/0;<NOPVW,,KG9UVV*,>@
-/	-/	,.dt4 'GAt

4(jjos8q=rd{ FLL-EHHUE!H5E OOA&OOC

:uQx(H(K$LMKK'MM%,/%%eEl3$$U5\2$$U5\2OOE%L1LLuQx1MM%a/2 a&,,s+C1v{{3'2- #AS 1eE!Ho6"))$/QT*b0 #AS 1$Qx"~%)ZZ_
eEl3"))
*M()KLLHHUCF3E OOA&OOC

:s1v(Fq(I$JKKKa)FE$$US[58%;<$$US[58%;<OOECK%($:;LLuQx1MM%a/2g ) (l >A8=TU=TztTs4y3T*=TU   #&
  GBt45>>66"23??T?JJww'(44$4??+ Vs   ?$Sc                     |j                         dk(  ry |j                  }|j                  }| j                  || _        | j                  || _        | j                  |       y r   )r  rm  rn  r  )r   r;   rY  fts       r:   ro  z Booster._assign_dmatrix_features  s_    <<>Q%!#D%!#D#r9   rm  c                 n   | j                   y |3| j                   't        ddj                  | j                         z         | j                   |k7  rt        t	        t
        | j                               t        t	        t
        |            z
  }t        t	        t
        |            t        t	        t
        | j                               z
  }d}|r!|ddj                  d |D              z   dz   z  }|r|ddj                  d |D              z   z  }t        |j                  | j                   |            y )	Nz1training data did not have the following fields: r  zfeature_names mismatch: {0} {1}z

expected c              3   2   K   | ]  }t        |        y wr>   r   r   rf   s     r:   r   z-Booster._validate_features.<locals>.<genexpr>  s     <1Ar   z in input dataz2
training data did not have the following fields: c              3   2   K   | ]  }t        |        y wr>   r   r  s     r:   r   z-Booster._validate_features.<locals>.<genexpr>  s     ;
1A
r   )rm  r   r   r&  r   r%   r  )r   rm  dat_missing
my_missingrp   s        r:   r  zBooster._validate_features  s9   % T%7%7%CC))D../0 
 .d<1C1CDE\=1I K T,>?#\4#5#56C J 4C!ii<<<=&' Iii;
;;<
 SZZ(:(:MJKK/ /r9   featurebins	as_pandasc           	         | j                  |      }g }t        j                  dj                  |            }|D ]@  }t        j                  ||      }	|j                  |	D 
cg c]  }
t        |
       c}
       B t        t        j                  |            }t        |t        ||      n|d      }t        j                  ||      }t        j                  |d   dd |d   f      }||dddf   dkD     }|j                  dk(  r| j                  }| j                   }|)t#        | j%                               D cg c]  }d| 	 }}	 |j'                  |      }t)        t*        t,           |      |   }|dk(  rt/        d	      |rt4        rt7        |d
dg      S |r t4        st9        j:                  dt<               |S c c}
w c c}w # t.        t0        t2        f$ r d}Y mw xY w)a  Get split value histogram of a feature

        Parameters
        ----------
        feature :
            The name of the feature.
        fmap:
            The name of feature map file.
        bin :
            The maximum number of bins.
            Number of bins equals number of unique split values n_unique,
            if bins == None or bins > n_unique.
        as_pandas :
            Return pd.DataFrame when pandas is installed.
            If False or pandas is not installed, return numpy ndarray.

        Returns
        -------
        a histogram of used splitting values for the specified feature
        either as numpy array or pandas DataFrame.
        )r>  z\[{0}<([\d.Ee+-]+)\]Nr   )r  r   r   cz8Split value historgam doesn't support categorical split.
SplitValueCount)columnszPReturning histogram as ndarray (as_pandas == True, but pandas is not installed).)rC  rq  compiler  rr  extendrd   rJ   r   r   maxmin	histogramcolumn_stackr  rn  rm  rR   r  indexr   r   rE   r   r/  rK   r-   r.   ru   rv   rw   )r   r  r>  r  r  xgdumpr  regexpr  mr   n_uniquenphnph_stackedr  rY  rX   r  	feature_ts                      r:   get_split_value_histogramz!Booster.get_split_value_histogram	  s   8 D)3::7CDC

63'AMMQ/Q58Q/0  ryy()$*:3x&!Lll6-oos1vabz3q6&:;!+ad"3a"78q ##B##Bz',T->->-@'AB'A!!g'AB!)+/S	2+>u+E	 C N  )[<2IJJ-MME
 E 0 C 	: ! 	!s   #G
 G
+G G('G()NNNr  )r<   ri  r>   )r   NT)r  r   )	FFFFFTFr  F)ubj)r  Ftext)r  )r  r  )r  NT)Sr4   r5   r6   r7   r   r   r   r  r   r  r   r3  rE   rO  r   r   r   r  r   r  ru  rg  rp  r  r'   rc   r  r  r   r  r  r  r  r   r  r$  r  r  r  r$   r  r  r+  r&   rn  r,  r%   rm  r   rv  	Objectivers  r*   r  Metricr  r  r  r(   r   r  r  r  r#   rd   r"  r%  r)  r)   rt  r.  r5  r  r  rH  rC  rN  rM  r.   r  ro  r  r  r8   r9   r:   ri  ri    s    *.-1NR	;/&;/ )*;/ U9ic#IJK	;/
 
;/zC4S>3c3h?@C	uS#X#	$C"8HSM2C78	sDcO#	$*\ l "
d  $$ $4 $ /uWeU%:; /	 /b)$9: S $N# N$ N'(c (i (  45Dhsm!34 5$Q# Q4 Q6s 6x/D 6 (;*?  PT , 6x5 6 6 9h|&< 9 9 9 6x5 6 6 9h|&< 9 9 9  $dHU38_5s:; } 
	6 LPJJ*-J5=i5HJ	J>A
A
*-A
5@A
HSA
	A
L "&"<gsl+,< < 	<
 < 
<|8 8 8 8S 84 $# %"'"&*0"D=D= D= 	D=
 D= D=  D=  D= D= (D= D= 
D=T +1#"&"]
]
 (]
 	]

 ]
  ]
 ]
 ]
 
]
~Ec2;;&6 7 ED E413 19 16: :D :B 
 
 
 0 0 0 0 
E 
 
 ( ( ( (C c  )+ !+C$%+ C$%+ 	+
 + 
+^ )+ !	"C$%" " 	"
 
c"J /1>#r{{*+>	c5U+,,	->& JR?#r{{*+?CF?	c5U+,,	-?Dp@uS"++-='> p@	 p@d$W $ $!L0F !L4 !LL )+"DD BKK$%D sm	D
 D 
rzz9$	%Dr9   ri  ){r7   r$  rH   r\   r   rq  r]  ru   rr  abcr   r   collections.abcr   enumr   r   	functoolsr   inspectr	   r
   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   numpyr   scipy.sparser  _typingr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   compatr-   r.   r/   r0   libpathr1   r   r3   rE   rF   r@   r-  rY   r^   rd   rj   r   rk   rr   rz   r~   CDLLr   r   r   r   r   r   r   r  r   r)  r   numberr   r   r   r  r  r  r  rI   r  _Pointerr  r3  rc   r<  rB  rD  r{  r2  r  r  rH  rN  r\  r  r  rg  ri  r8   r9   r:   <module>r     s       	 	 
   # #    (   "       * E D "+: + 
 /S /U / 
 / 
 <T#Y <6<< < 
 <U3S	>2 uUFLL=P7Q (X { tCy &2# 2% 2
C DsEz):$;  K%S/!:E#s(OL	(4. t  .u  % %1fkk 1eCcM&: 1 S  2 2 2I6;; IZ {;S ;T ;
d38n 
 
*3--0CGOR	#Y"D "+d299o +$x. +$E8 E E U { C RYY BJJ    3# 3&// 3
*<*!**
6<<()*'D '[ 'T	"38_59"))_OS	#uS%%&
&'8)3<GKj$s j$l::xR !8CG#445:z 2%8  G  l

 l

^1
G 1
hXg Xv*O * bjj'*E"**bjj2H,IIJ		2::w'sEz)::	;|  F Fr9   