B
    0da                 @   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re9  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	characterZ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&   L/var/www/html/venv/lib/python3.7/site-packages/scipy/linalg/_generate_pyx.py
<listcomp>(   s    z'arg_names_and_types.<locals>.<listcomp>z, )zipr#   )argsr&   r&   r'   arg_names_and_types'   s    r+   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k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    
r.   c          
      s   t |\}} |k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   s    z!pyx_decl_func.<locals>.<listcomp>c             S   s    g | ]}|d kr|n|d qS ))lambdainr/   r&   )r$   r0   r&   r&   r'   r(   K   s   z, c             S   s   g | ]\}}d  ||gqS )z *)join)r$   r0   tr&   r&   r'   r(   M   s   c             S   s   g | ]}t ||qS r&   )	npy_typesget)r$   r5   r&   r&   r'   r(   O   s    c             S   s   g | ]\}}d  ||gqS )z *)r4   )r$   r0   r5   r&   r&   r'   r(   P   s   c             S   s   g | ]\}}t || qS r&   )r.   )r$   r0   r5   r&   r&   r'   r(   R   s    r2   lambda_)nameupnamer*   	fort_argsr1   
c_ret_typeargnamesheader_name)r+   r4   r)   c_typesreplacepyx_func_templater-   upper)r9   r1   r*   r>   argtypesr=   r;   r<   r&   )r1   r'   pyx_decl_funcC   s$    


rD   zcdef 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&   )r6   r7   )r$   r5   r&   r&   r'   r(   e   s    z pyx_decl_sub.<locals>.<listcomp>c             S   s    g | ]}|d kr|n|d qS ))r2   r3   r/   r&   )r$   r0   r&   r&   r'   r(   f   s    z, c             S   s   g | ]\}}d  ||gqS )z *)r4   )r$   r0   r5   r&   r&   r'   r(   g   s   c             S   s   g | ]\}}t || qS r&   )r.   )r$   r0   r5   r&   r&   r'   r(   i   s    z*lambda,z	*lambda_,z*in,z*in_,)r9   r:   r*   r;   r=   r>   )r+   r4   r)   r@   pyx_sub_templater-   rB   )r9   r*   r>   rC   r=   r;   r&   r&   r'   pyx_decl_subc   s    

