a
    )$a{                     @   s  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mZ ddl	m
Z
mZ dZddgZejdd	 ejd
krzejnejZejd
krejnejZG dd dejZz
ejZW n ey   ejZY n0 dddddddddddddddddZeedd e D Z dd e D Z!dd e D Z"dd e D Z#eed d Z$d d! Z%e%ee e!d"d#d Z&e%d$'d%d e D d$'e#d$'e$d&G d'd dZ(e%d$'d(d e"D d$'d)d e D d$'e#d$'e$d*G d+d, d,Z)e%d$'d-d e D d$'d.d e!D d"G d/d0 d0e
Z*G d1d2 d2e*Z+G d3d4 d4e*Z,G d5d6 d6e*Z-G d7d de*Z.d8d9 Z/e0d:kre/  dS );zthreadpoolctl

This module provides utilities to introspect native libraries that relies on
thread pools (notably BLAS and OpenMP implementations) and dynamically set the
maximal number of threads they can use.
    N)find_library)ABCabstractmethodz2.2.0threadpool_limitsthreadpool_infoZKMP_DUPLICATE_LIB_OKTruel        c                   @   s,   e Zd ZdefdejfdejfdefgZdS )_dl_phdr_infoZ	dlpi_addr	dlpi_nameZ	dlpi_phdrZ
dlpi_phnumN)	__name__
__module____qualname___SYSTEM_UINTctypesc_char_pZc_void_p_SYSTEM_UINT_HALFZ_fields_ r   r   ,lib/python3.9/site-packages/threadpoolctl.pyr   -   s
   r   openmp)libiompZlibgomplibompZvcomp)user_apiinternal_apifilename_prefixesblasZopenblas)ZlibopenblasZmkl)Z	libmkl_rtZmkl_rtZblis)Zlibblis)_OpenMPModule_OpenBLASModule
_MKLModule_BLISModulec                 c   s   | ]}|d  V  qdS )r   Nr   .0mr   r   r   	<genexpr>Y       r!   c                 C   s   g | ]}|d  qS )r   r   r   r   r   r   
<listcomp>Z   r"   r#   c                 C   s   g | ]}|d  D ]}|qqS )r   r   )r   r    prefixr   r   r   r#   [   s   c                 C   s    g | ]}|d  dkr|d qS )r   r   r   r   r   r   r   r   r#   ]   s   r   r   c                     s    fdd}|S )Nc                    s   | j j i | _ | S N)__doc__format)oargskwargsr   r   	decoratord   s    z$_format_docstring.<locals>.decoratorr   )r*   r+   r,   r   r)   r   _format_docstringc   s    r-   )	USER_APISZINTERNAL_APISc                   C   s   t td S )a  Return the maximal number of threads for each detected library.

    Return a list with all the supported modules that have been found. Each
    module is represented by a dict with the following information:

      - "user_api" : user API. Possible values are {USER_APIS}.
      - "internal_api": internal API. Possible values are {INTERNAL_APIS}.
      - "prefix" : filename prefix of the specific implementation.
      - "filepath": path to the loaded module.
      - "version": version of the library (if available).
      - "num_threads": the current thread limit.

    In addition, each module may contain internal_api specific entries.
    r   )_ThreadpoolInfo_ALL_USER_APIStodictsr   r   r   r   r   k   s    , c                 c   s   | ]}d  |V  qdS z"{}"Nr'   r   Zapir   r   r   r!      r"   )r.   	BLAS_LIBSOPENMP_LIBSc                   @   sJ   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )r   a  Change the maximal number of threads that can be used in thread pools.

    This class can be used either as a function (the construction of this
    object limits the number of threads) or as a context manager, in a `with`
    block.

    Set the maximal number of threads that can be used in thread pools used in
    the supported libraries to `limit`. This function works for libraries that
    are already loaded in the interpreter and can be changed dynamically.

    Parameters
    ----------
    limits : int, dict or None (default=None)
        The maximal number of threads that can be used in thread pools

        - If int, sets the maximum number of threads to `limits` for each
          library selected by `user_api`.

        - If it is a dictionary `{{key: max_threads}}`, this function sets a
          custom maximum number of threads for each `key` which can be either a
          `user_api` or a `prefix` for a specific library.

        - If None, this function does not do anything.

    user_api : {USER_APIS} or None (default=None)
        APIs of libraries to limit. Used only if `limits` is an int.

        - If "blas", it will only limit BLAS supported libraries ({BLAS_LIBS}).

        - If "openmp", it will only limit OpenMP supported libraries
          ({OPENMP_LIBS}). Note that it can affect the number of threads used
          by the BLAS libraries if they rely on OpenMP.

        - If None, this function will apply to all supported libraries.
    Nc                 C   s&   |  ||\| _| _| _|  | _d S r%   )_check_params_limits	_user_api	_prefixes_set_threadpool_limits_original_info)selflimitsr   r   r   r   __init__   s    
