a
    ˜¥»aÜa  ã                   @   sÚ  d Z ddlmZ ddlmZ ddlZej ej e	¡¡Z
ddddd	d
ddœZddddddddddddddddœZdd„ ZdZdddddddddddœ
Zd d!„ Zd"d#„ Zd$Zd%d&„ Zd'Zd(d)„ Zd*Zd+d,„ Zd-Zd.d/„ Zd0Zd1d2„ Zd3Zd4Zd5d6„ Zd7Zd8d9„ Zd:Z d;d<„ Z!d=Z"d>d?d@d>d>d>d>d>d>dAœ	Z#dBdBdCœZ$dDd>iZ%ee&e$e%e%e$e$dE�Z'dFdG„ Z(dHdI„ Z)dJdK„ Z*dLdM„ Z+dNdO„ Z,dPZ-dQdR„ Z.dSZ/dTdU„ Z0dVZ1dWZ2dXZ3dYZ4dZd[„ Z5d\d]„ Z6d^d_„ Z7d`da„ Z8dmdjdk„Z9e:dlk�rÖe9ƒ  dS )nzù
Code generator script to make the Cython BLAS and LAPACK wrappers
from the files "cython_blas_signatures.txt" and
"cython_lapack_signatures.txt" which contain the signatures for
all the BLAS/LAPACK routines that should be included in the wrappers.
é    )Údefaultdict)Ú
itemgetterNÚintegerÚcomplexzdouble precisionÚrealz
complex*16Ú	characterÚlogical)ÚintÚcÚdÚsÚzÚcharÚbintr	   Únpy_complex64ÚdoubleÚfloatÚnpy_complex128r   Ú	_cselect1Ú	_cselect2Ú	_dselect2Ú	_dselect3Ú	_sselect2Ú	_sselect3Ú	_zselect1Ú	_zselect2)r	   r
   r   r   r   r   r   Úcselect1Úcselect2Údselect2Údselect3Ússelect2Ússelect3Úzselect1Úzselect2c                 C   s   t dd„ |  d¡D ƒŽ S )Nc                 S   s   g | ]}|  d ¡‘qS ©z *©Úsplit©Ú.0Úarg© r*   úT/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/scipy/linalg/_generate_pyx.pyÚ
<listcomp>(   ó    z'arg_names_and_types.<locals>.<listcomp>ú, )Úzipr&   )Úargsr*   r*   r+   Úarg_names_and_types'   s    r1   zô
cdef extern from "{header_name}":
    void _fortran_{name} "F_FUNC({name}wrp, {upname}WRP)"({ret_type} *out, {fort_args}) nogil
cdef {ret_type} {name}({args}) nogil:
    cdef {ret_type} out
    _fortran_{name}(&out, {argnames})
    return out
)
r
   r   r   r   r   r   r    r!   r"   r#   c                 C   s   | dv rd  | ¡S dS )N)
r   r   r   r   r   r   r   r   r   r   z<{0}*>Ú ©Úformat)r)   r*   r*   r+   Ú	arg_casts;   s    
r5   c              
      sÆ   t |ƒ\}}ˆ |v rN‡ fdd„|D ƒ}dd„ |D ƒ}d dd„ t||ƒD ƒ¡}dd„ |D ƒ}d dd„ t||ƒD ƒ¡}dd„ t||ƒD ƒ}d |¡}tˆ  }| d	d
¡}tj| |  ¡ ||ˆ |||d�S )Nc                    s    g | ]}|ˆ kr|nˆ d  ‘qS )Ú_r*   ©r(   Ún©Úret_typer*   r+   r,   J   r-   z!pyx_decl_func.<locals>.<listcomp>c                 S   s    g | ]}|d vr|n|d ‘qS ©)ÚlambdaÚinr6   r*   r7   r*   r*   r+   r,   K   s   ÿr.   c                 S   s   g | ]\}}d   ||g¡‘qS r$   ©Újoin©r(   r8   Útr*   r*   r+   r,   M   s   ÿc                 S   s   g | ]}t  ||¡‘qS r*   ©Ú	npy_typesÚget©r(   rA   r*   r*   r+   r,   O   r-   c                 S   s   g | ]\}}d   ||g¡‘qS r$   r>   r@   r*   r*   r+   r,   P   s   ÿc                 S   s   g | ]\}}t |ƒ| ‘qS r*   ©r5   r@   r*   r*   r+   r,   R   r-   r<   Úlambda_)ÚnameÚupnamer0   Ú	fort_argsr:   Ú
c_ret_typeÚargnamesÚheader_name)r1   r?   r/   Úc_typesÚreplaceÚpyx_func_templater4   Úupper)rH   r:   r0   rM   ÚargtypesrL   rJ   rK   r*   r9   r+   Úpyx_decl_funcC   s,    ÿ
ÿ
ÿ
ýrS   z¨cdef extern from "{header_name}":
    void _fortran_{name} "F_FUNC({name},{upname})"({fort_args}) nogil
cdef void {name}({args}) nogil:
    _fortran_{name}({argnames})
c                 C   sŽ   t |ƒ\}}dd„ |D ƒ}dd„ |D ƒ}d dd„ t||ƒD ƒ¡}dd„ t||ƒD ƒ}d |¡}| dd¡ d	d
¡}tj| |  ¡ ||||d�S )Nc                 S   s   g | ]}t  ||¡‘qS r*   rB   rE   r*   r*   r+   r,   e   r-   z pyx_decl_sub.<locals>.<listcomp>c                 S   s    g | ]}|d vr|n|d ‘qS r;   r*   r7   r*   r*   r+   r,   f   r-   r.   c                 S   s   g | ]\}}d   ||g¡‘qS r$   r>   r@   r*   r*   r+   r,   g   s   ÿc                 S   s   g | ]\}}t |ƒ| ‘qS r*   rF   r@   r*   r*   r+   r,   i   r-   z*lambda,z	*lambda_,ú*in,ú*in_,)rH   rI   r0   rJ   rL   rM   )r1   r?   r/   rO   Úpyx_sub_templater4   rQ   )rH   r0   rM   rR   rL   rJ   r*   r*   r+   Úpyx_decl_subc   s    
ÿ
þrW   a†  # cython: boundscheck = False
# cython: wraparound = False
# cython: cdivision = True

"""
BLAS Functions for Cython
=========================

Usable from Cython via::

    cimport scipy.linalg.cython_blas

These wrappers do not check for alignment of arrays.
Alignment should be checked before these wrappers are used.

Raw function pointers (Fortran-style pointer arguments):

- {}


"""

# Within SciPy, these wrappers can be used via relative or absolute cimport.
# Examples:
# from ..linalg cimport cython_blas
# from scipy.linalg cimport cython_blas
# cimport scipy.linalg.cython_blas as cython_blas
# cimport ..linalg.cython_blas as cython_blas

# Within SciPy, if BLAS functions are needed in C/C++/Fortran,
# these wrappers should not be used.
# The original libraries should be linked directly.

cdef extern from "fortran_defs.h":
    pass

from numpy cimport npy_complex64, npy_complex128

c                 C   s   dd„ | D ƒ}t  d |¡¡S )Nc                 S   s   g | ]}|d  ‘qS ©r   r*   ©r(   Úsigr*   r*   r+   r,   ›   r-   z*make_blas_pyx_preamble.<locals>.<listcomp>ú
- )Úblas_pyx_preambler4   r?   ©Úall_sigsÚnamesr*   r*   r+   Úmake_blas_pyx_preambleš   s    r`   a"  """
LAPACK functions for Cython
===========================

Usable from Cython via::

    cimport scipy.linalg.cython_lapack

This module provides Cython-level wrappers for all primary routines included
in LAPACK 3.4.0 except for ``zcgesv`` since its interface is not consistent
from LAPACK 3.4.0 to 3.6.0. It also provides some of the
fixed-api auxiliary routines.

These wrappers do not check for alignment of arrays.
Alignment should be checked before these wrappers are used.

Raw function pointers (Fortran-style pointer arguments):

- {}


"""

# Within SciPy, these wrappers can be used via relative or absolute cimport.
# Examples:
# from ..linalg cimport cython_lapack
# from scipy.linalg cimport cython_lapack
# cimport scipy.linalg.cython_lapack as cython_lapack
# cimport ..linalg.cython_lapack as cython_lapack

# Within SciPy, if LAPACK functions are needed in C/C++/Fortran,
# these wrappers should not be used.
# The original libraries should be linked directly.

cdef extern from "fortran_defs.h":
    pass

from numpy cimport npy_complex64, npy_complex128

cdef extern from "_lapack_subroutines.h":
    # Function pointer type declarations for
    # gees and gges families of functions.
    ctypedef bint _cselect1(npy_complex64*)
    ctypedef bint _cselect2(npy_complex64*, npy_complex64*)
    ctypedef bint _dselect2(d*, d*)
    ctypedef bint _dselect3(d*, d*, d*)
    ctypedef bint _sselect2(s*, s*)
    ctypedef bint _sselect3(s*, s*, s*)
    ctypedef bint _zselect1(npy_complex128*)
    ctypedef bint _zselect2(npy_complex128*, npy_complex128*)

c                 C   s   dd„ | D ƒ}t  d |¡¡S )Nc                 S   s   g | ]}|d  ‘qS rX   r*   rY   r*   r*   r+   r,   Ö   r-   z,make_lapack_pyx_preamble.<locals>.<listcomp>r[   )Úlapack_pyx_preambler4   r?   r]   r*   r*   r+   Úmake_lapack_pyx_preambleÕ   s    rb   aæ  

# Python-accessible wrappers for testing:

cdef inline bint _is_contiguous(double[:,:] a, int axis) nogil:
    return (a.strides[axis] == sizeof(a[0,0]) or a.shape[axis] == 1)

cpdef float complex _test_cdotc(float complex[:] cx, float complex[:] cy) nogil:
    cdef:
        int n = cx.shape[0]
        int incx = cx.strides[0] // sizeof(cx[0])
        int incy = cy.strides[0] // sizeof(cy[0])
    return cdotc(&n, &cx[0], &incx, &cy[0], &incy)

cpdef float complex _test_cdotu(float complex[:] cx, float complex[:] cy) nogil:
    cdef:
        int n = cx.shape[0]
        int incx = cx.strides[0] // sizeof(cx[0])
        int incy = cy.strides[0] // sizeof(cy[0])
    return cdotu(&n, &cx[0], &incx, &cy[0], &incy)

cpdef double _test_dasum(double[:] dx) nogil:
    cdef:
        int n = dx.shape[0]
        int incx = dx.strides[0] // sizeof(dx[0])
    return dasum(&n, &dx[0], &incx)

cpdef double _test_ddot(double[:] dx, double[:] dy) nogil:
    cdef:
        int n = dx.shape[0]
        int incx = dx.strides[0] // sizeof(dx[0])
        int incy = dy.strides[0] // sizeof(dy[0])
    return ddot(&n, &dx[0], &incx, &dy[0], &incy)

cpdef int _test_dgemm(double alpha, double[:,:] a, double[:,:] b, double beta,
                double[:,:] c) nogil except -1:
    cdef:
        char *transa
        char *transb
        int m, n, k, lda, ldb, ldc
        double *a0=&a[0,0]
        double *b0=&b[0,0]
        double *c0=&c[0,0]
    # In the case that c is C contiguous, swap a and b and
    # swap whether or not each of them is transposed.
    # This can be done because a.dot(b) = b.T.dot(a.T).T.
    if _is_contiguous(c, 1):
        if _is_contiguous(a, 1):
            transb = 'n'
            ldb = (&a[1,0]) - a0 if a.shape[0] > 1 else 1
        elif _is_contiguous(a, 0):
            transb = 't'
            ldb = (&a[0,1]) - a0 if a.shape[1] > 1 else 1
        else:
            with gil:
                raise ValueError("Input 'a' is neither C nor Fortran contiguous.")
        if _is_contiguous(b, 1):
            transa = 'n'
            lda = (&b[1,0]) - b0 if b.shape[0] > 1 else 1
        elif _is_contiguous(b, 0):
            transa = 't'
            lda = (&b[0,1]) - b0 if b.shape[1] > 1 else 1
        else:
            with gil:
                raise ValueError("Input 'b' is neither C nor Fortran contiguous.")
        k = b.shape[0]
        if k != a.shape[1]:
            with gil:
                raise ValueError("Shape mismatch in input arrays.")
        m = b.shape[1]
        n = a.shape[0]
        if n != c.shape[0] or m != c.shape[1]:
            with gil:
                raise ValueError("Output array does not have the correct shape.")
        ldc = (&c[1,0]) - c0 if c.shape[0] > 1 else 1
        dgemm(transa, transb, &m, &n, &k, &alpha, b0, &lda, a0,
                   &ldb, &beta, c0, &ldc)
    elif _is_contiguous(c, 0):
        if _is_contiguous(a, 1):
            transa = 't'
            lda = (&a[1,0]) - a0 if a.shape[0] > 1 else 1
        elif _is_contiguous(a, 0):
            transa = 'n'
            lda = (&a[0,1]) - a0 if a.shape[1] > 1 else 1
        else:
            with gil:
                raise ValueError("Input 'a' is neither C nor Fortran contiguous.")
        if _is_contiguous(b, 1):
            transb = 't'
            ldb = (&b[1,0]) - b0 if b.shape[0] > 1 else 1
        elif _is_contiguous(b, 0):
            transb = 'n'
            ldb = (&b[0,1]) - b0 if b.shape[1] > 1 else 1
        else:
            with gil:
                raise ValueError("Input 'b' is neither C nor Fortran contiguous.")
        m = a.shape[0]
        k = a.shape[1]
        if k != b.shape[0]:
            with gil:
                raise ValueError("Shape mismatch in input arrays.")
        n = b.shape[1]
        if m != c.shape[0] or n != c.shape[1]:
            with gil:
                raise ValueError("Output array does not have the correct shape.")
        ldc = (&c[0,1]) - c0 if c.shape[1] > 1 else 1
        dgemm(transa, transb, &m, &n, &k, &alpha, a0, &lda, b0,
                   &ldb, &beta, c0, &ldc)
    else:
        with gil:
            raise ValueError("Input 'c' is neither C nor Fortran contiguous.")
    return 0

cpdef double _test_dnrm2(double[:] x) nogil:
    cdef:
        int n = x.shape[0]
        int incx = x.strides[0] // sizeof(x[0])
    return dnrm2(&n, &x[0], &incx)

cpdef double _test_dzasum(double complex[:] zx) nogil:
    cdef:
        int n = zx.shape[0]
        int incx = zx.strides[0] // sizeof(zx[0])
    return dzasum(&n, &zx[0], &incx)

cpdef double _test_dznrm2(double complex[:] x) nogil:
    cdef:
        int n = x.shape[0]
        int incx = x.strides[0] // sizeof(x[0])
    return dznrm2(&n, &x[0], &incx)

cpdef int _test_icamax(float complex[:] cx) nogil:
    cdef:
        int n = cx.shape[0]
        int incx = cx.strides[0] // sizeof(cx[0])
    return icamax(&n, &cx[0], &incx)

cpdef int _test_idamax(double[:] dx) nogil:
    cdef:
        int n = dx.shape[0]
        int incx = dx.strides[0] // sizeof(dx[0])
    return idamax(&n, &dx[0], &incx)

cpdef int _test_isamax(float[:] sx) nogil:
    cdef:
        int n = sx.shape[0]
        int incx = sx.strides[0] // sizeof(sx[0])
    return isamax(&n, &sx[0], &incx)

cpdef int _test_izamax(double complex[:] zx) nogil:
    cdef:
        int n = zx.shape[0]
        int incx = zx.strides[0] // sizeof(zx[0])
    return izamax(&n, &zx[0], &incx)

cpdef float _test_sasum(float[:] sx) nogil:
    cdef:
        int n = sx.shape[0]
        int incx = sx.shape[0] // sizeof(sx[0])
    return sasum(&n, &sx[0], &incx)

cpdef float _test_scasum(float complex[:] cx) nogil:
    cdef:
        int n = cx.shape[0]
        int incx = cx.strides[0] // sizeof(cx[0])
    return scasum(&n, &cx[0], &incx)

cpdef float _test_scnrm2(float complex[:] x) nogil:
    cdef:
        int n = x.shape[0]
        int incx = x.strides[0] // sizeof(x[0])
    return scnrm2(&n, &x[0], &incx)

cpdef float _test_sdot(float[:] sx, float[:] sy) nogil:
    cdef:
        int n = sx.shape[0]
        int incx = sx.strides[0] // sizeof(sx[0])
        int incy = sy.strides[0] // sizeof(sy[0])
    return sdot(&n, &sx[0], &incx, &sy[0], &incy)

cpdef float _test_snrm2(float[:] x) nogil:
    cdef:
        int n = x.shape[0]
        int incx = x.shape[0] // sizeof(x[0])
    return snrm2(&n, &x[0], &incx)

cpdef double complex _test_zdotc(double complex[:] zx, double complex[:] zy) nogil:
    cdef:
        int n = zx.shape[0]
        int incx = zx.strides[0] // sizeof(zx[0])
        int incy = zy.strides[0] // sizeof(zy[0])
    return zdotc(&n, &zx[0], &incx, &zy[0], &incy)

cpdef double complex _test_zdotu(double complex[:] zx, double complex[:] zy) nogil:
    cdef:
        int n = zx.shape[0]
        int incx = zx.strides[0] // sizeof(zx[0])
        int incy = zy.strides[0] // sizeof(zy[0])
    return zdotu(&n, &zx[0], &incx, &zy[0], &incy)
c                    sH   d  ‡ fdd„| D ƒ¡}dd  ‡ fdd„|D ƒ¡ }t|ƒ| | t S )NÚ
c                 3   s   | ]}t |ˆ f Ž V  qd S ©N©rS   ©r(   r   ©rM   r*   r+   Ú	<genexpr>¥  r-   z$generate_blas_pyx.<locals>.<genexpr>c                 3   s&   | ]}t |d d d… ˆ f Ž V  qd S ©Né   ©rW   rf   rg   r*   r+   rh   ¦  s   ÿ)r?   r`   Úblas_py_wrappers)Ú	func_sigsÚsub_sigsr^   rM   ÚfuncsÚsubsr*   rg   r+   Úgenerate_blas_pyx¤  s
    ÿ
rq   až  

# Python accessible wrappers for testing:

def _test_dlamch(cmach):
    # This conversion is necessary to handle Python 3 strings.
    cmach_bytes = bytes(cmach)
    # Now that it is a bytes representation, a non-temporary variable
    # must be passed as a part of the function call.
    cdef char* cmach_char = cmach_bytes
    return dlamch(cmach_char)

def _test_slamch(cmach):
    # This conversion is necessary to handle Python 3 strings.
    cmach_bytes = bytes(cmach)
    # Now that it is a bytes representation, a non-temporary variable
    # must be passed as a part of the function call.
    cdef char* cmach_char = cmach_bytes
    return slamch(cmach_char)
c                    sL   d  ‡ fdd„| D ƒ¡}dd  ‡ fdd„|D ƒ¡ }t|ƒ}|| | t S )Nrc   c                 3   s   | ]}t |ˆ f Ž V  qd S rd   re   rf   rg   r*   r+   rh   Â  r-   z&generate_lapack_pyx.<locals>.<genexpr>c                 3   s&   | ]}t |d d d… ˆ f Ž V  qd S ri   rk   rf   rg   r*   r+   rh   Ã  s   ÿ)r?   rb   Úlapack_py_wrappers)rm   rn   r^   rM   ro   rp   Úpreambler*   rg   r+   Úgenerate_lapack_pyxÁ  s    ÿ
rt   zCctypedef {ret_type} {name}_t({args}) nogil
cdef {name}_t *{name}_f
z%cdef {ret_type} {name}({args}) nogil
c                 C   s$   |  dd¡  dd¡}tj| ||d�S )Nr<   rG   rT   rU   ©rH   r:   r0   )rO   Úpxd_templater4   ru   r*   r*   r+   Úpxd_declÐ  s    rw   aö  # Within scipy, these wrappers can be used via relative or absolute cimport.
# Examples:
# from ..linalg cimport cython_blas
# from scipy.linalg cimport cython_blas
# cimport scipy.linalg.cython_blas as cython_blas
# cimport ..linalg.cython_blas as cython_blas

