Cython C++ Example - Gists · GitHub
Có thể bạn quan tâm
Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }}
cournape/gist:1077528 Created July 12, 2011 07:00 Show Gist options
Copy link
Instantly share code, notes, and snippets.
- Download ZIP
- Star (11) You must be signed in to star a gist
- Fork (2) You must be signed in to fork a gist
- Embed Select an option
- Embed Embed this gist in your website.
- Share Copy sharable link for this gist.
- Clone via HTTPS Clone using the web URL.
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/cournape/1077528.js"></script> - Save cournape/1077528 to your computer and use it in GitHub Desktop.
- Embed Embed this gist in your website.
- Share Copy sharable link for this gist.
- Clone via HTTPS Clone using the web URL.
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/cournape/1077528.js"></script> Save cournape/1077528 to your computer and use it in GitHub Desktop. Download ZIP cython c++ example Raw gistfile1.txt This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters| # rectangle.pyx |
| cdef extern from "Rectangle.h" namespace "shapes": |
| cdef cppclass Rectangle: |
| Rectangle(int, int, int, int) |
| int x0, y0, x1, y1 |
| int getLength() |
| int getHeight() |
| int getArea() |
| void move(int, int) |
| cdef class PyRectangle: |
| cdef Rectangle *thisptr # hold a C++ instance which we're wrapping |
| def __cinit__(self, int x0, int y0, int x1, int y1): |
| self.thisptr = new Rectangle(x0, y0, x1, y1) |
| def __dealloc__(self): |
| del self.thisptr |
| def getLength(self): |
| return self.thisptr.getLength() |
| def getHeight(self): |
| return self.thisptr.getHeight() |
| def getArea(self): |
| return self.thisptr.getArea() |
| def move(self, dx, dy): |
| self.thisptr.move(dx, dy) |
| # Rectangle.h |
| namespace shapes { |
| class Rectangle { |
| public: |
| int x0, y0, x1, y1; |
| Rectangle(int x0, int y0, int x1, int y1); |
| ~Rectangle(); |
| int getLength(); |
| int getHeight(); |
| int getArea(); |
| void move(int dx, int dy); |
| }; |
| } |
| # Rectangle.cpp |
| #include "Rectangle.h" |
| using namespace shapes; |
| Rectangle::Rectangle(int X0, int Y0, int X1, int Y1) |
| { |
| x0 = X0; |
| y0 = Y0; |
| x1 = X1; |
| y1 = Y1; |
| } |
| Rectangle::~Rectangle() |
| { |
| } |
| int Rectangle::getLength() |
| { |
| return (x1 - x0); |
| } |
| int Rectangle::getHeight() |
| { |
| return (y1 - y0); |
| } |
| int Rectangle::getArea() |
| { |
| return (x1 - x0) * (y1 - y0); |
| } |
| void Rectangle::move(int dx, int dy) |
| { |
| x0 += dx; |
| y0 += dy; |
| x1 += dx; |
| y1 += dy; |
| } |
| # setup.py |
| from distutils.core import setup |
| from distutils.extension import Extension |
| from Cython.Distutils import build_ext |
| setup(ext_modules=[Extension("rectangle", ["rectangle.pyx", "Rectangle.cpp"], language="c++",)], |
| cmdclass = {'build_ext': build_ext}) |
etale-cohomology commented Sep 29, 2016
1. How do I build this (without installing)? Is it python setup.py build or python setup.py build_ext? (Both work for me.) 2. How do I call this from a python script? (In the same directory.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.Từ khóa » Cython C++ Github
-
Cython/wrapping_t At Master - GitHub
-
[ENH] C++ Variant · Issue #4677 · Cython/cython - GitHub
-
Cython · GitHub Topics
-
Cython C++ Example - Gists · GitHub
-
Cython 0.16 C++ Demo - Gists · GitHub
-
A Few Quick Tutorials On Using C++ Function In Python Code With Cython
-
Cython/cython: The Most Widely Used Python To C Compiler - GitHub
-
Cython · GitHub Topics
-
Cython-wrapper · GitHub Topics
-
Molpopgen/cython_mcpp: Glue Layer Between Cython And C++11 ...
-
Add C++ "to_string()" Function To Declarations. - GitHub
-
David-cortes/cycereal: C++ Cereal Headers As An ... - GitHub
-
Cython-wrapper · GitHub Topics
-
Allow Sharing C++ Classes Across Modules · Issue #4561 - GitHub