zthreadpool_limits.__init__c                 C   s   | S r%   r   r?   r   r   r   	__enter__   s    zthreadpool_limits.__enter__c                 C   s   |    d S r%   )
unregister)r?   typevalue	tracebackr   r   r   __exit__   s    zthreadpool_limits.__exit__c                 C   s&   | j d ur"| j D ]}||j qd S r%   )r>   set_num_threadsnum_threads)r?   moduler   r   r   rD      s    

zthreadpool_limits.unregisterc                 C   s   | j dur| j }nt| jd}i }g }| jD ]d}dd |d|D }t|}t|}|dkrh| }n |dkrvd}nt|}|| |||< q,|rt	
dd	| d
  |S )zuOriginal num_threads from before calling threadpool_limits

        Return a dict `{user_api: num_threads}`.
        Nr/   c                 S   s   g | ]
}|j qS r   rJ   r   rK   r   r   r   r#      r"   z>threadpool_limits.get_original_num_threads.<locals>.<listcomp>r      r   z1Multiple value possible for following user apis: r3   z. Returning the minimum.)r>   r0   r;   get_modulessetlenpopminappendwarningswarnjoin)r?   Zoriginal_limitsrJ   Zwarning_apisr   r@   Zn_limitslimitr   r   r   get_original_num_threads   s6    