# Within SciPy, if BLAS functions are needed in C/C++/Fortran,
# these wrappers should not be used.
# The original libraries should be linked directly.

ctypedef float s
ctypedef double d
ctypedef float complex c
ctypedef double complex z

c                 C   s   d  dd„ | D ƒ¡}t| S )Nrc   c                 s   s   | ]}t |Ž V  qd S rd   ©rw   rY   r*   r*   r+   rh   é  r-   z$generate_blas_pxd.<locals>.<genexpr>)r?   Úblas_pxd_preamble)r^   Úbodyr*   r*   r+   Úgenerate_blas_pxdè  s    r{   aM  # Within SciPy, these wrappers can be used via relative or absolute cimport.
# Examples:
# from ..linalg cimport cython_lapack
# from scipy.linalg cimport cython_lapack
# cimport scipy.linalg.cython_lapack as cython_lapack
# cimport ..linalg.cython_lapack as cython_lapack

# Within SciPy, if LAPACK functions are needed in C/C++/Fortran,
# these wrappers should not be used.
# The original libraries should be linked directly.

ctypedef float s
ctypedef double d
ctypedef float complex c
ctypedef double complex z

# Function pointer type declarations for
# gees and gges families of functions.
ctypedef bint cselect1(c*)
ctypedef bint cselect2(c*, c*)
ctypedef bint dselect2(d*, d*)
ctypedef bint dselect3(d*, d*, d*)
ctypedef bint sselect2(s*, s*)
ctypedef bint sselect3(s*, s*, s*)
ctypedef bint zselect1(z*)
ctypedef bint zselect2(z*, z*)

c                 C   s   t d dd„ | D ƒ¡ S )Nrc   c                 s   s   | ]}t |Ž V  qd S rd   rx   rY   r*   r*   r+   rh     r-   z&generate_lapack_pxd.<locals>.<genexpr>)Úlapack_pxd_preambler?   )r^   r*   r*   r+   Úgenerate_lapack_pxd  s    r}   zò      subroutine {name}wrp(
     +    ret,
     +    {argnames}
     +    )
        external {wrapper}
        {ret_type} {wrapper}
        {ret_type} ret
        {argdecls}
        ret = {wrapper}(
     +    {argnames}
     +    )
      end