rF   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(      s    z*make_blas_pyx_preamble.<locals>.<listcomp>z
- )blas_pyx_preambler-   r4   )all_sigsnamesr&   r&   r'   make_blas_pyx_preamble   s    rK   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 )r   r&   )r$   rG   r&   r&   r'   r(      s    z,make_lapack_pyx_preamble.<locals>.<listcomp>z
- )lapack_pyx_preambler-   r4   )rI   rJ   r&   r&   r'   make_lapack_pyx_preamble   s    rM   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)rD   )r$   r   )r>   r&   r'   	<genexpr>  s    z$generate_blas_pyx.<locals>.<genexpr>c             3   s&   | ]}t |d d d  f  V  qd S )N   )rF   )r$   r   )r>   r&   r'   rO     s   )r4   rK   blas_py_wrappers)	func_sigssub_sigsrI   r>   funcssubsr&   )r>   r'   generate_blas_pyx  s    rV   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 )NrN   c             3   s   | ]}t | f  V  qd S )N)rD   )r$   r   )r>   r&   r'   rO     s    z&generate_lapack_pyx.<locals>.<genexpr>c             3   s&   | ]}t |d d d  f  V  qd S )NrP   )rF   )r$   r   )r>   r&   r'   rO     s   )r4   rM   lapack_py_wrappers)rR   rS   rI   r>   rT   rU   preambler&   )r>   r'   generate_lapack_pyx  s
    rY   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 )Nr2   r8   z*in,z*in_,)r9   r1   r*   )r@   pxd_templater-   )r9   r1   r*   r&   r&   r'   pxd_decl  s    r[   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 )NrN   c             s   s   | ]}t | V  qd S )N)r[   )r$   rG   r&   r&   r'   rO     s    z$generate_blas_pxd.<locals>.<genexpr>)r4   blas_pxd_preamble)rI   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 )NrN   c             s   s   | ]}t | V  qd S )N)r[   )r$   rG   r&   r&   r'   rO     s    z&generate_lapack_pxd.<locals>.<genexpr>)lapack_pxd_preambler4   )rI   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lldr,   )xyrb   )ZladivZlanhfZlansfZlapy2Zlapy3c             C   sN   d| kr| S t |dd   }d| ks,d| kr:|| d}n|| d}| | S )Ninc   re   rf   z(n)r,   )special_casesr7   )r9   funcnamespecialsuffixr&   r&   r'   process_fortran_name*  s    rm   c             C   s$   ddddddg}| |kr d|  S | S )NZcdotcZcdotuZzdotcZzdotuZcladivZzladivwr&   )r9   Zincludedr&   r&   r'   called_name5  s    ro   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&   )rm   )r$   r0   )r9   r&   r'   r(   A  s    z+fort_subroutine_wrapper.<locals>.<listcomp>z	
        c             s   s"   | ]\}}d  t| |V  qdS )z{0} {1}N)r-   fortran_types)r$   r0   r5   r&   r&   r'   rO   B  s   z*fort_subroutine_wrapper.<locals>.<genexpr>)r9   wrapperr=   argdeclsr1   )ro   r+   r4   r)   fortran_templater-   rp   )r9   r1   r*   rq   typesrJ   r=   rr   r&   )r9   r'   fort_subroutine_wrapper<  s    

ru   c             C   s   d dd | D S )NrN   c             s   s   | ]}t | V  qd S )N)ru   )r$   rG   r&   r&   r'   rO   J  s    z#generate_fortran.<locals>.<genexpr>)r4   )rR   r&   r&   r'   generate_fortranI  s    rv   c             C   s4   t | \}}dd |D }ddd t||D S )Nc             S   s   g | ]}t | qS r&   )r?   )r$   r%   r&   r&   r'   r(   O  s    zmake_c_args.<locals>.<listcomp>z, c             s   s   | ]\}}d  ||V  qdS )z{0} *{1}N)r-   )r$   r5   r0   r&   r&   r'   rO   P  s    zmake_c_args.<locals>.<genexpr>)r+   r4   r)   )r*   rt   rJ   r&   r&   r'   make_c_argsM  s    rw   zAvoid F_FUNC({name}wrp, {upname}WRP)({return_type} *ret, {args});
c             C   s&   t |}t| }tj| |  ||dS )N)r9   r:   return_typer*   )rw   r?   c_func_templater-   rB   )r9   rx   r*   r&   r&   r'   c_func_declW  s    rz   z&void F_FUNC({name},{upname})({args});
c             C   s   t |}tj| |  |dS )N)r9   r:   r*   )rw   c_sub_templater-   rB   )r9   rx   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 )Nr,   c             s   s   | ]}t | V  qd S )N)rz   )r$   rG   r&   r&   r'   rO     s    z$generate_c_header.<locals>.<genexpr>rN   c             s   s   | ]}t | V  qd S )N)r|   )r$   rG   r&   r&   r'   rO     s    LAPACK)lib)r4   
c_preambler-   lapack_decls	cpp_guardc_end)rR   rS   rI   Zlib_namerT   rU   rX   r&   r&   r'   generate_c_header  s    r   c             C   s.   | d d  d\}}| d\}}|||fS )N( )r#   )rG   Zname_and_typer*   r1   r9   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'   r(     s    c             S   s&   g | ]}| d d dkrt|qS )r   r   r   )r#   r   )r$   r   r&   r&   r'   r(     s    r   )key)mapstrstriplistsortedr   )linesrR   rS   rI   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 )N)ospathexists)r$   dstsrc)r   	src_filesr&   r'   rO     s   zall_newer.<locals>.<genexpr>)distutils.dep_utilr   all)r   	dst_filesr&   )r   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 Q R X t|}t||f  }t	|d d}|| || W d Q R X t|d }t	|d d}|| || W d Q R X t|d }t	|d}|| || W d Q R X t|d  }t	|d}|| || W d Q R X t	|d}|
 }W d Q R X t|}t||f  }t	|d d}|| || W d Q R X t|d }t	|d d}|| || W d Q R X t|d }t	|d}|| || W d Q R X t|d  }t	|d}|| || W d Q R X 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.
r,   c             S   s   g | ]}d |   d qS )z/* z */
)rstrip)r$   r   r&   r&   r'   r(     s   zmake_all.<locals>.<listcomp>rN   c             S   s   g | ]}d | qS )z# r&   )r$   r   r&   r&   r'   r(     s    c             S   s   g | ]}d | qS )zc     r&   )r$   r   r&   r&   r'   r(     s    rrn   rP   r   )ZBLAS)r}   )r   r   abspath__file__chdirBASE_DIRr   printr4   open	readlinesr   rV   writer^   rv   r   rY   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  sv    	











r   __main__)r   r   r   r   r   r   r   r   );__doc__collectionsr   operatorr   r   r   r   dirnamer   r   rp   r?   r+   rA   r6   r.   rD   rE   rF   rH   rK   rL   rM   rQ   rV   rW   rY   rZ   r[   r\   r^   r_   r`   rs   ZdimsZxy_specialized_dimsZa_specialized_dimsdictri   rm   ro   ru   rv   rw   ry   rz   r{   r|   r   r   r   r   r   r   r   r   r   __name__r&   r&   r&   r'   <module>   s   
48 M
 
	
       
B
