最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Cython strategy for organizing source files targeted for multiple implementations? - Stack Overflow

programmeradmin1浏览0评论

I have a project (which is my first Cython project), where a computation speed is critical, but I also want to utilize Cython's ease of distribution.

Because of this reason, I wrote only a common interface and then implemented using different libraries (e.g., for linear algebra, CBLAS, cuBLAS, ...) Now, I have a module inside my project, that currently has a structure of

└── module/ 
    ├── __init__.py
    ├── common.pxd 
    ├── foo.pxd 
    ├── foo/ 
    │   ├── foo_1.pyx
    │   └── foo_2.pyx
    ├── bar.pxd 
    └── bar/ 
        ├── bar_1.pyx
        └── bar_2.pyx

where at compile time, I can choose via setup.py file

if target==1:
    module_foo = Extension(
        name = package_name + '.module.foo',
        sources=[src_path + 'module/foo/foo_1.pyx'],
   )
    module_bar = Extension(
        name = package_name + '.module.bar',
        sources=[src_path + 'module/bar/bar_1.pyx'],
    )
elif target==2:
    module_foo = Extension(
        name = package_name + '.module.foo',
        sources=[src_path + 'module/foo/foo_2.pyx'],
   )
    module_bar = Extension(
        name = package_name + '.module.bar',
        sources=[src_path + 'module/bar/bar_2.pyx'],
    )

or at least I thought this would work. The problem is, I cannot import anything from *pyx files inside the subdirectories because they're "non-package directory", including the common.pxd, foo.pxd, and bar.pxd.

It would be the best if I could use C-style conditional compilation directives, but it seems that is also deprecated in the recent Cython.

I also want to wrap common functions inside foo and bar and put it in a separate file, but it also doesn't seem to work very well..

So, what would be the best strategy in my case? Any suggestions would help immensely.

发布评论

评论列表(0)

  1. 暂无评论