z(*)z(ldab,*)z(lda,*))	ZworkÚabÚaÚdlr   ZduZapÚeZlldr2   )ÚxÚyr   )ZladivZlanhfZlansfZlapy2Zlapy3c                 C   sN   d| v r| S t |dd …  }d| v s,d| v r:| | d¡}n| | d¡}| | S )NÚincé   r‚   rƒ   z(n)r2   )Úspecial_casesrD   )rH   ÚfuncnameZspecialÚsuffixr*   r*   r+   Úprocess_fortran_name*  s    r‰   c                 C   s   g d¢}| |v rd|  S | S )N)ZcdotcZcdotuZzdotcZzdotuZcladivZzladivÚwr*   )rH   Zincludedr*   r*   r+   Úcalled_name5  s    r‹   c                    sb   t ˆ ƒ}t|ƒ\}}d |¡}‡ fdd„|D ƒ}d dd„ t||ƒD ƒ¡}tjˆ |||t| d�S )Nz,
     +    c                    s   g | ]}t |ˆ ƒ‘qS r*   )r‰   r7   ©rH   r*   r+   r,   A  r-   z+fort_subroutine_wrapper.<locals>.<listcomp>z	
        c                 s   s"   | ]\}}d   t| |¡V  qdS )z{0} {1}N)r4   Úfortran_typesr@   r*   r*   r+   rh   B  s   ÿz*fort_subroutine_wrapper.<locals>.<genexpr>)rH   ÚwrapperrL   Úargdeclsr:   )r‹   r1   r?   r/   Úfortran_templater4   r�   )rH   r:   r0   rŽ   Útypesr_   rL   r�   r*   rŒ   r+   Úfort_subroutine_wrapper<  s    

