summaryrefslogtreecommitdiffstats
path: root/debian/pyrex/pyrex-0.9.9/Demos
diff options
context:
space:
mode:
Diffstat (limited to 'debian/pyrex/pyrex-0.9.9/Demos')
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/Makefile15
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/Makefile.nodistutils21
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/Setup.py14
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile10
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile.nodistutils19
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/README.txt1
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/Setup.py11
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/cheese.pyx13
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.c21
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.h1
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/callback/run_cheese.py7
l---------debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile1
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc35
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc.static1
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.unix30
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/embed/README1
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/embed/embedded.pyx5
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/embed/main.c9
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/numeric_demo.pyx39
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/primes.pyx18
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/pyprimes.py13
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/run_numeric_demo.py5
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/run_primes.py7
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/run_spam.py8
-rw-r--r--debian/pyrex/pyrex-0.9.9/Demos/spam.pyx22
25 files changed, 327 insertions, 0 deletions
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/Makefile b/debian/pyrex/pyrex-0.9.9/Demos/Makefile
new file mode 100644
index 00000000..e70687f4
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/Makefile
@@ -0,0 +1,15 @@
+all:
+ python Setup.py build_ext --inplace
+
+test: all
+ python run_primes.py 20
+ python run_numeric_demo.py
+ python run_spam.py
+ cd callback; $(MAKE) test
+
+clean:
+ @echo Cleaning Demos
+ @rm -f *.c *.o *.so *~ core
+ @rm -rf build
+ @cd callback; $(MAKE) clean
+ @cd embed; $(MAKE) clean
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/Makefile.nodistutils b/debian/pyrex/pyrex-0.9.9/Demos/Makefile.nodistutils
new file mode 100644
index 00000000..d648f849
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/Makefile.nodistutils
@@ -0,0 +1,21 @@
+PYHOME = $(HOME)/pkg/python/version
+PYINCLUDE = \
+ -I$(PYHOME)/include/python2.2 \
+ -I$(PYHOME)/$(ARCH)/include/python2.2
+
+%.c: %.pyx
+ ../bin/pyrexc $<
+
+%.o: %.c
+ gcc -c -fPIC $(PYINCLUDE) $<
+
+%.so: %.o
+ gcc -shared $< -lm -o $@
+
+all: primes.so spam.so numeric_demo.so
+
+clean:
+ @echo Cleaning Demos
+ @rm -f *.c *.o *.so *~ core core.*
+ @cd callback; $(MAKE) clean
+ @cd embed; $(MAKE) clean
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/Setup.py b/debian/pyrex/pyrex-0.9.9/Demos/Setup.py
new file mode 100644
index 00000000..e220d81b
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/Setup.py
@@ -0,0 +1,14 @@
+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"]),
+ Extension("spam", ["spam.pyx"]),
+ Extension("numeric_demo", ["numeric_demo.pyx"]),
+ ],
+ cmdclass = {'build_ext': build_ext}
+)
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile b/debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile
new file mode 100644
index 00000000..890bc808
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile
@@ -0,0 +1,10 @@
+all:
+ python Setup.py build_ext --inplace
+
+test: all
+ python run_cheese.py
+
+clean:
+ @echo Cleaning Demos/callback
+ @rm -f cheese.c *.o *.so *~ core
+ @rm -rf build
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile.nodistutils b/debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile.nodistutils
new file mode 100644
index 00000000..012c1a86
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/Makefile.nodistutils
@@ -0,0 +1,19 @@
+PYHOME = $(HOME)/pkg/python/version
+PYINCLUDE = \
+ -I$(PYHOME)/include/python2.2 \
+ -I$(PYHOME)/$(ARCH)/include/python2.2
+
+%.c: %.pyx
+ ../../bin/pyrexc $<
+
+%.o: %.c
+ gcc -c -fPIC $(PYINCLUDE) $<
+
+%.so: %.o
+ gcc -shared $< -lm -o $@
+
+all: cheese.so
+
+clean:
+ @echo Cleaning Demos/callback
+ @rm -f *.c *.o *.so *~ core core.*
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/README.txt b/debian/pyrex/pyrex-0.9.9/Demos/callback/README.txt
new file mode 100644
index 00000000..fa3b871c
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/README.txt
@@ -0,0 +1 @@
+This example demonstrates how you can wrap a C API that has a callback interface, so that you can pass Python functions to it as callbacks. The files cheesefinder.h and cheesefinder.c represent the C library to be wrapped. The file cheese.pyx is the Pyrex module which wraps it. The file run_cheese.py demonstrates how to call the wrapper. \ No newline at end of file
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/Setup.py b/debian/pyrex/pyrex-0.9.9/Demos/callback/Setup.py
new file mode 100644
index 00000000..5e48206a
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/Setup.py
@@ -0,0 +1,11 @@
+from distutils.core import setup
+from distutils.extension import Extension
+from Pyrex.Distutils import build_ext
+
+setup(
+ name = 'callback',
+ ext_modules=[
+ Extension("cheese", ["cheese.pyx", "cheesefinder.c"]),
+ ],
+ cmdclass = {'build_ext': build_ext}
+)
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/cheese.pyx b/debian/pyrex/pyrex-0.9.9/Demos/callback/cheese.pyx
new file mode 100644
index 00000000..db0fc082
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/cheese.pyx
@@ -0,0 +1,13 @@
+#
+# Pyrex wrapper for the cheesefinder API
+#
+
+cdef extern from "cheesefinder.h":
+ ctypedef void (*cheesefunc)(char *name, void *user_data)
+ void find_cheeses(cheesefunc user_func, void *user_data)
+
+def find(f):
+ find_cheeses(callback, <void*>f)
+
+cdef void callback(char *name, void *f):
+ (<object>f)(name)
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.c b/debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.c
new file mode 100644
index 00000000..ab41853b
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.c
@@ -0,0 +1,21 @@
+/*
+ * An example of a C API that provides a callback mechanism.
+ */
+
+#include "cheesefinder.h"
+
+static char *cheeses[] = {
+ "cheddar",
+ "camembert",
+ "that runny one",
+ 0
+};
+
+void find_cheeses(cheesefunc user_func, void *user_data) {
+ char **p = cheeses;
+ while (*p) {
+ user_func(*p, user_data);
+ ++p;
+ }
+}
+
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.h b/debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.h
new file mode 100644
index 00000000..3c31bdc0
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/cheesefinder.h
@@ -0,0 +1 @@
+typedef void (*cheesefunc)(char *name, void *user_data); void find_cheeses(cheesefunc user_func, void *user_data); \ No newline at end of file
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/callback/run_cheese.py b/debian/pyrex/pyrex-0.9.9/Demos/callback/run_cheese.py
new file mode 100644
index 00000000..65fd431b
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/callback/run_cheese.py
@@ -0,0 +1,7 @@
+import cheese
+
+def report_cheese(name):
+ print "Found cheese:", name
+
+cheese.find(report_cheese)
+
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile
new file mode 120000
index 00000000..a89ef208
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile
@@ -0,0 +1 @@
+Makefile.unix \ No newline at end of file
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc
new file mode 100644
index 00000000..37114c73
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc
@@ -0,0 +1,35 @@
+# Makefile for Microsoft C Compiler, building a DLL
+PYVERSION = 2.2
+PYHOME = \Python$(PYVERSION:.=)
+PYINCLUDE = -I$(PYHOME)\include
+PYLIB = /LIBPATH:$(PYHOME)\libs
+
+CFLAGS = $(PYINCLUDE) /Ox /W3 /GX -nologo
+.SUFFIXES: .exe .dll .obj .c .cpp .pyx
+
+.pyx.c:
+ $(PYHOME)\Python.exe ../../pyrexc.py $<
+
+all: main.exe
+
+clean:
+ del /Q/F *.obj embedded.h embedded.c main.exe embedded.dll embedded.lib embedded.exp
+
+# When linking the DLL we must explicitly list all of the exports
+# There doesn't seem to be an easy way to get DL_EXPORT to have the correct definition
+# to do the export for us without breaking the importing of symbols from the core
+# python library.
+embedded.dll: embedded.obj
+ link /nologo /DLL /INCREMENTAL:NO $(PYLIB) $** /IMPLIB:$*.lib /DEF:<< /OUT:$*.dll
+EXPORTS initembedded
+EXPORTS spam
+<<
+
+main.exe: main.obj embedded.lib
+ link /nologo $** $(PYLIB) /OUT:main.exe
+
+embedded.h: embedded.c
+main.obj: embedded.h
+embedded.obj: embedded.c
+ $(CC) /MD $(CFLAGS) -c $**
+embedded.lib: embedded.dll
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc.static b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc.static
new file mode 100644
index 00000000..14e1080c
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.msc.static
@@ -0,0 +1 @@
+# Makefile for Microsoft compiler statically linking PYVERSION = 2.2 PYHOME = \Python$(PYVERSION:.=) PYINCLUDE = -I$(PYHOME)\include PYLIB = /LIBPATH:$(PYHOME)\libs python22.lib CFLAGS = $(PYINCLUDE) /Ox /W3 /GX -nologo .SUFFIXES: .exe .dll .obj .c .cpp .pyx .pyx.c: $(PYHOME)\Python.exe ../../pyrexc.py $< all: main.exe clean: -del /Q/F *.obj embedded.h embedded.c main.exe main.exe: main.obj embedded.obj link /nologo $** $(PYLIB) /OUT:main.exe embedded.h: embedded.c main.obj: embedded.h \ No newline at end of file
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.unix b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.unix
new file mode 100644
index 00000000..c8c7dbeb
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/Makefile.unix
@@ -0,0 +1,30 @@
+PYVERSION = 2.2
+PYHOME = $(HOME)/pkg/python/$(PYVERSION)
+PYARCH = $(PYHOME)/$(ARCH)
+PYINCLUDE = \
+ -I$(PYHOME)/include/python$(PYVERSION) \
+ -I$(PYARCH)/include/python$(PYVERSION)
+PYLIB = -L$(PYARCH)/lib/python$(PYVERSION)/config \
+ -lpython$(PYVERSION) \
+ -ldl -lpthread -lutil -lm
+
+%.c: %.pyx
+ ../../bin/pyrexc $<
+
+%.o: %.c
+ gcc -c -fPIC $(PYINCLUDE) $<
+
+#%.so: %.o
+# gcc -shared $< -lm -o $@
+
+all: main
+
+main: main.o embedded.o
+ gcc main.o embedded.o $(PYLIB) -o main
+
+clean:
+ @echo Cleaning Demos/embed
+ @rm -f *~ *.o *.so core core.* embedded.h embedded.c main
+
+embedded.h: embedded.c
+main.o: embedded.h
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/README b/debian/pyrex/pyrex-0.9.9/Demos/embed/README
new file mode 100644
index 00000000..55283ac3
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/README
@@ -0,0 +1 @@
+This example demonstrates how Pyrex-generated code can be called directly from a main program written in C. In this example, the module's initialisation function (called "initembedded", since the module is called "embedded") is called explicitly. This is necessary because the module is not being imported using the normal Python import mechanism. The Windows makefiles were contributed by Duncan Booth <Duncan.Booth@SuttonCourtenay.org.uk>. \ No newline at end of file
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/embedded.pyx b/debian/pyrex/pyrex-0.9.9/Demos/embed/embedded.pyx
new file mode 100644
index 00000000..90d62f67
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/embedded.pyx
@@ -0,0 +1,5 @@
+cdef public void spam():
+ praise()
+
+def praise():
+ print "Spam, glorious spam!"
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/embed/main.c b/debian/pyrex/pyrex-0.9.9/Demos/embed/main.c
new file mode 100644
index 00000000..3e089abc
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/embed/main.c
@@ -0,0 +1,9 @@
+#include "Python.h"
+#include "embedded.h"
+
+int main(int argc, char *argv) {
+ Py_Initialize();
+ initembedded();
+ spam();
+ Py_Finalize();
+}
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/numeric_demo.pyx b/debian/pyrex/pyrex-0.9.9/Demos/numeric_demo.pyx
new file mode 100644
index 00000000..3a20fd90
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/numeric_demo.pyx
@@ -0,0 +1,39 @@
+#
+# This example demonstrates how to access the internals
+# of a Numeric array object.
+#
+
+cdef extern from "Numeric/arrayobject.h":
+
+ struct PyArray_Descr:
+ int type_num, elsize
+ char type
+
+ ctypedef class Numeric.ArrayType [object PyArrayObject]:
+ cdef char *data
+ cdef int nd
+ cdef int *dimensions, *strides
+ cdef object base
+ cdef PyArray_Descr *descr
+ cdef int flags
+
+def print_2d_array(ArrayType a):
+ print "Type:", chr(a.descr.type)
+ if chr(a.descr.type) <> "f":
+ raise TypeError("Float array required")
+ if a.nd <> 2:
+ raise ValueError("2 dimensional array required")
+ cdef int nrows, ncols
+ cdef float *elems, x
+ nrows = a.dimensions[0]
+ ncols = a.dimensions[1]
+ elems = <float *>a.data
+ hyphen = "-"
+ divider = ("+" + 10 * hyphen) * ncols + "+"
+ print divider
+ for row in range(nrows):
+ for col in range(ncols):
+ x = elems[row * ncols + col]
+ print "| %8f" % x,
+ print "|"
+ print divider
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/primes.pyx b/debian/pyrex/pyrex-0.9.9/Demos/primes.pyx
new file mode 100644
index 00000000..dfbaae48
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/primes.pyx
@@ -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
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/pyprimes.py b/debian/pyrex/pyrex-0.9.9/Demos/pyprimes.py
new file mode 100644
index 00000000..edcce852
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/pyprimes.py
@@ -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
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/run_numeric_demo.py b/debian/pyrex/pyrex-0.9.9/Demos/run_numeric_demo.py
new file mode 100644
index 00000000..803442d5
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/run_numeric_demo.py
@@ -0,0 +1,5 @@
+import Numeric
+import numeric_demo
+
+a = Numeric.array([[1.0, 3.5, 8.4], [2.3, 6.6, 4.1]], "f")
+numeric_demo.print_2d_array(a)
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/run_primes.py b/debian/pyrex/pyrex-0.9.9/Demos/run_primes.py
new file mode 100644
index 00000000..487767d4
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/run_primes.py
@@ -0,0 +1,7 @@
+import sys
+from primes import primes
+if len(sys.argv) >= 2:
+ n = int(sys.argv[1])
+else:
+ n = 1000
+print primes(n)
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/run_spam.py b/debian/pyrex/pyrex-0.9.9/Demos/run_spam.py
new file mode 100644
index 00000000..e1c1e155
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/run_spam.py
@@ -0,0 +1,8 @@
+from spam import Spam
+
+s = Spam()
+print "Created:", s
+s.set_amount(42)
+print "Amount =", s.get_amount()
+s.describe()
+s = None
diff --git a/debian/pyrex/pyrex-0.9.9/Demos/spam.pyx b/debian/pyrex/pyrex-0.9.9/Demos/spam.pyx
new file mode 100644
index 00000000..ab773378
--- /dev/null
+++ b/debian/pyrex/pyrex-0.9.9/Demos/spam.pyx
@@ -0,0 +1,22 @@
+#
+# Example of an extension type.
+#
+
+cdef class Spam:
+
+ cdef int amount
+
+ def __cinit__(self):
+ self.amount = 0
+
+ def __dealloc__(self):
+ print self.amount, "tons of spam is history."
+
+ def get_amount(self):
+ return self.amount
+
+ def set_amount(self, new_amount):
+ self.amount = new_amount
+
+ def describe(self):
+ print self.amount, "tons of spam!"