{"id":216649,"date":"2020-11-24T13:17:29","date_gmt":"2020-11-24T05:17:29","guid":{"rendered":"http:\/\/4563.org\/?p=216649"},"modified":"2020-11-24T13:17:29","modified_gmt":"2020-11-24T05:17:29","slug":"cython-%e4%b8%ad%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8-c-%e7%9a%84%e6%a8%a1%e6%9d%bf%e5%ba%93%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=216649","title":{"rendered":"Cython \u4e2d\u5982\u4f55\u8c03\u7528 c++ \u7684\u6a21\u677f\u5e93\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Cython \u4e2d\u5982\u4f55\u8c03\u7528 c++ \u7684\u6a21\u677f\u5e93\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5982\u9898\uff0c\u6700\u8fd1\u6709\u4e00\u4e2a\u5927\u91cf\u7528\u5230 python \u4e2d\u5b57\u5178\u548c\u5217\u8868\u5bfb\u5740\u7279\u6027\u7684\u79d1\u5b66\u8ba1\u7b97\u51fd\u6570\uff0c\u521d\u6b65\u4f30\u7b97\u4e86\u4e00\u4e0b\u5faa\u73af\u6b21\u6570\u5728\u5341\u4ebf\u7ea7\uff0c\u7eaf python \u8dd1\u7684\u975e\u5e38\u6162\uff0c\u6362\u5230 pypy \u4ee5\u540e\u52a0\u901f\u5feb\u4e86\u4e09\u500d\u5de6\u53f3\uff0c\u4f46\u8fd8\u662f\u8981\u7b49\u4e00\u5206\u949f\u624d\u80fd\u51fa\u7ed3\u679c\u3002<\/p>\n<p>\u4e8e\u662f\u60f3\u5230\u80fd\u4e0d\u80fd\u7528 cython \u52a0\u901f\uff0c\u6211\u4ee5\u524d cython \u90fd\u662f\u4e86\u89e3\u76ae\u6bdb\uff0c\u53ea\u8dd1\u8fc7 helloworld \u3002 \u4eca\u5929\u521d\u6b65\u7814\u7a76\u4e86\u4e00\u4e0b\u611f\u89c9\u53ef\u884c\uff0c\u6309\u6211\u7684\u60f3\u6cd5\uff0c\u56e0\u4e3a\u8981\u5927\u91cf\u4f7f\u7528 python \u5217\u8868\uff0c\u5176\u52a0\u901f\u65b9\u5f0f\u5927\u6982\u5c31\u662f\u8981\u6620\u5c04\u5230 cpp \u7684 vector \u4e86\u5427<\/p>\n<p>\u5728\u5f15\u5165 stl \u65f6\u9047\u5230\u4e86\u65e0\u6cd5\u5f15\u5165\u7684\u95ee\u9898\uff0c\u6709\u6ca1\u6709\u5e26\u4f6c\u6307\u70b9\u4e00\u4e0b\u54ea\u9519\u4e86<\/p>\n<pre><code># \u6309\u6211\u7684\u7406\u89e3\u5b89\u88c5 cython \u65f6\u5e94\u8be5\u5df2\u7ecf\u81ea\u5e26\u8f6c\u6362\u597d\u7684 stl \u6587\u4ef6\u4e86\u5427 # \u4ee5\u4e0b\u8fd9\u6bb5 C \u5e93\u7684\u5f15\u5165\u662f\u53ef\u4ee5\u6b63\u5e38\u7f16\u8bd1\u7684 import cython from libc.stdlib cimport atoi from libc.string cimport memset  # \u4f46\u662f\u8fd9\u91cc\u5f15\u5165 CPP \u7684\u8bdd\u5374\u4f1a\u62a5\u9519 from libcpp.vector cimport vector <\/code><\/pre>\n<p>\u53e6\u5916\u6c42\u95ee\u4e00\u4e0b\u5173\u4e8e python \u5b57\u5178\u7684\u6620\u5c04\u65b9\u5f0f\uff0c\u5728 cython \u4e2d\u5e94\u8be5\u600e\u4e48\u5904\u7406\u3002\u6bd4\u5982\u73b0\u5728\u6709\u4e00\u4e2a\u957f\u5ea6\u4e0d\u786e\u5b9a\u7684\u5b57\u5178 <code>name_dict<\/code>\uff0c\u4f30\u6d4b\u957f\u5ea6\u5728\u4e00\u767e\u4e07\u5de6\u53f3\uff0c \u6211\u9700\u8981\u5927\u91cf\u4f7f\u7528\u8bf8\u5982 <code>name_dict['tom']<\/code> , <code>name_dict['sam']<\/code> \u8fd9\u7c7b\u5b57\u7b26\u4e32\u5bfb\u5740\u6765\u641c\u5bfb\u5177\u4f53\u5bf9\u8c61\uff0c\u5bf9\u8c61\u5185\u5bb9\u4e0d\u590d\u6742\uff0c\u53ef\u4ee5\u6620\u5c04\u4e3a\u7ed3\u6784\u4f53\uff0c\u4f46\u662f\u8fd9\u4e2a\u5b57\u5178\u8be5\u600e\u4e48\u641e\uff1f<\/p>\n<p>\u8c22\u8c22\u5927\u5bb6<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>25<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4402133\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Tony042 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8003\u8651\u4e0b pybind11 \u6765\u8fdb\u884c python \u548c C++\u4ea4\u4e92\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402134\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5e94\u8be5\u662f cimport cython \u5427\uff0c\u62a5\u9519\u4e5f\u4e0d\u8bf4\u4ec0\u4e48\u9519\u8fd9\u600e\u4e48 debug                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402135\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u8bb0\u5f97\u76f4\u63a5\u7528 Python \u539f\u751f\u7684 dict \u662f\u6bd4\u8f83\u5feb\u7684\uff0c\u7528 cpp \u7684 map \u4e0d\u4e00\u5b9a\u5feb\uff0c\u4e5f\u53ef\u80fd\u662f\u6211\u54ea\u91cc\u6ca1\u5f04\u5bf9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402136\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lovestudykid \u5144\uff0c\u4e00\u5171\u5c31\u56db\u884c import\uff0c\u8fd9\u8fd8\u7528\u518d\u8d34\u4e00\u4e0b\u62a5\u9519\u62a5\u4e86\u4ec0\u4e48\u4e48\u3002\u3002\u3002\u518d\u8bf4 cython \u548b\u770b\u62a5\u9519\u4fe1\u606f\u554a\uff0c\u53c8\u6ca1\u6709\u89e3\u91ca\u5668\uff0c\u6211\u90fd\u662f\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u770b\u62a5\u9519\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402137\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Tony042 \u662f\u8fd9\u6837\uff0c\u73b0\u5728\u60c5\u51b5\u662f\u6709\u4e00\u6bb5 python \u4ee3\u7801\uff0c\u9884\u7814\u4e00\u4e0b cython \u5982\u679c\u5408\u9002\u7684\u8bdd\u51c6\u5907\u6539\u6210 cython\uff0c\u770b\u4e86\u4e00\u4e0b\u4f60\u8bf4\u7684\u8fd9\u4e2a\u9879\u76ee\u4f3c\u4e4e\u662f\u8bbe\u8ba1\u7528\u6765\u5728\u5df2\u7ecf\u6709 cpp \u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u63a5\u5165 py \u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402138\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black \u56e0\u4e3a code \u5e76\u6ca1\u6709\u95ee\u9898\uff0c\u7f16\u8bd1\u5668\u7684\u62a5\u9519\u4e5f\u662f\u62a5\u9519\u3002\u4f60\u6ca1\u8bbe\u7f6e language = c++?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402139\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lovestudykid \u611f\u8c22\uff0c\u662f c++\u58f0\u660e\u7684\u95ee\u9898\uff0c\u4e00\u8d34\u6761\u91cc\u5199\u4e86\u3002\u53e6\u5916\u51fa\u73b0\u4e86\u65b0\u7684\u95ee\u9898\uff0c\u5e26\u4f6c\u770b\u770b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402140\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black \u4f60\u53ef\u4ee5\u8bd5\u8bd5 long long                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402141\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             BTW, \u8fd9\u662f c \u548c gcc \u73af\u5883\u7684\u95ee\u9898\uff0c\u8ddf cython \u6ca1\u5173\u7cfb\u3002\u5728\u6211\u8fd9\u91cc\u6ca1\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402142\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lovestudykid OK\uff0c\u53ef\u80fd\u662f 64 \u4f4d python \u7528\u4e86 32 \u4f4d\u7f16\u8bd1\u5668\u95ee\u9898\uff0c\u5927\u6982\u5427\u3002\u5e94\u8be5\u600e\u4e48\u4fee\u6b63\u5462\uff1f cython \u901a\u8fc7 pip \u88c5\u7684\uff0c\u6211\u4e0d\u77e5\u9053\u4ed6\u7528\u4ec0\u4e48\u65b9\u6cd5\u8c03\u7528\u7684\u7f16\u8bd1\u5668                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402143\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black \u76f4\u63a5\u4ece\u4f60 PATH \u8c03\u7528\u7684\uff0c\u4e5f\u53ef\u4ee5\u5728 setup.py \u5236\u5b9a\uff0c\u770b cython \u6587\u6863                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402144\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuboying <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3b\u80fd\u4e0d\u80fd\u987a\u5e26\u6d4b\u6d4b numba \u5e93\u7684\u6548\u7387\uff1f<\/p>\n<p>\u4e2a\u4eba\u611f\u89c9\u7eaf\u8ba1\u7b97\u7528\u4e86 jit \u6280\u672f\u4ee5\u540e\u5e94\u8be5\u4e0d\u4f1a\u6709\u592a\u5927\u7684\u5dee\u522b\u4e86\u5427\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402145\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lovestudykid \u5e26\u4f6c\u6307\u70b9\u4e00\u4e0b\u600e\u4e48\u8c03\uff0c\u6211\u5728\u6587\u6863\u91cc\u641c\u7d22 compiler \u76f8\u5173\u7684\u5185\u5bb9\u6ca1\u770b\u89c1\u80fd\u8bbe\u7f6e\u7684\u9009\u9879\uff0c\u4e3b\u8981\u662f\u8fd9\u7bc7 https:\/\/cython.readthedocs.io\/en\/latest\/src\/userguide\/source_files_and_compilation.html                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402146\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xuboying numba \u6709\u4e9b\u9ed1\u9b54\u6cd5\uff0c\u4e0d\u592a\u559c\u6b22\u7528\uff0c\u4ee5\u524d\u6d4b\u8bd5\u8fc7\u4e00\u4e9b\u573a\u666f\u6bd4\u7eaf C \u8bed\u8a00\u8fd0\u884c\u8fd8\u5feb\uff0c\u4e0d\u660e\u539f\u56e0\u3002\u6211\u8fd9\u4e2a\u73af\u5883\u91cc jit \u548c C \u8fd8\u662f\u6709\u6bd4\u8f83\u5927\u901f\u5ea6\u5dee\u8ddd\u7684\uff0cpypy \u611f\u89c9\u5728\u4e00\u4e9b\u7ed3\u6784\u7684\u5b9e\u73b0\u4e0a\u6548\u7387\u8ddf\u539f\u751f\u6ca1\u5565\u533a\u522b\uff0c\u6bd4\u5982\u8fd9\u79cd\u5927\u5b57\u5178\u5bfb\u5740\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402147\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\u6309\u7167\u4e0a\u8001\u54e5\u8bf4\u7684\u7528 long long \u7c7b\u578b\u4ee5\u540e\u786e\u5b9e\u7a0b\u5e8f\u80fd\u6b63\u5e38\u8fd0\u884c\u4e86\u3002\u6211\u6d4b\u4e86\u4e00\u4e0b\uff0ccython \u91cc\u662f\u6709 sizeof \u8fd9\u4e2a bif \u7684\uff0c\u6211\u6d4b void *p \u662f 8bit\uff0c\u800c long \u662f 4bit\uff0c\u6574\u4e2a\u4eba\u90fd\u662f\u61f5\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402148\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u904d\u5730\u91c7\u5751\u554a\u3002<\/p>\n<p>\u53c8\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u6bd4\u5982 python \u5f53\u4e2d\uff0c\u5728\u5faa\u73af\u8fc7\u7a0b\u4e2d\u65b0\u5efa\u5bf9\u8c61\u662f\u4e2a\u5f88\u6b63\u5e38\u7684\u64cd\u4f5c\uff0c\u6bd4\u5982\u4e0b\u9762\u8fd9\u6837<\/p>\n<p>class A:<\/p>\n<p> pass <\/p>\n<p>lst = list()<\/p>\n<p>for i in range(10):<\/p>\n<p> lst.append(A())<\/p>\n<p>\u4f46\u662f\u5728 cython \u91cc\u5e76\u4e0d\u80fd\u5728\u5faa\u73af\u5185\u90e8\u8fdb\u884c cdef\uff0c\u6240\u4ee5\u73b0\u5728\u53c8\u5361\u4e86\uff0c\u4e0d\u4f1a\u5faa\u73af\u65b0\u5efa\u5bf9\u8c61\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402149\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mckelvin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8981\u7528\u5199 Python \u7684\u601d\u60f3\u53bb\u5199 C++, \u5148\u60f3\u529e\u6cd5\u5b9a\u4e49\u597d\u80f6\u6c34\u5c42\u7684\u63a5\u53e3\u53c2\u6570\u7c7b\u578b\uff0c\u4e00\u822c\u4e0d\u5efa\u8bae vector \u76f4\u63a5\u5bf9\u5e94 list. \u56e0\u4e3a list \u91cc\u7684\u5185\u5b58\u65e0\u6cd5\u76f4\u63a5\u53d8\u6210 vector \u53ef\u7528\u7684\u5185\u5b58\uff0c\u4e0d\u5f97\u4e0d\u6709\u5185\u5b58\u62f7\u8d1d\u53d1\u751f\u3002\u5efa\u8bae\u7528\u6734\u7d20\u4e00\u4e9b\u7684\u6570\u636e\u7ed3\u6784\uff0c\u6bd4\u5982 double* . \u6570\u503c\u8ba1\u7b97\u5927\u90e8\u5206\u60c5\u51b5\u4e0b numpy \u548c scipy \u5df2\u7ecf\u591f\u7528\u4e86\uff0c\u4ed6\u4eec\u5df2\u7ecf\u5c01\u88c5\u597d\u4e86\u4e00\u4e9b\u5e95\u5c42 C\/C++\u5b9e\u73b0\u7684\u529f\u80fd\u3002<\/p>\n<p>\u6570\u503c\u4e0d\u5bf9\u8fd9\u4e2a\u95ee\u9898\u5927\u6982\u7387\u662f\u6ea2\u51fa\u4e86\u3002\u6709\u4e9b 64 \u4f4d\u64cd\u4f5c\u7cfb\u7edf\u91cc long \u662f 32bit \u7684\u3002\u5efa\u8bae\u7528 int64_t \u8fd9\u6837\u7684\u7c7b\u578b\uff0c\u8fd9\u6837\u660e\u786e\u5b83\u662f 64bit \u957f\u5ea6\u3002<\/p>\n<p>&#8220;`<br \/>In [16]: (1 + 1000000) \/ 2 * 1000000<br \/>Out[16]: 500000000000<\/p>\n<p>In [17]: 1 &lt;&lt; 32<br \/>Out[17]: 4294967296<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402150\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qbqbqbqb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black long \u8fd9\u4e2a\u786e\u5b9e\u662f\u4e2a\u5751\uff0c64 \u4f4d Linux \u91cc\u662f 8 \u5b57\u8282\u7684\uff0c\u4f46 64 \u4f4d Windows \u91cc\u662f 4 \u5b57\u8282\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402151\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuboying <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black #14 \u6211\u4ee5\u524d\u9047\u5230\u8fc7 numba \u7684\u5751\u662f\u4f9d\u8d56\u4e86\u4ed6\u7684\u7c7b\u578b\u63a8\u6d4b\u5bfc\u81f4\u6267\u884c\u4e0d\u7a33\u5b9a\uff0c\u4e0d\u77e5\u9053\u8fd9\u4e2a\u662f\u4e0d\u662f\u4f60\u63d0\u5230\u7684\u201c\u9ed1\u9b54\u6cd5\u201d\uff0c\u540e\u6765\u6211\u53bb\u5b98\u7f51\u7814\u7a76\u4e86\u4ed6\u7684\u5f62\u53c2\u7c7b\u578b\u58f0\u660e\u4ee5\u540e\uff0c\u95ee\u9898\u5c31\u5b8c\u5168\u89e3\u51b3\u4e86\u3002\u5982\u679c\u8fd9\u4e9b\u4f60\u5df2\u7ecf\u77e5\u9053\u4e86\uff0c\u5c31\u5ffd\u7565\u6211\u7684\u7559\u8a00\u597d\u4e86\u3002btw\uff0c\u6bd5\u7adf\u6211\u6ca1\u6709\u770b\u8fc7\u6c47\u7f16\u4ee3\u7801\uff0c\u4e86\u89e3\u7a0b\u5ea6\u5c31\u5230\u8fd9\u4e00\u5c42\u4e86\u3002\u5728\u6211\u7684\u56fe\u5f62\u8ba1\u7b97\u7684\u5e94\u7528\u91cc\u6548\u679c\u8fd8\u662f\u76f8\u5f53\u8ba9\u6211\u6ee1\u610f\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402152\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wevsty <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             cpp \u7684 std::vector \u662f\u6a21\u677f\uff0c\u6a21\u677f\u672c\u8eab\u53ea\u662f\u4e2a\u6e90\u7801\u4e0d\u4f7f\u7528\u7684\u8bdd\u672c\u8eab\u5e76\u6ca1\u6709\u5b9e\u4f8b\uff0c\u4f60\u5f53\u7136\u4e0d\u53ef\u80fd\u7528 python \u76f4\u63a5\u8c03\u6a21\u677f\u7684\u6e90\u7801\u3002<br \/>\u60f3\u8981\u7528 std::vector \u7684\u8bdd\uff0c\u53ea\u80fd\u4f60\u81ea\u5df1\u7528 C \u5c01\u88c5\u4e00\u5957\u51fd\u6570\u51fa\u6765\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402153\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @qbqbqbqb #18L\uff1a\u7528 int32_t, int64_t \u8fd9\u79cd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402154\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovestudykid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black \u5927\u6982\u8fd9\u6837\uff0cCC=gcc-10 CXX=g++-10 python setup.py build_ext &#8211;inplace\uff0c\u4e5f\u53ef\u4ee5\u5728 script \u91cc\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u6211\u7528\u8fd9\u4e2a\u662f\u56e0\u4e3a Mac \u4e0a\u9ed8\u8ba4\u8c03\u7528 clang \u6709\u5751                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402155\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mckelvin <br \/>@wevsty <br \/>\u611f\u8c22\u5927\u4f6c\u56de\u590d\uff0c\u6211\u73b0\u5728\u7684\u9700\u6c42\u5f88\u666e\u901a\u5c31\u662f\u6709\u4e00\u5f20\u4ece\u6570\u636e\u5e93\u5bfc\u8fc7\u6765\u7684\u4e8c\u7ef4\u8868\uff0c\u8fd9\u79cd\u8868\u7ed3\u6784\u4e00\u822c\u5728 python \u91cc\u662f\u505a\u6210\u8868\u5957\u8868\uff0c\u6216\u8005\u8868\u5957\u5b57\u5178\uff0c\u50cf\u8fd9\u6837 [[],[],&#8230;] \/ [{},{},&#8230;] \u3002\u5904\u7406\u8fc7\u7a0b\u653e\u5230 cpp \u7684\u8bdd\u786e\u5b9e\u8f6c\u6362\u5f00\u9500\u86ee\u9ad8\u7684\uff0c\u6240\u4ee5\u6211\u7406\u89e3\u5e94\u8be5\u4e0d\u80fd\u8fdb\u884c\u4e00\u4e9b\u6bd4\u8f83\u7ec6\u7c92\u5ea6\u7684 c \u52a0\u901f\uff0c\u6700\u597d\u662f\u6574\u4e2a\u6d41\u7a0b\u5b8c\u5168\u8dd1 c\uff0c\u8fd9\u6837\u53ea\u7ecf\u8fc7\u4e00\u6b21\u5bfc\u5165\u5bfc\u51fa\u8f6c\u6362\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u7528 vector \u7684\u8bdd\u600e\u4e48\u5904\u7406\u8fd9\u79cd\u7ed3\u6784\u5462\uff1f\u6211\u611f\u89c9 vector \u8fd8\u662f\u633a\u5408\u9002\u7684\uff0c\u56e0\u4e3a push \u6dfb\u52a0\u5f88\u8f7b\u677e\uff0c\u4e0d\u7528\u8003\u8651\u5185\u5b58\u95ee\u9898\u3002\u6211\u73b0\u5728\u9047\u5230\u7684\u95ee\u9898\u662f\uff0c\u6211\u4e0d\u4f1a\u52a8\u6001\u5411 vector \u91cc\u6dfb\u52a0\u5bf9\u8c61\uff0c\u6bd4\u5982\u6211\u5199\u5728 for \u5faa\u73af\u4e2d cdef \u4e00\u4e2a\u5bf9\u8c61\u7136\u540e push \u8fdb vector \u91cc\uff0c\u8fd9\u79cd\u8bed\u6cd5\u662f\u4e0d\u5141\u8bb8\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402156\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u4e86\u4e00\u4e0b\uff0c\u4f3c\u4e4e\u5728\u5b50 block \u91cc\u65b0\u5efa\u5bf9\u8c61\u5e76\u4e0d\u9700\u8981 cdef \u6216\u8005 new \u4e4b\u7c7b\u7684\uff08 new \u5728 cython \u91cc\u4f3c\u4e4e\u6ca1\u6709\u8fd9\u4e2a\u8bed\u6cd5\uff09\uff0c\u76f4\u63a5 object()\u5c31\u80fd\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u4e86\u3002\u4e0d\u8fc7\u6211\u5b9a\u4e49\u7ed3\u6784\u4f53\u540e\u770b\u4e86\u4e00\u4e0b cython \u751f\u6210\u7684\u5206\u6790\uff0c\u4f3c\u4e4e\u4fee\u6539\u7ed3\u6784\u4f53\u5f53\u4e2d\u7684\u503c\u4ecd\u7136\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u6821\u6b63\uff0c\u4f3c\u4e4e\u8fd9\u90e8\u5206\u662f\u8d70\u7684 python\uff0c\u5e76\u4e0d\u80fd\u8d77\u5230\u52a0\u901f\u4f5c\u7528\u3002<\/p>\n<p>\u4ee3\u7801\u5730\u5740<\/p>\n<p>https:\/\/paste.ubuntu.com\/p\/s4wk9QfqPB\/<\/p>\n<p>\u5404\u4f4d\u5927\u4f6c\u6307\u70b9\u4e00\u4e0b\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff0c\u8fd9\u4e48\u505a\u5f00\u5206\u6790\u6a21\u5f0f\u770b\u7684\u8bdd\u611f\u89c9\u8fd8\u662f\u4e0d\u592a\u5bf9                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4402157\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/paste.ubuntu.com\/p\/cBgVXqWQJ8\/<\/p>\n<p>\u4fee\u6b63\uff0c\u4e0a\u4e00\u4ee3\u7801\u6709\u5c0f\u9519\u8bef                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Cython \u4e2d\u5982\u4f55\u8c03\u7528 c++ &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/216649"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216649"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/216649\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216649"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}