ÿþr’   c                 C   s   d  dd„ | D ƒ¡S )Nrc   c                 s   s   | ]}t |Ž V  qd S rd   )r’   rY   r*   r*   r+   rh   J  r-   z#generate_fortran.<locals>.<genexpr>r>   )rm   r*   r*   r+   Úgenerate_fortranI  s    r“   c                 C   s4   t | ƒ\}}dd„ |D ƒ}d dd„ t||ƒD ƒ¡S )Nc                 S   s   g | ]}t | ‘qS r*   )rN   r'   r*   r*   r+   r,   O  r-   zmake_c_args.<locals>.<listcomp>r.   c                 s   s   | ]\}}d   ||¡V  qdS )z{0} *{1}Nr3   )r(   rA   r8   r*   r*   r+   rh   P  r-   zmake_c_args.<locals>.<genexpr>)r1   r?   r/   )r0   r‘   r_   r*   r*   r+   Úmake_c_argsM  s    r”   zAvoid F_FUNC({name}wrp, {upname}WRP)({return_type} *ret, {args});
c                 C   s&   t |ƒ}t| }tj| |  ¡ ||d�S )N)rH   rI   Úreturn_typer0   )r”   rN   Úc_func_templater4   rQ   ©rH   r•   r0   r*   r*   r+   Úc_func_declW  s
    ÿr˜   z&void F_FUNC({name},{upname})({args});
c                 C   s   t |ƒ}tj| |  ¡ |d�S )N)rH   rI   r0   )r”   Úc_sub_templater4   rQ   r—   r*   r*   r+   Ú
c_sub_decla  s    rš   z•#ifndef SCIPY_LINALG_{lib}_FORTRAN_WRAPPERS_H
#define SCIPY_LINALG_{lib}_FORTRAN_WRAPPERS_H
#include "fortran_defs.h"
#include "numpy/arrayobject.h"
a‰  
typedef int (*_cselect1)(npy_complex64*);
typedef int (*_cselect2)(npy_complex64*, npy_complex64*);
typedef int (*_dselect2)(double*, double*);
typedef int (*_dselect3)(double*, double*, double*);
typedef int (*_sselect2)(float*, float*);
typedef int (*_sselect3)(float*, float*, float*);
typedef int (*_zselect1)(npy_complex128*);
typedef int (*_zselect2)(npy_complex128*, npy_complex128*);
z)
#ifdef __cplusplus
extern "C" {
#endif

z$
#ifdef __cplusplus
}
#endif
#endif
c                 C   sf   d  dd„ | D ƒ¡}dd  dd„ |D ƒ¡ }|dkrFtj|d�t }ntj|d�}d  |t||tg¡S )Nr2   c                 s   s   | ]}t |Ž V  qd S rd   )r˜   rY   r*   r*   r+   rh   ‡  r-   z$generate_c_header.<locals>.<genexpr>rc   c                 s   s   | ]}t |Ž V  qd S rd   )rš   rY   r*   r*   r+   rh   ˆ  r-   ÚLAPACK)Úlib)r?   Ú
c_preambler4   Úlapack_declsÚ	cpp_guardÚc_end)rm   rn   r^   Zlib_namero   rp   rs   r*   r*   r+   Úgenerate_c_header†  s    r¡   c                 C   s.   | d d…   d¡\}}|  d¡\}}|||fS )Néÿÿÿÿú(ú r%   )rZ   Zname_and_typer0   r:   rH   r*   r*   r+   Úsplit_signature�  s    r¥   c                 C   sT   dd„ t tj| ƒD ƒ} dd„ | D ƒ}dd„ | D ƒ}tt|| tdƒd�ƒ}|||fS )Nc                 S   s   g | ]}|r|  d ¡s|‘qS )ú#)Ú
startswith©r(   Úliner*   r*   r+   r,   —  s   ÿz filter_lines.<locals>.<listcomp>c                 S   s&   g | ]}|  d ¡d dkrt|ƒ‘qS ©r¤   r   Úvoid©r&   r¥   r¨   r*   r*   r+   r,   ™  s   ÿc                 S   s&   g | ]}|  d ¡d dkrt|ƒ‘qS rª   r¬   r¨   r*   r*   r+   r,   ›  s   ÿr   )Úkey)ÚmapÚstrÚstripÚlistÚsortedr   )Úlinesrm   rn   r^   r*   r*   r+   Úfilter_lines–  s
    r´   c                    s$   ddl m‰  t‡ ‡fdd„|D ƒƒS )Nr   )Únewerc                 3   s.   | ]&}ˆD ]}t j |¡o"ˆ ||ƒV  q