z*threadpool_limits.get_original_num_threadsc                    s    du st  tr`|du r t}n |tv r0|g}ntdt| durZ fdd|D  g }njt  trzdd  D  nt  trdd  D  t  tstdt	 dd	  D }d
d	  D } ||fS )zLSuitable values for the _limits, _user_api and _prefixes attributes
        Nz6user_api must be either in {} or None. Got {} instead.c                    s   i | ]
}| qS r   r   r6   r@   r   r   
<dictcomp>   r"   z3threadpool_limits._check_params.<locals>.<dictcomp>c                 S   s   i | ]}|d  |d qS r$   rJ   r   rM   r   r   r   r[      s   c                 S   s   i | ]}|j |jqS r   r\   rM   r   r   r   r[      s   z>limits must either be an int, a list or a dict. Got {} insteadc                 S   s   g | ]}|t v r|qS r   )_ALL_PREFIXESr   r$   r   r   r   r#      r"   z3threadpool_limits._check_params.<locals>.<listcomp>c                 S   s   g | ]}|t v r|qS r   )r1   r6   r   r   r   r#      r"   )

isinstanceintr1   
ValueErrorr'   listr0   dict	TypeErrorrE   )r?   r@   r   prefixesr   rZ   r   r9      s8    


zthreadpool_limits._check_paramsc                 C   sd   | j du rdS t| j| jd}|D ]<}|j| j v r@| j |j }n| j |j }|dur"|| q"|S )zChange the maximal number of threads in selected thread pools.

        Return a list with all the supported modules that have been found
        matching `self._prefixes` and `self._user_api`.
        N)re   r   )r:   r0   r<   r;   r$   r   rI   )r?   modulesrK   rJ   r   r   r   r=     s    
z(threadpool_limits._set_threadpool_limits)NN)r
   r   r   r&   rA   rC   rH   rD   rY   r9   r=   r   r   r   r   r      s   #
$'c                 c   s   | ]}d  |V  qdS r4   r5   r^   r   r   r   r!      r"   c                 c   s   | ]}d  |V  qdS r4   r5   r6   r   r   r   r!   !  r"   )PREFIXESr.   r7   r8   c                   @   s   e Zd ZdZe Ze Zd$ddZdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zedd  Zed%d"d#ZdS )&r0   a  Collection of all supported modules that have been found

    Parameters
    ----------
    user_api : list of user APIs or None (default=None)
        Select libraries matching the requested API. Ignored if `modules` is
        not None. Supported user APIs are {USER_APIS}.

        - "blas" selects all BLAS supported libraries ({BLAS_LIBS})
        - "openmp" selects all OpenMP supported libraries ({OPENMP_LIBS})

        If None, libraries are not selected by their `user_api`.

    prefixes : list of prefixes or None (default=None)
        Select libraries matching the requested prefixes. Supported prefixes
        are {PREFIXES}.
        If None, libraries are not selected by their prefix. Ignored if
        `modules` is not None.

    modules : list of _Module objects or None (default=None)
        Wraps a list of _Module objects into a _ThreapoolInfo object. Does not
        load or reload any shared library. If it is not None, `prefixes` and
        `user_api` are ignored.

    Note
    ----
    Is is possible to select libraries both by prefixes and by user_api. All
    libraries matching one or the other will be selected.
    Nc                 C   sN   |d u rD|d u rg n|| _ |d u r&g n|| _g | _|   |   n|| _d S r%   )re   r   rf   _load_modules_warn_if_incompatible_openmp)r?   r   re   rf   r   r   r   rA   N  s    
z_ThreadpoolInfo.__init__c                    sH    dkrdu rt ttt s(g fdd| jD }t|dS )z8Return all modules such that values contains module[key]r   Nc                    s   g | ]}t | v r|qS r   )getattrrM   keyvaluesr   r   r#   _  s   z/_ThreadpoolInfo.get_modules.<locals>.<listcomp>rf   )rb   r1   r_   rf   r0   )r?   rl   rm   rf   r   rk   r   rO   Y  s    
z_ThreadpoolInfo.get_modulesc                 C   s   dd | j D S )zReturn info as a list of dictsc                 S   s   g | ]}|  qS r   todictrM   r   r   r   r#   e  r"   z+_ThreadpoolInfo.todicts.<locals>.<listcomp>rn   rB   r   r   r   r2   c  s    z_ThreadpoolInfo.todictsc                 C   s
   t | jS r%   )rQ   rf   rB   r   r   r   __len__g  s    z_ThreadpoolInfo.__len__c                 c   s   | j E d H  d S r%   rn   rB   r   r   r   __iter__j  s    z_ThreadpoolInfo.__iter__c                 C   s   | j |j kS r%   rn   r?   otherr   r   r   __eq__m  s    z_ThreadpoolInfo.__eq__c                 C   s4   t jdkr|   nt jdkr(|   n|   dS )z6Loop through loaded libraries and store supported onesdarwinwin32N)sysplatform_find_modules_with_dyld)_find_modules_with_enum_process_module_ex"_find_modules_with_dl_iterate_phdrrB   r   r   r   rh   p  s
    



z_ThreadpoolInfo._load_modulesc                    s`      }t|dsg S  fdd}ttjtttjtj}||}td}|	|| dS )ao  Loop through loaded libraries and return binders on supported ones

        This function is expected to work on POSIX system only.
        This code is adapted from code by Intel developper @anton-malakhov
        available at https://github.com/IntelPython/smp

        Copyright (c) 2017, Intel Corporation published under the BSD 3-Clause
        license
        dl_iterate_phdrc                    s$   | j j}|r |d} | dS )Nutf-8r   )contentsr	   decode_make_module_from_path)infosizedatafilepathrB   r   r   match_module_callback  s
    

