cython

python项目打包相关知识

我们两清 提交于 2020-02-27 06:48:14
一、编译为so: 编译除__init__.py之外的py文件,并且除__init__.py以外,不拷贝其他.py文件 from setuptools import setup, find_packages from distutils.command.build_py import build_py as build_py_orig from Cython.Build import cythonize class CustBbuildPy(build_py_orig): def find_modules(self): modules = super().find_modules() modules = [module for module in modules if module[1] == "__init__"] # 只拷贝__init__.py return modules def find_package_modules(self, package, package_dir): modules = super().find_package_modules(package, package_dir) modules = [module for module in modules if module[1] == "__init__"] # 只拷贝__init__.py

return 2D array created from a C function into Python using Cython

泪湿孤枕 提交于 2020-02-25 09:38:05
问题 I want to use a 2D array created by a c function in python . I asked how to do this before today and one approach suggested by @Abhijit Pritam was to use structs. I implemented it and it does work. c code: typedef struct { int arr[3][5]; } Array; Array make_array_struct() { Array my_array; int count = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 5; j++) my_array.arr[i][j] = ++count; return my_array; } in python I have this: cdef extern from "numpy_fun.h": ctypedef struct Array: int[3][5

Line profiling with cython in jupyter notebook

ⅰ亾dé卋堺 提交于 2020-02-25 08:18:06
问题 I'm trying to use liner_profiler library in jupyter notebook with cython function. It is working only halfway. The result I get only consist of first row of the function and no profiling results. %%cython -a # cython: linetrace=True # cython: binding=True # distutils: define_macros=CYTHON_TRACE_NOGIL=1 import numpy as np cimport numpy as np from datetime import datetime import math cpdef np.int64_t get_days(np.int64_t year, np.int64_t month): cdef np.ndarray months=np.array([31,28,31,30,31,30

edgedb 内部pg 数据存储的探索 (三) 源码包setup.py 文件

好久不见. 提交于 2020-02-25 07:25:19
edgedb 是基于python开发的,同时集成了cython 以下为包的setup.py 配置,从里面我们可以看到关于edgedb 的一些依赖 以及构建过程 setup.py 源码 整体配置不算很多,500 多行,主要是cython extension 配置以及pg 构建配置,以及pg extension 配置,其中添加了关于pg 以及 pg 扩展build 的自定义cmdclass 代码 # # This source file is part of the EdgeDB open source project. # # Copyright 2008-present MagicStack Inc. and the EdgeDB authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed

Cython “Cannot take address of memoryview slice”

狂风中的少年 提交于 2020-02-25 06:05:07
问题 I am having trouble creating a simple class in Cython. There is little documentation related to handling memoryviews for arrays in C++ wrappers. I want to create a data class with time, x, y, and z attributes. I need these attributes to be arrays, which will ultimately be callable in Python. I previously had this working using numpy types, but I would like to do this properly using memoryviews. My background is not strong in C++. For now, I am only trying to get the time attribute working

Cython “Cannot take address of memoryview slice”

可紊 提交于 2020-02-25 06:04:58
问题 I am having trouble creating a simple class in Cython. There is little documentation related to handling memoryviews for arrays in C++ wrappers. I want to create a data class with time, x, y, and z attributes. I need these attributes to be arrays, which will ultimately be callable in Python. I previously had this working using numpy types, but I would like to do this properly using memoryviews. My background is not strong in C++. For now, I am only trying to get the time attribute working

python 集成cython 简单测试

纵饮孤独 提交于 2020-02-23 09:06:02
实际开发中我们可能需要集成c/c++ 编写的模块,我们可以通过cython 解决类似的问题 以下测试一个简单的c add 方法, 使用venv 同时构建为一个pip 包 环境准备 venv 初始化 python3 -m venv . 添加项目依赖包 pip install click cython 代码结构 ├── Makefile ├── README.md ├── cli │ ├── __init__.py │ └── app.pyx ├── ext │ ├── Makefile │ ├── add.c │ ├── add.h ├── pyvenv.cfg └── setup.py c 项目代码说明 ext 目录为c add 函数同时make 进行项目构建 add.h int add(int first,int second); add.c #include "add.h" int add(int first,int second){ return first+second; } Makefile: 主要是进行静态库的构建 CC = gcc default: libadd.a libadd.a: add.o ar rcs $@ $^ add.o: add.c add.h $(CC) -c $< clean: rm *.o *.a cython 包装c 静态库 lib/app

Compiling Executable with dask or joblib multiprocessing with cython results in errors

删除回忆录丶 提交于 2020-02-22 15:33:33
问题 I'm converting some serial processed python jobs to multiprocessing with dask or joblib. Sadly I need to work on windows. When running from within IPython or from command line invoking the py-file with python everything is running fine. When compiling an executable with cython, it is no longer running fine: Step by step more and more processes (unlimited and bigger than the number of requested processes) get startet and block my system. It somehow feels like Multiprocessing Bomb - but of

How can I merge multiple Cython pyx files into a single linked library?

ぃ、小莉子 提交于 2020-02-10 10:55:51
问题 I have multiple .pyx files, is there a way to import them into a single pyx file and compile that file into a shared library, instead of having to compile 15 independent modules? 回答1: At the moment, it seems the only way is to create a master .pyx file that uses include directives to create a monolithic .C file. See project structure for wrapping many c++ classes in cython to a single shared object. 来源: https://stackoverflow.com/questions/8772966/how-can-i-merge-multiple-cython-pyx-files-into

How can I merge multiple Cython pyx files into a single linked library?

心不动则不痛 提交于 2020-02-10 10:55:22
问题 I have multiple .pyx files, is there a way to import them into a single pyx file and compile that file into a shared library, instead of having to compile 15 independent modules? 回答1: At the moment, it seems the only way is to create a master .pyx file that uses include directives to create a monolithic .C file. See project structure for wrapping many c++ classes in cython to a single shared object. 来源: https://stackoverflow.com/questions/8772966/how-can-i-merge-multiple-cython-pyx-files-into