Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
158092a9
Commit
158092a9
authored
May 23, 2014
by
Aidan Hobson Sayers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename cmath to not conflict with built-in module
parent
bdc95095
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
17 deletions
+17
-17
Demos/freeze/Makefile
Demos/freeze/Makefile
+1
-1
Demos/freeze/README.txt
Demos/freeze/README.txt
+13
-13
Demos/freeze/combinatorics.pyx
Demos/freeze/combinatorics.pyx
+3
-3
Demos/freeze/lcmath.pyx
Demos/freeze/lcmath.pyx
+0
-0
No files found.
Demos/freeze/Makefile
View file @
158092a9
...
@@ -18,7 +18,7 @@ LDLIBS = $(PY_LDLIBS)
...
@@ -18,7 +18,7 @@ LDLIBS = $(PY_LDLIBS)
TARGETS
=
nCr python
TARGETS
=
nCr python
# List of Cython source files, with main module first.
# List of Cython source files, with main module first.
CYTHON_SOURCE
=
combinatorics.pyx cmath.pyx
CYTHON_SOURCE
=
combinatorics.pyx
l
cmath.pyx
CYTHON_SECONDARY
=
$(CYTHON_SOURCE:.pyx=.c)
$(TARGETS:=.c)
CYTHON_SECONDARY
=
$(CYTHON_SOURCE:.pyx=.c)
$(TARGETS:=.c)
...
...
Demos/freeze/README.txt
View file @
158092a9
...
@@ -42,30 +42,30 @@ EXAMPLE
...
@@ -42,30 +42,30 @@ EXAMPLE
In the Demos/freeze directory, there exist two Cython modules:
In the Demos/freeze directory, there exist two Cython modules:
cmath.pyx
l
cmath.pyx
A module that interfaces with the -lm library.
A module that interfaces with the -lm library.
combinatorics.pyx
combinatorics.pyx
A module that implements n-choose-r using cmath.
A module that implements n-choose-r using
l
cmath.
Both modules have the Python idiom ``if __name__ == "__main__"``, which only
Both modules have the Python idiom ``if __name__ == "__main__"``, which only
execute if that module is the "main" module. If run as main, cmath prints the
execute if that module is the "main" module. If run as main,
l
cmath prints the
factorial of the argument, while combinatorics prints n-choose-r.
factorial of the argument, while combinatorics prints n-choose-r.
The provided Makefile creates an executable, *nCr*, using combinatorics as the
The provided Makefile creates an executable, *nCr*, using combinatorics as the
"main" module. It basically performs the following (ignoring the compiler
"main" module. It basically performs the following (ignoring the compiler
flags)::
flags)::
$ cython_freeze combinatorics cmath > nCr.c
$ cython_freeze combinatorics
l
cmath > nCr.c
$ cython combinatorics.pyx
$ cython combinatorics.pyx
$ cython cmath.pyx
$ cython
l
cmath.pyx
$ gcc -c nCr.c
$ gcc -c nCr.c
$ gcc -c combinatorics.c
$ gcc -c combinatorics.c
$ gcc -c cmath.c
$ gcc -c
l
cmath.c
$ gcc nCr.o combinatorics.o cmath.o -o nCr
$ gcc nCr.o combinatorics.o
l
cmath.o -o nCr
Because the combinatorics module was listed first, its ``__name__`` is set
Because the combinatorics module was listed first, its ``__name__`` is set
to ``"__main__"``, while
cmath's is set to ``"
cmath"``. The executable now
to ``"__main__"``, while
lcmath's is set to ``"l
cmath"``. The executable now
contains a Python interpreter and both Cython modules. ::
contains a Python interpreter and both Cython modules. ::
$ ./nCr
$ ./nCr
...
@@ -81,19 +81,19 @@ linked so you can profile it with gprof. To do this, add the ``--pymain``
...
@@ -81,19 +81,19 @@ linked so you can profile it with gprof. To do this, add the ``--pymain``
flag to ``cython_freeze``. In the Makefile, the *python* executable is built
flag to ``cython_freeze``. In the Makefile, the *python* executable is built
like this. ::
like this. ::
$ cython_freeze --pymain combinatorics cmath -o python.c
$ cython_freeze --pymain combinatorics
l
cmath -o python.c
$ gcc -c python.c
$ gcc -c python.c
$ gcc python.o combinatorics.o cmath.o -o python
$ gcc python.o combinatorics.o
l
cmath.o -o python
Now ``python`` is a normal Python interpreter, but the cmath and combinatorics
Now ``python`` is a normal Python interpreter, but the
l
cmath and combinatorics
modules will be built into the executable. ::
modules will be built into the executable. ::
$ ./python
$ ./python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Type "help", "copyright", "credits" or "license" for more information.
>>> import cmath
>>> import
l
cmath
>>> cmath.factorial(155)
>>>
l
cmath.factorial(155)
4.7891429014634364e+273
4.7891429014634364e+273
...
...
Demos/freeze/combinatorics.pyx
View file @
158092a9
import
cmath
import
l
cmath
def
nCr
(
n
,
r
):
def
nCr
(
n
,
r
):
"""Return the number of ways to choose r elements of a set of n."""
"""Return the number of ways to choose r elements of a set of n."""
return
cmath
.
exp
(
cmath
.
lfactorial
(
n
)
-
cmath
.
lfactorial
(
r
)
return
lcmath
.
exp
(
lcmath
.
lfactorial
(
n
)
-
l
cmath
.
lfactorial
(
r
)
-
cmath
.
lfactorial
(
n
-
r
)
)
-
l
cmath
.
lfactorial
(
n
-
r
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
sys
import
sys
...
...
Demos/freeze/cmath.pyx
→
Demos/freeze/
l
cmath.pyx
View file @
158092a9
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment