
    5[g-                        d Z ddgZddlZddlZddlmZ 	 ddlmZ 	 ddlm	Z	 dZ
dZdd
l [dD  ci c]  } | d c} Zej                  dD  ci c]  } | d c}        ej                  ddddd       d ej                  d      fd ej                  d      fd ej                  d      fd ej                  d      fdZdddddd d!d!d"d"d#
Zd(d$Z	 d)d%Zd& Zed*d'       Zy# e$ r dZY w xY w# e$ r d	Z
dZ	Y w xY wc c} w c c} w )+a  
Low-level BLAS functions (:mod:`scipy.linalg.blas`)
===================================================

This module contains low-level functions from the BLAS library.

.. versionadded:: 0.12.0

.. note::

   The common ``overwrite_<>`` option in many routines, allows the
   input arrays to be overwritten to avoid extra memory allocation.
   However this requires the array to satisfy two conditions
   which are memory order and the data type to match exactly the
   order and the type expected by the routine.

   As an example, if you pass a double precision float array to any
   ``S....`` routine which expects single precision arguments, f2py
   will create an intermediate array to match the argument types and
   overwriting will be performed on that intermediate array.

   Similarly, if a C-contiguous array is passed, f2py will pass a
   FORTRAN-contiguous array internally. Please make sure that these
   details are satisfied. More information can be found in the f2py
   documentation.

.. warning::

   These functions do little to no error checking.
   It is possible to cause crashes by mis-using them,
   so prefer using the higher-level routines in `scipy.linalg`.

Finding functions
-----------------

.. autosummary::
   :toctree: generated/

   get_blas_funcs
   find_best_blas_type

BLAS Level 1 functions
----------------------

.. autosummary::
   :toctree: generated/

   caxpy
   ccopy
   cdotc
   cdotu
   crotg
   cscal
   csrot
   csscal
   cswap
   dasum
   daxpy
   dcopy
   ddot
   dnrm2
   drot
   drotg
   drotm
   drotmg
   dscal
   dswap
   dzasum
   dznrm2
   icamax
   idamax
   isamax
   izamax
   sasum
   saxpy
   scasum
   scnrm2
   scopy
   sdot
   snrm2
   srot
   srotg
   srotm
   srotmg
   sscal
   sswap
   zaxpy
   zcopy
   zdotc
   zdotu
   zdrot
   zdscal
   zrotg
   zscal
   zswap

BLAS Level 2 functions
----------------------

.. autosummary::
   :toctree: generated/

   sgbmv
   sgemv
   sger
   ssbmv
   sspr
   sspr2
   ssymv
   ssyr
   ssyr2
   stbmv
   stpsv
   strmv
   strsv
   dgbmv
   dgemv
   dger
   dsbmv
   dspr
   dspr2
   dsymv
   dsyr
   dsyr2
   dtbmv
   dtpsv
   dtrmv
   dtrsv
   cgbmv
   cgemv
   cgerc
   cgeru
   chbmv
   chemv
   cher
   cher2
   chpmv
   chpr
   chpr2
   ctbmv
   ctbsv
   ctpmv
   ctpsv
   ctrmv
   ctrsv
   csyr
   zgbmv
   zgemv
   zgerc
   zgeru
   zhbmv
   zhemv
   zher
   zher2
   zhpmv
   zhpr
   zhpr2
   ztbmv
   ztbsv
   ztpmv
   ztrmv
   ztrsv
   zsyr

BLAS Level 3 functions
----------------------

.. autosummary::
   :toctree: generated/

   sgemm
   ssymm
   ssyr2k
   ssyrk
   strmm
   strsm
   dgemm
   dsymm
   dsyr2k
   dsyrk
   dtrmm
   dtrsm
   cgemm
   chemm
   cher2k
   cherk
   csymm
   csyr2k
   csyrk
   ctrmm
   ctrsm
   zgemm
   zhemm
   zher2k
   zherk
   zsymm
   zsyr2k
   zsyrk
   ztrmm
   ztrsm

get_blas_funcsfind_best_blas_type    N)_fblas)_cblas)	_fblas_64TF)*z?bBhHef   iIlLqQd         )FDgGsfloat32dfloat64c	complex64z
complex128)r	   r   r   r   scnrm2dznrm2cdotczdotccgerczgercsdotddot)
cnrm2znrm2cdotzdotcgerzgersdotcsdotuddotcddotuc                 d   t        j                  |      }t        j                  |j                  d      }d}| rt        |       dk(  r@t        j                  | d   j                  j                  d      }| d   j                  d   }nr| D cg c],  }t        j                  |j                  j                  d      . }}t        |      }|j                  |      }|dk(  rd|v rd}| |   j                  d   rd	}t        j                  |d
t        j                  d      f      \  }}|||fS c c}w )a  Find best-matching BLAS/LAPACK type.

    Arrays are used to determine the optimal prefix of BLAS routines.

    Parameters
    ----------
    arrays : sequence of ndarrays, optional
        Arrays can be given to determine optimal prefix of BLAS
        routines. If not given, double-precision routines will be
        used, otherwise the most generic type in arrays will be used.
    dtype : str or dtype, optional
        Data-type specifier. Not used if `arrays` is non-empty.

    Returns
    -------
    prefix : str
        BLAS/LAPACK prefix character.
    dtype : dtype
        Inferred Numpy data type.
    prefer_fortran : bool
        Whether to prefer Fortran order routines over C order.

    Examples
    --------
    >>> import numpy as np
    >>> import scipy.linalg.blas as bla
    >>> rng = np.random.default_rng()
    >>> a = rng.random((10,15))
    >>> b = np.asfortranarray(a)  # Change the memory layout order
    >>> bla.find_best_blas_type((a,))
    ('d', dtype('float64'), False)
    >>> bla.find_best_blas_type((a*1j,))
    ('z', dtype('complex128'), False)
    >>> bla.find_best_blas_type((b,))
    ('d', dtype('float64'), True)

       Fr	   r   FORTRANr   r   r   Tr   r   )
