Repository: scipy/scipy

Issue:
ENH: Expose Cythonized functions to other pyx files through cimport
This is more of a learning issue that I have been trying out for a few weeks now but couldn't have any progress. What I would like to have is 
 - expose a Cython API for linalg that is similar to `cython_blas`, `cython_lapack` or `cython_special`. 
 - or at least make certain Cythonized functions common to all scipy functions. 

I think I can say that I really don't understand the machinery `_generate_pyx.py` or the `custom_target` of meson yet. 

#### A particular case study: 

In `matfuncs_expm.pyx.in` file there is a function that is a fast transpose for memoryviews. What I wanted to have is to make it available through `_cythonized_linalg_utils.pyx` and `cimport` it via other pyx files. To do that it turns out that I need a pxd file for the definitions since I am constantly getting 

```
from ._cythonized_array_utils cimport swap_c_and_f_layout
^
------------------------------------------------------------

scipy\linalg\_matfuncs_expm.pyx:31:0: 'scipy\linalg\_cythonized_array_utils.pxd' not found
```

But processing pxd file is quite the black magic both in distutils and also meson. Or put better, I really don't understand it at all. And I would like to throw the towel after wasting a lot of time. 

The resulting structure I tried to have is 

```
-- __cythonized_array_utils  #  this namespace holds the cimportable 'swap_c_f_layout' function
 | ...
 | ...
 |- _matfuncs_expm.pyx.in #  this file cimports the 'swap_c_f_layout'
 |- ...
```

The optimal outcome is to expose a Cython `cython_linalg_utils` API however that turned out to be even more complicated hence the case study above is already enough for me. Maybe it can be also beneficial for others in the future to expose a Cython API in other modules.

#### What I have tried

There are many permutations I've tried but the generic attempt was to create a pxd file and change `setup.py` to

```python
    config.add_data_files('_cythonized_array_utils.pxd')
    config.add_extension('_cythonized_array_utils',
                         sources=['_cythonized_array_utils.c',
                                        '_cythonized_array_utils.pxd'])  #  also tried the "depends" etc. but
                                                                         #  documentation is awful for distutils on these
```



Discussion:

Resolving patch:
diff --git a/scipy/linalg/setup.py b/scipy/linalg/setup.py
--- a/scipy/linalg/setup.py
+++ b/scipy/linalg/setup.py
@@ -146,8 +146,14 @@ def configuration(parent_package='', top_path=None):
     config.add_extension('_decomp_update',
                          sources=['_decomp_update.c'])
 
+    config.add_data_files('_cythonized_array_utils.pxd')
+
     config.add_extension('_cythonized_array_utils',
-                         sources=['_cythonized_array_utils.c'])
+                         sources=['_cythonized_array_utils.c'],
+                         depends=['_cythonized_array_utils.pyx',
+                                  '_cythonized_array_utils.pxd'],
+                         include_dirs=['.']
+                         )
 
     config.add_extension('_matfuncs_expm',
                          sources=['_matfuncs_expm.c'])


Test patch: