<div dir="ltr"><div>Hi all,</div><div><br></div><div>As you might have seen my recent mails in Cython list, I'm trying to cook up an input validator for the linalg.solve() function. The machinery of SciPy linalg is as follows: <br></div><div><br></div><div>Some input comes in passes through np.asarray() then depending on the resulting dtype of the numpy array we choose a LAPACK flavor (s,d,c,z) and off it goes through f2py to lalaland and comes back with some result. <br></div><div><br></div><div>For the backslash polyalgorithm I need the arrays to be contiguous (C- or F- doesn't matter) and any of the four (possibly via making new copies) float, double, float complex, double complex after the intake because we are using wrapped fortran code (LAPACK) in SciPy. So my difficulty is how to type such function input, say, <br></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">ctypedef fused numeric_numpy_t:<br>    bint<br>    cnp.npy_bool<br>    cnp.int_t       <br>    cnp.intp_t      <br>    cnp.int8_t      <br>    cnp.int16_t     <br>    cnp.int32_t     <br>    cnp.int64_t     <br>    cnp.uint8_t     <br>    cnp.uint16_t    <br>    cnp.uint32_t    <br>    cnp.uint64_t<br>    cnp.float32_t   <br>    cnp.float64_t   <br>    cnp.complex64_t <br>    cnp.complex128_t</span><br></div><div><br></div><div>Is this acceptable or something else needs to be used? Then there is the storyof np.complex256 and mysterious np.float16. Then there is the Linux vs Windows platform dependence issue and possibly some more that I can't comprehend. Then there are datetime, str, unicode etc. that need to be rejected. So this is quickly getting out of hand for my small brain.<br></div><div><br></div><div>To be honest, I am a bit running out of steam working with this issue even though I managed to finish the actual difficult algorithmic part but got stuck here. I am quite surprised how fantastically complicated and confusing both NumPy and Cython docs about this stuff. Shouldn't we keep a generic fused type for such usage? Or maybe there already exists 

but I don't know and would be really grateful for pointers.</div><div><br></div><div>Here I wrote a dummy typed Cython function just for type checking:</div><div><br></div><div><span style="font-family:monospace">cpdef inline bint ncc(
numeric_numpy_t[:, :] a):<br>    print(a.is_f_contig())<br>    print(a.is_c_contig())<br><br>    return a.is_f_contig() or a.is_c_contig()</span></div><div><br></div><div>And this is a dummy loop (with aliases) just to check whether fused type is working or not (on windows I couldn't make it work for float16).<br></div><div><br></div><div><span style="font-family:monospace">for x in (np.uint, np.uintc, np.uintp, np.uint0, np.uint8, np.uint16, np.uint32,<br>          np.uint64, <a href="http://np.int">np.int</a>, np.intc, np.intp, np.int0, np.int8, np.int16,<br>          np.int32,np.int64, np.float, np.float32, np.float64, np.float_,<br>          np.complex, np.complex64, np.complex128, np.complex_):<br>    print(x)<br>    C = np.arange(25., dtype=x).reshape(5, 5)<br>    ncc(C)</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:arial,sans-serif">Thanks in advance,</span></div><div><span style="font-family:monospace"><span style="font-family:arial,sans-serif">ilhan</span><br></span></div><div><br></div></div>