diff options
author | wfspotz@sandia.gov <wfspotz@sandia.gov@localhost> | 2007-03-23 17:36:16 +0000 |
---|---|---|
committer | wfspotz@sandia.gov <wfspotz@sandia.gov@localhost> | 2007-03-23 17:36:16 +0000 |
commit | 32a2519c0b028ada876a3fe33ca598c18e65d05c (patch) | |
tree | 68684b7bad8d20df51e6aaaa44e3bfbdf4b67164 /numpy/doc/swig | |
parent | 25526d1a26f4b7ac245ecedd16c82cfd7d67f741 (diff) | |
download | numpy-32a2519c0b028ada876a3fe33ca598c18e65d05c.tar.gz |
Added '#ifdef SWIGPYTHON' protection
Diffstat (limited to 'numpy/doc/swig')
-rw-r--r-- | numpy/doc/swig/numpy.i | 45 | ||||
-rw-r--r-- | numpy/doc/swig/numpy_swig.html | 23 | ||||
-rw-r--r-- | numpy/doc/swig/numpy_swig.pdf | bin | 119182 -> 115406 bytes | |||
-rw-r--r-- | numpy/doc/swig/numpy_swig.txt | 22 |
4 files changed, 38 insertions, 52 deletions
diff --git a/numpy/doc/swig/numpy.i b/numpy/doc/swig/numpy.i index 9ffb3698a..f6e72c424 100644 --- a/numpy/doc/swig/numpy.i +++ b/numpy/doc/swig/numpy.i @@ -1,4 +1,6 @@ /* -*- C -*- (not really, but good for syntax highlighting) */ +#ifdef SWIGPYTHON + %{ #ifndef SWIG_FILE_WITH_INIT # define NO_IMPORT_ARRAY @@ -73,7 +75,7 @@ char* pytype_string(PyObject* py_obj) { /* Given a NumPy typecode, return a string describing the type. */ char* typecode_string(int typecode) { - static char* type_names[24] = {"bool", "byte", "unsigned byte", + static char* type_names[25] = {"bool", "byte", "unsigned byte", "short", "unsigned short", "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long", @@ -81,12 +83,13 @@ char* typecode_string(int typecode) { "complex float", "complex double", "complex long double", "object", "string", "unicode", "void", "ntypes", - "notype", "char"}; - return type_names[typecode]; + "notype", "char", "unknown"}; + return typecode < 24 ? type_names[typecode] : type_names[24]; } -/* Make sure input has correct numeric type. Allow character and byte - * to match. Also allow int and long to match. +/* Make sure input has correct numpy type. Allow character and byte + * to match. Also allow int and long to match. This is deprecated. + * You should use PyArray_EquivTypenums() instead. */ int type_match(int actual_type, int desired_type) { return PyArray_EquivTypenums(actual_type, desired_type); @@ -99,12 +102,12 @@ int type_match(int actual_type, int desired_type) { PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode) { PyArrayObject* ary = NULL; if (is_array(input) && (typecode == NPY_NOTYPE || - type_match(array_type(input), typecode))) { + PyArray_EquivTypenums(array_type(input), typecode))) { ary = (PyArrayObject*) input; } else if is_array(input) { char* desired_type = typecode_string(typecode); - char* actual_type = typecode_string(array_type(input)); + char* actual_type = typecode_string(array_type(input)); PyErr_Format(PyExc_TypeError, "Array of type '%s' required. Array of type '%s' given", desired_type, actual_type); @@ -112,9 +115,9 @@ PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode) { } else { char * desired_type = typecode_string(typecode); - char * actual_type = pytype_string(input); + char * actual_type = pytype_string(input); PyErr_Format(PyExc_TypeError, - "Array of type '%s' required. A %s was given", + "Array of type '%s' required. A '%s' was given", desired_type, actual_type); ary = NULL; } @@ -122,7 +125,7 @@ PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode) { } /* Convert the given PyObject to a NumPy array with the given - * typecode. On Success, return a valid PyArrayObject* with the + * typecode. On success, return a valid PyArrayObject* with the * correct type. On failure, the python error string will be set and * the routine returns NULL. */ @@ -130,7 +133,8 @@ PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode, int* is_new_object) { PyArrayObject* ary = NULL; PyObject* py_obj; - if (is_array(input) && (typecode == NPY_NOTYPE || type_match(array_type(input),typecode))) { + if (is_array(input) && (typecode == NPY_NOTYPE || + PyArray_EquivTypenums(array_type(input),typecode))) { ary = (PyArrayObject*) input; *is_new_object = 0; } @@ -196,7 +200,8 @@ PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input, int require_contiguous(PyArrayObject* ary) { int contiguous = 1; if (!array_is_contiguous(ary)) { - PyErr_SetString(PyExc_TypeError, "Array must be contiguous. A discontiguous array was given"); + PyErr_SetString(PyExc_TypeError, + "Array must be contiguous. A non-contiguous array was given"); contiguous = 0; } return contiguous; @@ -365,7 +370,7 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { /* Typemap suite for (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) */ %typemap(in) (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) - (PyArrayObject* array=NULL, int is_new_object=0) { + (PyArrayObject* array=NULL, int is_new_object=0) { array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object); npy_intp size[1] = {-1}; if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail; @@ -379,7 +384,7 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { /* Typemap suite for (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) */ %typemap(in) (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) - (PyArrayObject* array=NULL, int is_new_object=0) { + (PyArrayObject* array=NULL, int is_new_object=0) { array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object); npy_intp size[2] = {-1,-1}; if (!array || !require_dimensions(array, 2) || !require_size(array, size, 1)) SWIG_fail; @@ -403,7 +408,8 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) */ -%typemap(in) (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) (PyArrayObject* temp=NULL) { +%typemap(in) (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) + (PyArrayObject* temp=NULL) { temp = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!temp || !require_contiguous(temp)) SWIG_fail; $1 = (DATA_TYPE*) temp->data; @@ -462,7 +468,7 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) */ %typemap(in) (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) - (PyArrayObject* array=NULL, int is_new_object=0) { + (PyArrayObject* array=NULL, int is_new_object=0) { array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object); npy_intp size[1] = {-1}; if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail; @@ -476,7 +482,7 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) */ %typemap(in) (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) - (PyArrayObject* array=NULL, int is_new_object=0) { + (PyArrayObject* array=NULL, int is_new_object=0) { array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object); npy_intp size[2] = {-1,-1}; if (!array || !require_dimensions(array, 2) || !require_size(array, size, 1)) SWIG_fail; @@ -500,7 +506,8 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) */ -%typemap(in) (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) (PyArrayObject* temp=NULL) { +%typemap(in) (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) + (PyArrayObject* temp=NULL) { temp = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!temp || !require_contiguous(temp)) SWIG_fail; $1 = (DIM_TYPE) temp->dimensions[0]; @@ -551,3 +558,5 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) { */ /*%numpy_typemaps(complex long double, NPY_CLONGDOUBLE) */ + +#endif /* SWIGPYTHON */ diff --git a/numpy/doc/swig/numpy_swig.html b/numpy/doc/swig/numpy_swig.html index 5a8b0fe74..b8d6f9d9c 100644 --- a/numpy/doc/swig/numpy_swig.html +++ b/numpy/doc/swig/numpy_swig.html @@ -614,7 +614,8 @@ can be cast to a <tt class="docutils literal"><span class="pre">PyArrayObject*</ <dd>Given a <a class="reference" href="http://numpy.scipy.org">NumPy</a> integer typecode, return a string describing the type.</dd> <dt><strong>int type_match(int actual_type, int desired_type)</strong></dt> <dd>Make sure input has correct <a class="reference" href="http://numpy.scipy.org">NumPy</a> type. Allow character and -byte to match. Also allow int and long to match.</dd> +byte to match. Also allow int and long to match. This is +deprecated . You should use <tt class="docutils literal"><span class="pre">PyArray_EquivTypenums()</span></tt> instead.</dd> <dt><strong>PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode)</strong></dt> <dd>Given a <tt class="docutils literal"><span class="pre">PyObject*</span></tt>, cast it to a <tt class="docutils literal"><span class="pre">PyArrayObject*</span></tt> if legal. If not, set the python error string appropriately and return @@ -651,19 +652,6 @@ python error string and return 0.</dd> <dd>Require the given <tt class="docutils literal"><span class="pre">PyArrayObject*</span></tt> to have a specified shape. If the array has the specified shape, return 1. Otherwise, set the python error string and return 0.</dd> -<dt><strong>static PyArrayObject *contiguous_typed_array(PyObject *obj, int typecode, int expectnd, int *expectdims)</strong></dt> -<dd>This function tries to create a contiguous <a class="reference" href="http://numpy.scipy.org">NumPy</a> array of type -typecode from an arbitrary python object <tt class="docutils literal"><span class="pre">obj</span></tt>. This should -work for any sequence object. The argument <tt class="docutils literal"><span class="pre">expectnd</span></tt> is the -expected number of dimensions, ignored if <= 0. The argument -<tt class="docutils literal"><span class="pre">expectdims</span></tt> is an array of expected dimensions, ignored if <= -0. This routine raises a <tt class="docutils literal"><span class="pre">ValueError</span></tt> exception if the -underlying <tt class="docutils literal"><span class="pre">PyArray_ContiguousFromObject</span></tt> routine fails, if the -array has a bad shape, if the extent of a given dimension doesn't -match the specified extent. If <tt class="docutils literal"><span class="pre">obj</span></tt> is a contiguous -<tt class="docutils literal"><span class="pre">PyArrayObject*</span></tt> then a reference is returned; if <tt class="docutils literal"><span class="pre">obj</span></tt> is a -python sequence, then a new <tt class="docutils literal"><span class="pre">PyArrayObject*</span></tt> is created and -returned.</dd> </dl> </blockquote> </div> @@ -671,8 +659,9 @@ returned.</dd> <div class="section"> <h1><a class="toc-backref" href="#id12" id="beyond-the-provided-typemaps" name="beyond-the-provided-typemaps">Beyond the Provided Typemaps</a></h1> <p>There are many C or C++ array/<a class="reference" href="http://numpy.scipy.org">NumPy</a> array situations not covered by -a simple <tt class="docutils literal"><span class="pre">%include</span> <span class="pre">"numpy.i"</span></tt>. Nevertheless, <tt class="docutils literal"><span class="pre">numpy.i</span></tt> may still -be helpful when you encounter them.</p> +a simple <tt class="docutils literal"><span class="pre">%include</span> <span class="pre">"numpy.i"</span></tt> and subsequent <tt class="docutils literal"><span class="pre">%apply</span></tt> directives. +Nevertheless, <tt class="docutils literal"><span class="pre">numpy.i</span></tt> may still be helpful when you encounter +them.</p> <blockquote> <ul> <li><p class="first">In some situations, it is possible that you could use the @@ -719,7 +708,7 @@ result possible.</p> </div> <div class="footer"> <hr class="footer" /> -Generated on: 2007-03-19 04:09 UTC. +Generated on: 2007-03-23 12:04 UTC. Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. </div> diff --git a/numpy/doc/swig/numpy_swig.pdf b/numpy/doc/swig/numpy_swig.pdf Binary files differindex 97822c4d1..9167b5979 100644 --- a/numpy/doc/swig/numpy_swig.pdf +++ b/numpy/doc/swig/numpy_swig.pdf diff --git a/numpy/doc/swig/numpy_swig.txt b/numpy/doc/swig/numpy_swig.txt index d3001da99..207f94e3d 100644 --- a/numpy/doc/swig/numpy_swig.txt +++ b/numpy/doc/swig/numpy_swig.txt @@ -304,7 +304,8 @@ Routines **int type_match(int actual_type, int desired_type)** Make sure input has correct `NumPy`_ type. Allow character and - byte to match. Also allow int and long to match. + byte to match. Also allow int and long to match. This is + deprecated . You should use ``PyArray_EquivTypenums()`` instead. **PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode)** @@ -359,26 +360,13 @@ Routines the python error string and return 0. - **static PyArrayObject *contiguous_typed_array(PyObject *obj, int typecode, int expectnd, int *expectdims)** - This function tries to create a contiguous `NumPy`_ array of type - typecode from an arbitrary python object ``obj``. This should - work for any sequence object. The argument ``expectnd`` is the - expected number of dimensions, ignored if <= 0. The argument - ``expectdims`` is an array of expected dimensions, ignored if <= - 0. This routine raises a ``ValueError`` exception if the - underlying ``PyArray_ContiguousFromObject`` routine fails, if the - array has a bad shape, if the extent of a given dimension doesn't - match the specified extent. If ``obj`` is a contiguous - ``PyArrayObject*`` then a reference is returned; if ``obj`` is a - python sequence, then a new ``PyArrayObject*`` is created and - returned. - Beyond the Provided Typemaps ============================ There are many C or C++ array/`NumPy`_ array situations not covered by -a simple ``%include "numpy.i"``. Nevertheless, ``numpy.i`` may still -be helpful when you encounter them. +a simple ``%include "numpy.i"`` and subsequent ``%apply`` directives. +Nevertheless, ``numpy.i`` may still be helpful when you encounter +them. * In some situations, it is possible that you could use the ``%numpy_templates`` macro to implement typemaps for your own |