npdtype_type_scoregetcharlenflagsmaxindex
_type_conv)arraysr0   	max_scoreprefer_fortranxscoresind_max_scoreprefixs           L/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/linalg/blas.pyr   r     s   L HHUOE

A.INv;!#q	(<(<a@I#AY__Y7N AGG1kooaggllA6FGFI"LL3MA~1;	m$**95!% NN9sBHHY4G.HIMFE5.(( Hs   1D-c
                 h   g }
d}t        j                  |      }||f}||f}t        | t              r| f} d}t	        ||      \  }}}|r||}}| D ]  }||z   }|j                  ||      }t        |d   |d      }|d   }|t        |d   |d      }|d   }|t        | d| d      ||c|_        |_	        ||_        |	s)t        j                  t         j                        |_        n(t        j                  t         j                        |_        ||_        |
j                  |        |r|
d   S |
S )zp
    Return available BLAS/LAPACK functions.

    Used also in lapack.py. See get_blas_funcs for docstring.
    FTr   Nr	   z
 function z could not be found)r/   r0   
isinstancestrr   r2   getattr
ValueErrormodule_nametypecodeintc	int_dtypeint64r?   append)namesr9   r0   lib_namefmodulecmodulefmodule_namecmodule_namealiasilp64funcsunpackmodule1module2r?   r;   name	func_namefuncrF   s                       r@   
_get_funcsr[   F  sP    EFHHUOE%G%G%$7$F!FE>"GTM	IIi3	wqz9d3aj<71:y$7D!!*K<*Jyk1DEG G*5v'$-
XXbgg.DNXXbhh/DNT% ( Qx    c                 Z     i  _         t        j                         d fd	       }|S )z5
    Memoized fast path for _get_funcs instances
    c                     | ||f}|D ]1  }||j                   j                  |j                  j                  fz  }3 	 j	                  |      }||S  | |||      }|||<   |S # t
        $ r d }d }Y 'w xY w)N)r0   r3   r5   fortranr2   	TypeError)	rL   r9   r0   rS   keyarrayvaluerZ   memos	          r@   getterz"_memoize_get_funcs.<locals>.getter  s    eU#EEKK$$ekk&9&9::C 	HHSME LUFE51?DI  	CE	s   A' 'A76A7 NF)rd   	functoolswraps)rZ   re   rd   s   ` @r@   _memoize_get_funcsrj   y  s3     DDI__T . Mr\   c                     t        |t              r|dk(  rt        }nt        d      |s!t	        | ||dt
        t        ddt        d
      S t        st        d      t	        | ||dt        d	d
d	t        d
      S )a  Return available BLAS function objects from names.

    Arrays are used to determine the optimal prefix of BLAS routines.

    Parameters
    ----------
    names : str or sequence of str
        Name(s) of BLAS functions without type prefix.

    arrays : sequence of ndarrays, optional
        Arrays can be given to determine optimal prefix of BLAS
        routines. If not given, double-precision routines will be
        used, otherwise the most generic type in arrays will be used.

    dtype : str or dtype, optional
        Data-type specifier. Not used if `arrays` is non-empty.

    ilp64 : {True, False, 'preferred'}, optional
        Whether to return ILP64 routine variant.
        Choosing 'preferred' returns ILP64 routine if available,
        and otherwise the 32-bit routine. Default: False

    Returns
    -------
    funcs : list
        List containing the found function(s).


    Notes
    -----
    This routine automatically chooses between Fortran/C
    interfaces. Fortran code is used whenever possible for arrays with
    column major order. In all other cases, C code is preferred.

    In BLAS, the naming convention is that all functions start with a
    type prefix, which depends on the type of the principal
    matrix. These can be one of {'s', 'd', 'c', 'z'} for the NumPy
    types {float32, float64, complex64, complex128} respectively.
    The code and the dtype are stored in attributes `typecode` and `dtype`
    of the returned functions.

    Examples
    --------
    >>> import numpy as np
    >>> import scipy.linalg as LA
    >>> rng = np.random.default_rng()
    >>> a = rng.random((3,2))
    >>> x_gemv = LA.get_blas_funcs('gemv', (a,))
    >>> x_gemv.typecode
    'd'
    >>> x_gemv = LA.get_blas_funcs('gemv',(a*1j,))
    >>> x_gemv.typecode
    'z'

    	preferredzInvalid value for 'ilp64'BLASfblascblasF)rS   zFBLAS ILP64 routine requested, but Scipy compiled only with 32-bit BLASNfblas_64T)
rB   rC   	HAS_ILP64rE   r[   r   r   _blas_aliasRuntimeErrorr   )rL   r9   r0   rS   s       r@   r   r     s    r %KE899% &&'7%U4 	4   @ A A% )T:t%T3 	3r\   )rg   N)Frf   )__doc____all__numpyr/   rh   scipy.linalgr   r   ImportErrorr   rq   empty_modulescipy.linalg._fblasr1   updater0   r8   rr   r   r[   rj   r   )r<   s   0r@   <module>r|      su  I^ 2
3   #&I  ! ''Yq!tY'   ),)QAqD), -   3 4 xrxx	*+xrxx	*+xrxx,-xrxx-.0
 !8	1@)L 0fD H3 H3I  F  II  (,s-   C& C3 
D
D&C0/C03	C?>C?