<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 6, 2015 at 8:04 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">On Tue, Oct 6, 2015 at 11:52 AM, David Cournapeau <<a href="mailto:cournape@gmail.com">cournape@gmail.com</a>> wrote:<br>
><br>
><br>
> On Tue, Oct 6, 2015 at 7:30 PM, Nathaniel Smith <<a href="mailto:njs@pobox.com">njs@pobox.com</a>> wrote:<br>
>><br>
>> [splitting this off into a new thread]<br>
>><br>
>> On Tue, Oct 6, 2015 at 3:00 AM, David Cournapeau <<a href="mailto:cournape@gmail.com">cournape@gmail.com</a>><br>
>> wrote:<br>
>> [...]<br>
>> > I also agree the current situation is not sustainable -- as we discussed<br>
>> > privately before, cythonizing numpy.core is made quite more complicated<br>
>> > by<br>
>> > this. I have myself quite a few issues w/ cythonizing the other parts of<br>
>> > umath. I would also like to support the static link better than we do<br>
>> > now<br>
>> > (do we know some static link users we can contact to validate our<br>
>> > approach<br>
>> > ?)<br>
>> ><br>
>> > Currently, what we have in numpy core is the following:<br>
>> ><br>
>> > numpy.core.multiarray -> compilation units in numpy/core/src/multiarray/<br>
>> > +<br>
>> > statically link npymath<br>
>> > numpy.core.umath -> compilation units in numpy/core/src/umath +<br>
>> > statically<br>
>> > link npymath/npysort + some shenanigans to use things in<br>
>> > numpy.core.multiarray<br>
>><br>
>> There are also shenanigans in the other direction - supposedly umath<br>
>> is layered "above" multiarray, but in practice there are circular<br>
>> dependencies (see e.g. np.set_numeric_ops).<br>
><br>
> Indeed, I am not arguing about merging umath and multiarray.<br>
<br>
</div></div>Oh, okay :-).<br>
<span class=""><br>
>> > I would suggest to have a more layered approach, to enable both 'normal'<br>
>> > build and static build, without polluting the public namespace too much.<br>
>> > This is an approach followed by most large libraries (e.g. MKL), and is<br>
>> > fairly flexible.<br>
>> ><br>
>> > Concretely, we could start by putting more common functionalities (aka<br>
>> > the<br>
>> > 'core' library) into its own static library. The API would be considered<br>
>> > private to numpy (no stability guaranteed outside numpy), and every<br>
>> > exported<br>
>> > symbol from that library would be decorated appropriately to avoid<br>
>> > potential<br>
>> > clashes (e.g. '_npy_internal_').<br>
>><br>
>> I don't see why we need this multi-layered complexity, though.<br>
><br>
><br>
> For several reasons:<br>
><br>
>  - when you want to cythonize either extension, it is much easier to<br>
> separate it as cython for CPython API, C for the rest.<br>
<br>
</span>I don't think this will help much, because I think we'll want to have<br>
multiple cython files, and that we'll probably move individual<br>
functions between being implemented in C and Cython (including utility<br>
functions). So that means we need to solve the problem of mixing C and<br>
Cython files inside a single library.<br></blockquote><div><br></div><div>Separating the pure C code into static lib is the simple way of achieving the same goal. Essentially, you write:<br><br></div><div># implemented in npyinternal.a<br></div><div>_npy_internal_foo(....)<br><br></div><div># implemented in merged_multiarray_umath.pyx<br></div><div>cdef PyArray_Foo(...):<br></div><div>    # use _npy_internal_foo()<br><br></div><div>then our merged_multiarray_umath.so is built by linking the .pyx and the npyinternal.a together. IOW, the static link is internal.<br><br></div><div>Going through npyinternal.a instead of just linking .o from pure C and Cython together gives us the following:<br><br></div><div> 1. the .a can just use normal linking strategies instead of the awkward capsule thing. Those are easy to get wrong when using cython as you may end up with multiple internal copies of the wrapped object inside capsule, causing hard to track bugs (this is what we wasted most of the time on w/ Stefan and Kurt during ds4ds)<br></div><div> 2. the only public symbols in .a are the ones needed by the cython wrapping, and since those are decorated with npy_internal, clashes are unlikely to happen<br></div><div> 3. since most of the code is already in .a internally, supporting the static linking should be simpler since the only difference is how you statically link the cython-generated code. Because of 1, you are also less likely to cause nasty surprises when putting everything together.<br></div><br>When you cythonize umath/multiarray, you need to do most of the underlying work anyway<br><br></div><div class="gmail_quote">I don't really care if the files are in the same directory or not, we can keep things as they are now.<br><br></div><div class="gmail_quote">David<br></div><br></div></div>