zQ_ThreadpoolInfo._find_modules_with_dl_iterate_phdr.<locals>.match_module_callbackr"   N)
	_get_libchasattrr   Z	CFUNCTYPEc_intZPOINTERr   Zc_size_tr   r}   )r?   libcr   Zc_func_signatureZc_match_module_callbackr   r   rB   r   r|   y  s    



z2_ThreadpoolInfo._find_modules_with_dl_iterate_phdrc                 C   s^   |   }t|dsg S | }tj|j_t|D ](}t||}|	d}| 
| q0dS )zLoop through loaded libraries and return binders on supported ones

        This function is expected to work on OSX system only
        _dyld_image_countr~   N)r   r   r   r   r   Z_dyld_get_image_namerestyperangeZ	string_atr   r   )r?   r   Zn_dyldir   r   r   r   rz     s    


z'_ThreadpoolInfo._find_modules_with_dyldc              	   C   sN  ddl m}m}m} d}d}d}| d}| d}|||B dt }	|	s^td	t  zd
}
| }||
  }t	
|}||	t	||t	||std||jkrq|j||
  }
qj|j||
  }t||d| }t	|}| }|D ]:}||	|t	|t	|std|j}| | qW ||	 n||	 0 dS )a  Loop through loaded libraries and return binders on supported ones

        This function is expected to work on windows system only.
        This code is adapted from code by Philipp Hagemeister @phihag available
        at https://stackoverflow.com/questions/17474574
        r   )DWORDHMODULEMAX_PATHi         ZPsapiZkernel32FzCould not open PID %s   zEnumProcessModulesEx failedNzGetModuleFileNameEx failed)Zctypes.wintypesr   r   r   _get_windllZOpenProcessosgetpidOSErrorr   ZsizeofZEnumProcessModulesExZbyrefrF   mapZcreate_unicode_bufferZGetModuleFileNameExWr   ZCloseHandle)r?   r   r   r   ZPROCESS_QUERY_INFORMATIONZPROCESS_VM_READZLIST_MODULES_ALLZps_apiZ	kernel_32Z	h_processZ	buf_countZneededbufZbuf_sizecountZ	h_modulesZn_sizeZh_moduler   r   r   r   r{     sL    






z9_ThreadpoolInfo._find_modules_with_enum_process_module_exc           	      C   s   |  |}tj| }t D ]j\}}| ||d }|du rDq"|d }|d }|| jv sh|| j	v r"t
 | }|||||}| j| q"dS )z.Store a module if it is supported and selectedr   Nr   r   )	_realpathr   pathbasenamelower_SUPPORTED_MODULESitems_check_prefixre   r   globalsrf   rT   )	r?   r   filenameZmodule_classZcandidate_moduler$   r   r   rK   r   r   r   r     s    

z&_ThreadpoolInfo._make_module_from_pathc                 C   s    |D ]}| |r|  S qdS )z]Return the prefix library_basename starts with

        Return None if none matches.
        N
startswith)r?   Zlibrary_basenamer   r$   r   r   r   r     s    

z_ThreadpoolInfo._check_prefixc                 C   sH   t jdkrdS dd | jD }td}d|v rDd|v rDt|t dS )z?Raise a warning if llvm-OpenMP and intel-OpenMP are both loadedZlinuxNc                 S   s   g | ]
}|j qS r   )r$   rM   r   r   r   r#     r"   z@_ThreadpoolInfo._warn_if_incompatible_openmp.<locals>.<listcomp>a  
            Found Intel OpenMP ('libiomp') and LLVM OpenMP ('libomp') loaded at
            the same time. Both libraries are known to be incompatible and this
            can cause random crashes or deadlocks on Linux when loaded in the
            same Python program.
            Using threadpoolctl may cause crashes or deadlocks. For more
            information and possible workarounds, please see
                https://github.com/joblib/threadpoolctl/blob/master/multiple_openmp.md
            r   r   )rx   ry   rf   textwrapdedentrU   rV   RuntimeWarning)r?   re   msgr   r   r   ri     s    

z,_ThreadpoolInfo._warn_if_incompatible_openmpc                 C   sD   | j d}|du r@td}|du r(dS tj|td}|| j d< |S )z Load the lib-C for unix systems.r   Ncmode)_system_librariesgetr   r   CDLL_RTLD_NOLOAD)clsr   Z	libc_namer   r   r   r   $  s    
z_ThreadpoolInfo._get_libcc                 C   s2   | j |}|du r.td|}|| j |< |S )zLoad a windows DLLNz{}.dll)r   r   r   ZWinDLLr'   )r   Zdll_nameZdllr   r   r   r   0  s
    
z_ThreadpoolInfo._get_windll'  c                 C   s<   | j |}|du r8tj|}t| j |k r8|| j |< |S )zLSmall caching wrapper around os.path.realpath to limit system calls
        N)
_realpathsr   r   r   realpathrQ   )r   r   Zcache_limitZrpathr   r   r   r   9  s    
z_ThreadpoolInfo._realpath)NNN)r   )r
   r   r   r&   rc   r   r   rA   rO   r2   rq   rr   ru   rh   r|   rz   r{   r   r   ri   classmethodr   r   r   r   r   r   r   r0     s,   !

	";


r0   c                 c   s   | ]}d  |V  qdS r4   r5   r6   r   r   r   r!   H  r"   c                 c   s   | ]}d  |V  qdS r4   r5   r6   r   r   r   r!   I  r"   c                   @   sZ   e Zd ZdZdddZdd Zdd Zed	d
 Zedd Z	edd Z
edd ZdS )_Modulea  Abstract base class for the modules

    A module is represented by the following information:
      - "user_api" : user API. Possible values are {USER_APIS}.
      - "internal_api" : internal API. Possible values are {INTERNAL_APIS}.
      - "prefix" : prefix of the shared library's name.
      - "filepath" : path to the loaded module.
      - "version" : version of the library (if available).
      - "num_threads" : the current thread limit.

    In addition, each module may contain internal_api specific entries.
    Nc                 C   sH   || _ || _|| _|| _tj|td| _|  | _	| 
 | _|   d S )Nr   )r   r$   r   r   r   r   r   _dynlibget_versionversionget_num_threadsrJ   _get_extra_info)r?   r   r$   r   r   r   r   r   rA   W  s    

z_Module.__init__c                 C   s   |   |  kS r%   ro   rs   r   r   r   ru   b  s    z_Module.__eq__c                 C   s   dd t |  D S )z&Return relevant info wrapped in a dictc                 S   s    i | ]\}}| d s||qS )_r   )r   kvr   r   r   r[   g  r"   z"_Module.todict.<locals>.<dictcomp>)varsr   rB   r   r   r   rp   e  s    z_Module.todictc                 C   s   dS )z(Return the version of the shared libraryNr   rB   r   r   r   r   i  s    z_Module.get_versionc                 C   s   dS )z5Return the maximum number of threads available to useNr   rB   r   r   r   r   n  s    z_Module.get_num_threadsc                 C   s   dS )z(Set the maximum number of threads to useNr   )r?   rJ   r   r   r   rI   s  s    z_Module.set_num_threadsc                 C   s   dS )z*Add additional module specific informationNr   rB   r   r   r   r   x  s    z_Module._get_extra_info)NNNN)r
   r   r   r&   rA   ru   rp   r   r   r   rI   r   r   r   r   r   r   G  s     



