summaryrefslogtreecommitdiff
path: root/doc/swig/test/Farray.i
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2008-08-23 23:17:23 +0000
committerStefan van der Walt <stefan@sun.ac.za>2008-08-23 23:17:23 +0000
commit5c86844c34674e3d580ac2cd12ef171e18130b13 (patch)
tree2fdf1150706c07c7e193eb7483ce58a5074e5774 /doc/swig/test/Farray.i
parent376d483d31c4c5427510cf3a8c69fc795aef63aa (diff)
downloadnumpy-5c86844c34674e3d580ac2cd12ef171e18130b13.tar.gz
Move documentation outside of source tree. Remove `doc` import from __init__.
Diffstat (limited to 'doc/swig/test/Farray.i')
-rw-r--r--doc/swig/test/Farray.i73
1 files changed, 73 insertions, 0 deletions
diff --git a/doc/swig/test/Farray.i b/doc/swig/test/Farray.i
new file mode 100644
index 000000000..25f6cd025
--- /dev/null
+++ b/doc/swig/test/Farray.i
@@ -0,0 +1,73 @@
+// -*- c++ -*-
+
+%module Farray
+
+%{
+#define SWIG_FILE_WITH_INIT
+#include "Farray.h"
+%}
+
+// Get the NumPy typemaps
+%include "../numpy.i"
+
+ // Get the STL typemaps
+%include "stl.i"
+
+// Handle standard exceptions
+%include "exception.i"
+%exception
+{
+ try
+ {
+ $action
+ }
+ catch (const std::invalid_argument& e)
+ {
+ SWIG_exception(SWIG_ValueError, e.what());
+ }
+ catch (const std::out_of_range& e)
+ {
+ SWIG_exception(SWIG_IndexError, e.what());
+ }
+}
+%init %{
+ import_array();
+%}
+
+// Global ignores
+%ignore *::operator=;
+%ignore *::operator();
+
+// Apply the 2D NumPy typemaps
+%apply (int* DIM1 , int* DIM2 , long** ARGOUTVIEW_FARRAY2)
+ {(int* nrows, int* ncols, long** data )};
+
+// Farray support
+%include "Farray.h"
+%extend Farray
+{
+ PyObject * __setitem__(PyObject* index, long v)
+ {
+ int i, j;
+ if (!PyArg_ParseTuple(index, "ii:Farray___setitem__",&i,&j)) return NULL;
+ self->operator()(i,j) = v;
+ return Py_BuildValue("");
+ }
+
+ PyObject * __getitem__(PyObject * index)
+ {
+ int i, j;
+ if (!PyArg_ParseTuple(index, "ii:Farray___getitem__",&i,&j)) return NULL;
+ return SWIG_From_long(self->operator()(i,j));
+ }
+
+ int __len__()
+ {
+ return self->nrows() * self->ncols();
+ }
+
+ std::string __str__()
+ {
+ return self->asString();
+ }
+}