@@ -783,7 +783,8 @@ At each step, we'll time and look at the output from::
783
783
AGC Example
784
784
-----------
785
785
786
- Another useful example is in:
786
+ Another useful example of doing something useful, and using a numpy
787
+ array is in:
787
788
788
789
Examples/week-08-extensions/AGC_example
789
790
@@ -793,7 +794,8 @@ It turns out that you can use some advanced numpy tricks to get pretty
793
794
good performancew with this filter, but you can't get full-on speed
794
795
without some compiled code.
795
796
796
- This example uses:
797
+
798
+ This example uses all of:
797
799
* Pure Cython
798
800
* C called from Cython
799
801
* f2py and Fortran
@@ -879,6 +881,8 @@ created by SWIG
879
881
Creating a wrapper:
880
882
-------------------
881
883
884
+ (``Examples/week-08-extensions/swig ``)
885
+
882
886
Create ``add.i ``::
883
887
884
888
%module add
@@ -900,11 +904,23 @@ Create ``setup.py``::
900
904
901
905
.. nextslide ::
902
906
903
- And built it::
907
+ And build it::
904
908
905
909
python setup.py build_ext --inplace
906
910
907
- then run the code::
911
+ NOTE: distutils (and thus setuptools) "knows" about SWIG, so it does the
912
+ swig step for you when you give it a \* .i file.
913
+
914
+ Notice what gets created:
915
+
916
+ * an ``add_wrap.c `` file -- the wrapper code.
917
+ * an ``add.py `` file -- python code that calls the C function
918
+ * an ``_add.so `` (or ``_add.pyd ``) file -- the compiled extension
919
+
920
+ .. nextslide ::
921
+
922
+
923
+ You can then run the code::
908
924
909
925
python -c 'import add; print add.add(4,5)'
910
926
@@ -913,7 +929,7 @@ http://www.swig.org/Doc2.0/SWIGDocumentation.html#Introduction_nn5
913
929
Installing SWIG
914
930
----------------
915
931
916
- On the SWIG download page, there is a source tarball for *nix, and
932
+ On the SWIG download page, there is a source tarball for \ * nix, and
917
933
Windows binaries:
918
934
919
935
http://www.swig.org/download.html
0 commit comments