r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )r   zModule class for OpenBLASc                 C   sB   t | jddd }tj|_|  }|d dkr>|d dS d S )NZopenblas_get_configc                   S   s   d S r%   r   r   r   r   r   <lambda>  r"   z-_OpenBLASModule.get_version.<locals>.<lambda>r   s   OpenBLASrN   r~   )rj   r   r   r   r   splitr   )r?   Z
get_configZconfigr   r   r   r     s    
z_OpenBLASModule.get_versionc                 C   s   t | jddd }| S )NZopenblas_get_num_threadsc                   S   s   d S r%   r   r   r   r   r   r     r"   z1_OpenBLASModule.get_num_threads.<locals>.<lambda>rj   r   r?   get_funcr   r   r   r     s    z_OpenBLASModule.get_num_threadsc                 C   s   t | jddd }||S )NZopenblas_set_num_threadsc                 S   s   d S r%   r   rL   r   r   r   r     r"   z1_OpenBLASModule.set_num_threads.<locals>.<lambda>r   r?   rJ   Zset_funcr   r   r   rI     s    z_OpenBLASModule.set_num_threadsc                 C   s   |   | _|  | _d S r%   get_threading_layerthreading_layerget_architectureZarchitecturerB   r   r   r   r     s    
z_OpenBLASModule._get_extra_infoc                 C   s&   | j  }|dkrdS |dkr"dS dS )z&Return the threading layer of OpenBLAS   r   rN   pthreadsdisabled)r   Zopenblas_get_parallel)r?   r   r   r   r   r     s    
z#_OpenBLASModule.get_threading_layerc                 C   s.   t | jdd }|d u rd S tj|_| dS )NZopenblas_get_corenamer~   rj   r   r   r   r   r   )r?   Zget_corenamer   r   r   r     s
    z _OpenBLASModule.get_architectureN
r
   r   r   r&   r   r   rI   r   r   r   r   r   r   r   r   ~  s   	r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )r   zModule class for BLISc                 C   s&   t | jddd }tj|_| dS )NZbli_info_get_version_strc                   S   s   d S r%   r   r   r   r   r   r     r"   z)_BLISModule.get_version.<locals>.<lambda>r~   r   )r?   Zget_version_r   r   r   r     s
    z_BLISModule.get_versionc                 C   s(   t | jddd }| }|dkr$dS |S )NZbli_thread_get_num_threadsc                   S   s   d S r%   r   r   r   r   r   r     r"   z-_BLISModule.get_num_threads.<locals>.<lambda>rN   r   )r?   r   rJ   r   r   r   r     s
    z_BLISModule.get_num_threadsc                 C   s   t | jddd }||S )NZbli_thread_set_num_threadsc                 S   s   d S r%   r   rL   r   r   r   r     r"   z-_BLISModule.set_num_threads.<locals>.<lambda>r   r   r   r   r   rI     s    z_BLISModule.set_num_threadsc                 C   s   |   | _|  | _d S r%   r   rB   r   r   r   r     s    
z_BLISModule._get_extra_infoc                 C   s    | j  rdS | j  rdS dS )z"Return the threading layer of BLISr   r   r   )r   Zbli_info_get_enable_openmpZbli_info_get_enable_pthreadsrB   r   r   r   r     s
    

z_BLISModule.get_threading_layerc                 C   sP   t | jdd }t | jdd }|d u s,|d u r0d S tj|_tj|_|| dS )Nbli_arch_query_idbli_arch_stringr~   )rj   r   r   r   r   r   r   )r?   r   r   r   r   r   r     s    z_BLISModule.get_architectureNr   r   r   r   r   r     s   r   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )r   zModule class for MKLc                 C   s\   t | jdsd S td}| j|d |jd}td|}|d urT|	 d }|
 S )NMKL_Get_Version_String   r~   zVersion ([^ ]+) r   )r   r   r   Zcreate_string_bufferr   rF   r   researchgroupsstrip)r?   resr   groupr   r   r   r     s    
