New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fused types in pxd --> Exception: This may never happen, please report a bug #2655

Open
jbrockmendel opened this Issue Oct 13, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@jbrockmendel

jbrockmendel commented Oct 13, 2018

Adding the following in statsmodels/src/math.pxd:

cimport scipy.linalg.cython_blas as blas
from numpy cimport float32_t, float64_t, complex64_t, complex128_t

ctypedef fused dot_t:
    float32_t
    float64_t
    complex64_t
    complex128_t


cdef inline dot_t blas_dot(int nrows, dot_t* left, int ncols, dot_t* right):
    cdef:
        # Parameters to simplify more general gemv call into just dot product
        int inc = 1
        dot_t alpha = 1
        dot_t beta = 0
        dot_t tmp

    if dot_t is float64_t:
        tmp = blas.ddot(&nrows,
                        left, &ncols,
                        right, &inc)

    elif dot_t is float32_t:
        tmp = blas.sdot(&nrows,
                        left, &ncols,
                        right, &inc)

    elif dot_t is complex64_t:
        # Note: zdot and cdot are broken, so have to use gemv for those
        blas.cgemv("N", &inc, &nrows,
                   &alpha, right, &inc,
                   left, &ncols,
                   &beta, &tmp, &inc)

    elif dot_t is complex128_t:
        # Note: zdot and cdot are broken, so have to use gemv for those
        blas.zgemv("N", &inc, &nrows,
                   &alpha, right, &inc,
                   left, &ncols,
                   &beta, &tmp, &inc)

    return tmp

leads to

Traceback (most recent call last):
  File "setup.py", line 288, in <module>
    extensions = cythonize(extensions, compiler_directives=COMPILER_DIRECTIVES)
[...]
  File "/usr/local/lib/python2.7/site-packages/Cython/Compiler/PyrexTypes.py", line 1646, in declaration_code
    raise Exception("This may never happen, please report a bug")
Exception: This may never happen, please report a bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment