[Scipy-svn] r3148 - trunk/Lib/sparse/sparsetools
scipy-svn@scip...
scipy-svn@scip...
Sun Jul 8 01:32:54 CDT 2007
Author: wnbell
Date: 2007-07-08 01:32:39 -0500 (Sun, 08 Jul 2007)
New Revision: 3148
Modified:
trunk/Lib/sparse/sparsetools/numpy.i
trunk/Lib/sparse/sparsetools/sparsetools.i
trunk/Lib/sparse/sparsetools/sparsetools_wrap.cxx
Log:
moved a few lines from sparsetools.i to numpy.i
Modified: trunk/Lib/sparse/sparsetools/numpy.i
===================================================================
--- trunk/Lib/sparse/sparsetools/numpy.i 2007-07-07 16:38:51 UTC (rev 3147)
+++ trunk/Lib/sparse/sparsetools/numpy.i 2007-07-08 06:32:39 UTC (rev 3148)
@@ -259,6 +259,41 @@
}
/* End John Hunter translation (with modifications by Bill Spotz) */
+
+
+
+
+/*!
+ Appends @a what to @a where. On input, @a where need not to be a tuple, but on
+ return it always is.
+
+ @par Revision history:
+ - 17.02.2005, c
+*/
+PyObject *helper_appendToTuple( PyObject *where, PyObject *what ) {
+ PyObject *o2, *o3;
+
+ if ((!where) || (where == Py_None)) {
+ where = what;
+ } else {
+ if (!PyTuple_Check( where )) {
+ o2 = where;
+ where = PyTuple_New( 1 );
+ PyTuple_SetItem( where, 0, o2 );
+ }
+ o3 = PyTuple_New( 1 );
+ PyTuple_SetItem( o3, 0, what );
+ o2 = where;
+ where = PySequence_Concat( o2, o3 );
+ Py_DECREF( o2 );
+ Py_DECREF( o3 );
+ }
+ return where;
+}
+
+
+
+
%}
/* TYPEMAP_IN macros
@@ -564,3 +599,49 @@
TYPEMAP_ARGOUT2(PyObject, PyArray_OBJECT)
#undef TYPEMAP_ARGOUT2
+
+
+
+/*
+ * WNBELL additions
+ */
+
+
+/*
+ * Use STL vectors for ARGOUTs
+ */
+%define VEC_ARRAY_ARGOUT( ctype, atype )
+%typemap( in, numinputs=0 ) std::vector<ctype>* array_argout( std::vector<ctype>* tmp ) {
+ tmp = new std::vector<ctype>();
+ $1 = tmp;
+};
+%typemap( argout ) std::vector<ctype>* array_argout {
+ int length = ($1)->size();
+ PyObject *obj = PyArray_FromDims(1, &length, PyArray_##atype);
+ memcpy(PyArray_DATA(obj),&((*($1))[0]),sizeof(ctype)*length);
+ delete $1;
+ $result = helper_appendToTuple( $result, (PyObject *)obj );
+};
+%enddef
+
+
+
+/*
+ * make typechecks - used for overloading
+ */
+%include "typemaps.i"
+
+%define NPY_TYPECHECK( ctype, atype )
+%typemap(typecheck) ctype *, const ctype *, ctype [], const ctype []
+{
+ $1 = (is_array($input) && PyArray_CanCastSafely(PyArray_TYPE($input),PyArray_##atype)) ? 1 : 0;
+};
+%enddef
+
+NPY_TYPECHECK( int, INT )
+NPY_TYPECHECK( long, LONG )
+NPY_TYPECHECK( float, FLOAT )
+NPY_TYPECHECK( double, DOUBLE )
+NPY_TYPECHECK( npy_cfloat, CFLOAT )
+NPY_TYPECHECK( npy_cdouble, CDOUBLE )
+
Modified: trunk/Lib/sparse/sparsetools/sparsetools.i
===================================================================
--- trunk/Lib/sparse/sparsetools/sparsetools.i 2007-07-07 16:38:51 UTC (rev 3147)
+++ trunk/Lib/sparse/sparsetools/sparsetools.i 2007-07-08 06:32:39 UTC (rev 3148)
@@ -21,79 +21,8 @@
%}
-%{
-/*!
- Appends @a what to @a where. On input, @a where need not to be a tuple, but on
- return it always is.
- @par Revision history:
- - 17.02.2005, c
-*/
-PyObject *helper_appendToTuple( PyObject *where, PyObject *what ) {
- PyObject *o2, *o3;
-
- if ((!where) || (where == Py_None)) {
- where = what;
- } else {
- if (!PyTuple_Check( where )) {
- o2 = where;
- where = PyTuple_New( 1 );
- PyTuple_SetItem( where, 0, o2 );
- }
- o3 = PyTuple_New( 1 );
- PyTuple_SetItem( o3, 0, what );
- o2 = where;
- where = PySequence_Concat( o2, o3 );
- Py_DECREF( o2 );
- Py_DECREF( o3 );
- }
- return where;
-}
-%} //end inline code
-
-
-
-/*
- * Use STL vectors for ARGOUTs
- */
-%define VEC_ARRAY_ARGOUT( ctype, atype )
-%typemap( in, numinputs=0 ) std::vector<ctype>* array_argout( std::vector<ctype>* tmp ) {
- tmp = new std::vector<ctype>();
- $1 = tmp;
-};
-%typemap( argout ) std::vector<ctype>* array_argout {
- int length = ($1)->size();
- PyObject *obj = PyArray_FromDims(1, &length, PyArray_##atype);
- memcpy(PyArray_DATA(obj),&((*($1))[0]),sizeof(ctype)*length);
- delete $1;
- $result = helper_appendToTuple( $result, (PyObject *)obj );
-};
-%enddef
-
-
-
/*
- * make typechecks - used for overloading
- */
-%include "typemaps.i"
-
-%define NPY_TYPECHECK( ctype, atype )
-%typemap(typecheck) ctype *, const ctype *, ctype [], const ctype []
-{
- $1 = (is_array($input) && PyArray_CanCastSafely(PyArray_TYPE($input),PyArray_##atype)) ? 1 : 0;
-};
-%enddef
-
-NPY_TYPECHECK( int, INT )
-NPY_TYPECHECK( long, LONG )
-NPY_TYPECHECK( float, FLOAT )
-NPY_TYPECHECK( double, DOUBLE )
-NPY_TYPECHECK( npy_cfloat, CFLOAT )
-NPY_TYPECHECK( npy_cdouble, CDOUBLE )
-
-
-
- /*
* IN types
*/
%define I_IN_ARRAY1( ctype )
@@ -300,7 +229,7 @@
INSTANTIATE_ALL(densetocsr)
/*
- * Ensure sorted CSR/CSC indices.
+ * Sort CSR/CSC indices.
*/
INSTANTIATE_ALL(sort_csr_indices)
INSTANTIATE_ALL(sort_csc_indices)
Modified: trunk/Lib/sparse/sparsetools/sparsetools_wrap.cxx
===================================================================
--- trunk/Lib/sparse/sparsetools/sparsetools_wrap.cxx 2007-07-07 16:38:51 UTC (rev 3147)
+++ trunk/Lib/sparse/sparsetools/sparsetools_wrap.cxx 2007-07-08 06:32:39 UTC (rev 3148)
@@ -1726,6 +1726,8 @@
+
+
/*!
Appends @a what to @a where. On input, @a where need not to be a tuple, but on
return it always is.
@@ -1755,6 +1757,10 @@
}
+
+
+
+
#include <limits.h>
More information about the Scipy-svn
mailing list