z_MKLModule.get_versionc                 C   s   t | jddd }| S )NZMKL_Get_Max_Threadsc                   S   s   d S r%   r   r   r   r   r   r     r"   z,_MKLModule.get_num_threads.<locals>.<lambda>r   r   r   r   r   r     s    z_MKLModule.get_num_threadsc                 C   s   t | jddd }||S )NZMKL_Set_Num_Threadsc                 S   s   d S r%   r   rL   r   r   r   r     r"   z,_MKLModule.set_num_threads.<locals>.<lambda>r   r   r   r   r   rI     s    z_MKLModule.set_num_threadsc                 C   s   |   | _d S r%   )r   r   rB   r   r   r   r     s    z_MKLModule._get_extra_infoc                 C   s0   t | jddd }dddddd	d
}||d S )z!Return the threading layer of MKLZMKL_Set_Threading_Layerc                 S   s   dS )Nr   r   )Zlayerr   r   r   r     r"   z0_MKLModule.get_threading_layer.<locals>.<lambda>ZintelZ
sequentialZpgiZgnuZtbbznot specified)r   rN   r   r      r   r   r   )r?   Zset_threading_layerZ	layer_mapr   r   r   r     s    z_MKLModule.get_threading_layerN)	r
   r   r   r&   r   r   rI   r   r   r   r   r   r   r     s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )r   zModule class for OpenMPc                 C   s   d S r%   r   rB   r   r   r   r     s    z_OpenMPModule.get_versionc                 C   s   t | jddd }| S )NZomp_get_max_threadsc                   S   s   d S r%   r   r   r   r   r   r     r"   z/_OpenMPModule.get_num_threads.<locals>.<lambda>r   r   r   r   r   r     s    z_OpenMPModule.get_num_threadsc                 C   s   t | jddd }||S )NZomp_set_num_threadsc                 S   s   d S r%   r   rL   r   r   r   r     r"   z/_OpenMPModule.set_num_threads.<locals>.<lambda>r   r   r   r   r   rI   
  s    z_OpenMPModule.set_num_threadsc                 C   s   d S r%   r   rB   r   r   r   r     s    z_OpenMPModule._get_extra_infoN)r
   r   r   r&   r   r   rI   r   r   r   r   r   r      s
   c               	   C   s   ddl } ddl}ddl}ddl}| jddd}|jdddd	d
dd |jdddd ||jdd }|jD ]:}z|j	|dd W qn t
y   td||jd Y qn0 qn|jrt|j t|jt dd dS )zBCommandline interface to display thread-pool information and exit.r   Nz5python -m threadpoolctl -i numpy scipy.linalg xgboostz)Display thread-pool information and exit.)usagedescriptionz-iz--importrf   *r   z;Python modules to import before introspecting thread-pools.)destnargsdefaulthelpz-cz	--commandz@a Python statement to execute before introspecting thread-pools.)r   rN   )packagezWARNING: could not import)filer   )indent)argparse	importlibjsonrx   ArgumentParseradd_argument
parse_argsargvrf   import_moduleImportErrorprintstderrZcommandexecdumpsr   )r   r   r   rx   parseroptionsrK   r   r   r   _main  s2    


r   __main__)1r&   r   r   rx   r   r   rU   Zctypes.utilr   abcr   r   __version____all__environ
setdefaultmaxsizeZc_uint64Zc_uint32r   Zc_uint16r   Z	Structurer   RTLD_NOLOADr   AttributeErrorZDEFAULT_MODEr   rb   rP   rm   r1   Z_ALL_INTERNAL_APISr]   Z_ALL_BLAS_LIBRARIESZ_ALL_OPENMP_LIBRARIESr-   r   rW   r   r0   r   r   r   r   r   r   r
   r   r   r   r   <module>   s   

	

   %4-.'!