qd S rd   )ÚosÚpathÚexists)r(   ÚdstÚsrc©rµ   Ú	src_filesr*   r+   rh   £  s   
ÿzall_newer.<locals>.<genexpr>)Údistutils.dep_utilrµ   Úall)r¼   Ú	dst_filesr*   r»   r+   Ú	all_newer¡  s    ÿrÀ   úcython_blas_signatures.txtúcython_lapack_signatures.txtÚcython_blasÚcython_lapackú_blas_subroutine_wrappers.fú_lapack_subroutine_wrappers.fú_blas_subroutines.hú_lapack_subroutines.hc                 C   s”  t j t¡| |f}|d |d |||d |d ||f}	t  t¡ t||	ƒrVtdƒ d S ddg}
d dd„ |
D ƒ¡d	 }d d
d„ |
D ƒ¡d	 }d dd„ |
D ƒ¡d	 }t	| dƒ�}| 
¡ }W d   ƒ n1 sÎ0    Y  t|ƒ}t||f Ž }t	|d dƒ�$}| |¡ | |¡ W d   ƒ n1 �s(0    Y  t|d ƒ}t	|d dƒ�$}| |¡ | |¡ W d   ƒ n1 �sx0    Y  t|d ƒ}t	|dƒ�$}| |¡ | |¡ W d   ƒ n1 �sÄ0    Y  t|d Ž }t	|dƒ�$}| |¡ | |¡ W d   ƒ n1 �s0    Y  t	|dƒ�}| 
¡ }W d   ƒ n1 �sD0    Y  t|ƒ}t||f Ž }t	|d dƒ�$}| |¡ | |¡ W d   ƒ n1 �sž0    Y  t|d ƒ}t	|d dƒ�$}| |¡ | |¡ W d   ƒ n1 �sî0    Y  t|d ƒ}t	|dƒ�$}| |¡ | |¡ W d   ƒ n1 �s:0    Y  t|d Ž }t	|dƒ�$}| |¡ | |¡ W d   ƒ n1 �s†0    Y  d S )Nz.pyxz.pxdz3scipy/linalg/_generate_pyx.py: all files up-to-datez-This file was generated by _generate_pyx.py.
z Do not edit this file directly.
r2   c                 S   s   g | ]}d |  ¡  d ‘qS )z/* z */
)Úrstripr¨   r*   r*   r+   r,   Ä  s   ÿzmake_all.<locals>.<listcomp>rc   c                 S   s   g | ]}d | ‘qS )z# r*   r¨   r*   r*   r+   r,   Æ  r-   c                 S   s   g | ]}d | ‘qS )zc     r*   r¨   r*   r*   r+   r,   Ç  r-   ÚrrŠ   rj   r   )ZBLAS)r›   )r¶   r·   ÚabspathÚ__file__ÚchdirÚBASE_DIRrÀ   Úprintr?   ÚopenÚ	readlinesr´   rq   Úwriter{   r“   r¡   rt   r}   )Zblas_signature_fileZlapack_signature_fileZ	blas_nameZlapack_nameZblas_fortran_nameZlapack_fortran_nameZblas_header_nameZlapack_header_namer¼   r¿   ÚcommentsZccommentZ
pyxcommentZfcommentÚfZ	blas_sigsZblas_pyxZblas_pxdZblas_fortranZblas_c_headerZlapack_sigsZ
lapack_pyxZ
lapack_pxdZlapack_fortranZlapack_c_headerr*   r*   r+   Úmake_all§  s‚    	
þù	

ÿ
ÿÿ&
*
*
*
*(
*
*
*
rÕ   Ú__main__)rÁ   rÂ   rÃ   rÄ   rÅ   rÆ   rÇ   rÈ   );Ú__doc__Úcollectionsr   Úoperatorr   r¶   r·   rË   ÚdirnamerÌ   rÎ   r�   rN   r1   rP   rC   r5   rS   rV   rW   r\   r`   ra   rb   rl   rq   rr   rt   rv   rw   ry   r{   r|   r}   r�   ÚdimsZxy_specialized_dimsZa_specialized_dimsÚdictr†   r‰   r‹   r’   r“   r”   r–   r˜   r™   rš   r�   rž   rŸ   r    r¡   r¥   r´   rÀ   rÕ   Ú__name__r*   r*   r*   r+   Ú<module>   sÂ   úò	ü)6 K
ÿ
û
        ù
I
