Revision: 4676
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4676&view=rev
Author:   jdh2358
Date:     2007-12-08 09:00:28 -0800 (Sat, 08 Dec 2007)

Log Message:
-----------
added primes demo

Added Paths:
-----------
    trunk/py4science/examples/pyrex/primes/
    trunk/py4science/examples/pyrex/primes/Makefile
    trunk/py4science/examples/pyrex/primes/primes.pyx
    trunk/py4science/examples/pyrex/primes/pyprimes.py
    trunk/py4science/examples/pyrex/primes/run_primes.py
    trunk/py4science/examples/pyrex/primes/setup.py

Added: trunk/py4science/examples/pyrex/primes/Makefile
===================================================================
--- trunk/py4science/examples/pyrex/primes/Makefile                             
(rev 0)
+++ trunk/py4science/examples/pyrex/primes/Makefile     2007-12-08 17:00:28 UTC 
(rev 4676)
@@ -0,0 +1,11 @@
+all:
+       python setup.py build_ext --inplace
+
+test:  all
+       python run_primes.py 20
+
+clean:
+       @echo Cleaning Primes
+       @rm -f *.c *.o *.so *~ *.pyc
+       @rm -rf build
+

Added: trunk/py4science/examples/pyrex/primes/primes.pyx
===================================================================
--- trunk/py4science/examples/pyrex/primes/primes.pyx                           
(rev 0)
+++ trunk/py4science/examples/pyrex/primes/primes.pyx   2007-12-08 17:00:28 UTC 
(rev 4676)
@@ -0,0 +1,18 @@
+def primes(int kmax):
+    cdef int n, k, i
+    cdef int p[1000]
+    result = []
+    if kmax > 1000:
+        kmax = 1000
+    k = 0
+    n = 2
+    while k < kmax:
+        i = 0
+        while i < k and n % p[i] <> 0:
+            i = i + 1
+        if i == k:
+            p[k] = n
+            k = k + 1
+            result.append(n)
+        n = n + 1
+    return result

Added: trunk/py4science/examples/pyrex/primes/pyprimes.py
===================================================================
--- trunk/py4science/examples/pyrex/primes/pyprimes.py                          
(rev 0)
+++ trunk/py4science/examples/pyrex/primes/pyprimes.py  2007-12-08 17:00:28 UTC 
(rev 4676)
@@ -0,0 +1,13 @@
+def primes(kmax):
+    p = []
+    k = 0
+    n = 2
+    while k < kmax:
+        i = 0
+        while i < k and n % p[i] <> 0:
+            i = i + 1
+        if i == k:
+            p.append(n)
+            k = k + 1
+        n = n + 1
+    return p

Added: trunk/py4science/examples/pyrex/primes/run_primes.py
===================================================================
--- trunk/py4science/examples/pyrex/primes/run_primes.py                        
        (rev 0)
+++ trunk/py4science/examples/pyrex/primes/run_primes.py        2007-12-08 
17:00:28 UTC (rev 4676)
@@ -0,0 +1,4 @@
+import sys
+from primes import primes
+n = 1000
+print primes(n)

Added: trunk/py4science/examples/pyrex/primes/setup.py
===================================================================
--- trunk/py4science/examples/pyrex/primes/setup.py                             
(rev 0)
+++ trunk/py4science/examples/pyrex/primes/setup.py     2007-12-08 17:00:28 UTC 
(rev 4676)
@@ -0,0 +1,12 @@
+from distutils.core import setup
+#from distutils.extension import Extension
+from Pyrex.Distutils.extension import Extension
+from Pyrex.Distutils import build_ext
+
+setup(
+  name = 'Demos',
+  ext_modules=[
+    Extension("primes",       ["primes.pyx"]),
+    ],
+  cmdclass = {'build_ext': build_ext}
+)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to