changeset 101:0c19ed1ce349

Remove Numeric array support. Use numpy exclusively.
author David Grundberg <individ@acc.umu.se>
date Mon, 09 Apr 2012 21:22:32 +0200
parents ff70627aa203
children 4e7307dd52a2
files ChangeLog NEWS arrayobjectdefs.h configure.ac m4/ax_python_numeric.m4 octave_to_python.cc package/pytave.py pytave.cc python_to_octave.cc
diffstat 9 files changed, 47 insertions(+), 163 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 09 20:05:48 2012 +0200
+++ b/ChangeLog	Mon Apr 09 21:22:32 2012 +0200
@@ -1,3 +1,14 @@
+2012-04-09  David Grundberg  <individ@acc.umu.se>
+
+	* configure.ac: Remove ability to select Numeric array library.
+	* octave_to_python.cc: Assume we use numpy, remove ifdefs for
+	numeric.
+	* python_to_octave.cc: Assume we use numpy.
+	* ax_python_numpy.m4: Remove file.
+	* arrayobjectdefs.h: Remove numeric specific code.
+	* pytave.cc (pytave::get_module_name): Remove function.
+	* package/pytave.py: Use only numpy.
+
 2012-04-09  David Grundberg  <individ@acc.umu.se>
 
 	* octave_to_python.cc, python_to_octave.cc, pytave.cc: Undef
--- a/NEWS	Mon Apr 09 20:05:48 2012 +0200
+++ b/NEWS	Mon Apr 09 21:22:32 2012 +0200
@@ -1,5 +1,12 @@
 Version 0.1.1-bzr 
 
+2012-04-09
+
+* Removed Numeric array support.  The Numeric array Python library is
+  deprecated.  Pytave has used numpy and its extensions since several
+  years ago and it was time to reduce the effort to support both
+  libraries.
+
 2009-05-25
 
 * Added functionality for explicit manipulation of variables.
--- a/arrayobjectdefs.h	Mon Apr 09 20:05:48 2012 +0200
+++ b/arrayobjectdefs.h	Mon Apr 09 21:22:32 2012 +0200
@@ -29,16 +29,11 @@
 #endif
 #define PY_ARRAY_UNIQUE_SYMBOL pytave_array_symbol
 #include <Python.h>
-#ifdef HAVE_NUMPY
+/* We use the oldnumeric.h header files because pytave was originally written
+   for the Numeric array library, which has since then been deprecated.  We use
+   the NumPy compability headers. */
 #include <numpy/oldnumeric.h>
 #include <numpy/old_defines.h>
-// Avoid deprecation warnings from NumPy
-#undef PyArray_FromDims 
-#define PyArray_FromDims PyArray_SimpleNew
-#else
-#include <Numeric/arrayobject.h>
-typedef int npy_intp;
-#endif
 
 /* Emacs
  * Local Variables:
--- a/configure.ac	Mon Apr 09 20:05:48 2012 +0200
+++ b/configure.ac	Mon Apr 09 21:22:32 2012 +0200
@@ -6,23 +6,29 @@
 
 AC_ARG_WITH(numpy,
 	      [AS_HELP_STRING([--with-numpy],
-			      [use NumPy module (experimental)
+			      [use NumPy module (you have no choice)
 			      @<:@default=yes@:>@])],
 			      [pytave_enable_numpy="$withval"],
 			      [pytave_enable_numpy=yes])
 
 AC_ARG_WITH(numeric,
 	      [AS_HELP_STRING([--with-numeric],
-			      [use legacy Numeric module. NumPy must be disabled.
+			      [Pytave used to be able to use Numeric
+			      module, support has since then
+			      been removed.
 			      @<:@default=no@:>@])],
 			      [pytave_enable_numeric="$withval"],
 			      [pytave_enable_numeric=no])
 
 # Check for bad arguments.
-AS_IF(test "x$pytave_enable_numpy" = "xyes" -a "x$pytave_enable_numeric" = "xyes" -o dnl
-"x$pytave_enable_numpy" = "xno" -a "x$pytave_enable_numeric" = "xno", 
+AS_IF(test "x$pytave_enable_numeric" = "xyes",
 [
-	AC_ERROR([NumPy or Numeric: select one.])
+	AC_ERROR([numeric: This library is no longer supported.])
+])
+
+AS_IF(test "x$pytave_enable_numpy" != "xyes",
+[
+	AC_ERROR([numpy: This library is required.])
 ])
 
 # Some important programs.
@@ -47,28 +53,13 @@
 # Pick a Python library to use
 AX_PYTHON_DEVEL([], [], [addmissing([Python development files])])
 
-# Select Python matrix interface, prefer numpy.
-AS_IF(test "x$pytave_enable_numpy" = "xno",
+# Look for numpy headers
+AX_PYTHON_NUMPY(
 [
-	pytave_matrix_interface="numeric"
+    AC_DEFINE([HAVE_NUMPY], 1, [Define if using NumPy])
 ],
 [
-	pytave_matrix_interface="numpy"
-])
-
-# Look for selected matrix interface
-AS_IF(test "$pytave_matrix_interface" = "numpy",
-[
-   AX_PYTHON_NUMPY(
-   [
-       AC_DEFINE([HAVE_NUMPY], 1, [Define if using NumPy])
-   ],
-   [
-       addmissing([NumPy development files])
-   ])
-],
-[
-   AX_PYTHON_NUMERIC([], [addmissing([Numeric development files])])
+    addmissing([NumPy development files])
 ])
 
 # Look for boost::python
@@ -167,7 +158,6 @@
   Python boost ....... $BOOST_PYTHON_LIB
 
 Features
-  matrix interface ... $pytave_matrix_interface
   uselocale .......... $pytave_have_uselocale
 
 ========================================================================])
--- a/m4/ax_python_numeric.m4	Mon Apr 09 20:05:48 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-# ===========================================================================
-#
-# ===========================================================================
-#
-# SYNOPSIS
-#
-#   AX_PYTHON_NUMERIC([ACTION_IF_FOUND], [ACTION_IF_NOT_FOUND])
-#
-# DESCRIPTION
-#
-#
-# LAST MODIFICATION
-#
-#   2009-08-24
-#
-# COPYING
-#
-#   Copyright (c) 2009 David Grundberg
-#
-#   This program is free software; you can redistribute it and/or modify it
-#   under the terms of the GNU General Public License as published by the
-#   Free Software Foundation; either version 2 of the License, or (at your
-#   option) any later version.
-#
-#   This program is distributed in the hope that it will be useful, but
-#   WITHOUT ANY WARRANTY; without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-#   Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License along
-#   with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-#   As a special exception, the respective Autoconf Macro's copyright owner
-#   gives unlimited permission to copy, distribute and modify the configure
-#   scripts that are the output of Autoconf when processing the Macro. You
-#   need not follow the terms of the GNU General Public License when using
-#   or distributing such scripts, even though portions of the text of the
-#   Macro appear in them. The GNU General Public License (GPL) does govern
-#   all other use of the material that constitutes the Autoconf Macro.
-#
-#   This special exception to the GPL applies to versions of the Autoconf
-#   Macro released by the Autoconf Macro Archive. When you make and
-#   distribute a modified version of the Autoconf Macro, you may extend this
-#   special exception to the GPL to apply to your modified version as well.
-
-AC_DEFUN([AX_PYTHON_NUMERIC],[
-	AC_MSG_CHECKING([for python])
-	AS_IF([test -z "$PYTHON"], [
-		AC_MSG_RESULT([unknown])
-	],[
-		AC_MSG_RESULT([$PYTHON])
-	])
-
-	AS_IF([true], [
-
-		AC_CACHE_CHECK([whether linking to numeric library works], [ax_python_numeric_cv_check],
-		[
-			ax_python_numeric_cv_check=no
-
-			AC_LANG_PUSH([C++])
-
-			ax_python_numeric_cppflags="$CPPFLAGS"
-			ax_python_numeric_ldflags="$LDFLAGS"
-			CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
-			LDFLAGS="$LDFLAGS $PYTHON_LDFLAGS"
-			
-			AC_LANG_ASSERT(C++)
-			AC_LINK_IFELSE(
-			AC_LANG_PROGRAM(
-				[[
-#define PY_ARRAY_UNIQUE_SYMBOL my_array_symbol
-#include <Python.h>
-#include <Numeric/arrayobject.h>
-typedef int npy_intp;
-]],
-				[[ &PyArray_FromDims; ]]),
-				[ax_python_numeric_cv_check=yes],
-				[ax_python_numeric_cv_check=no])
-			CPPFLAGS="$ax_python_numeric_cppflags"
-			LDFLAGS="$ax_python_numeric_ldflags"
-			
-			AC_LANG_POP([C++])
-		])
-	])
-
-	AS_IF([test "x$ax_python_numeric_cv_check" != "xyes"], [
-		AC_MSG_WARN([[
-========================================================================
-Can not link with Numeric.
-
-Make sure the Numeric development package is installed.
-========================================================================]])
-	])
-
-	# Execute ACTION_IF_FOUND or ACTION_IF_NOT_FOUND
-	if test "x$ax_python_numeric_cv_check" == "xyes" ; then
-		m4_ifvaln([$1],[$1],[:])dnl
-		m4_ifvaln([$2],[else $2])dnl
-	fi
-
-])
--- a/octave_to_python.cc	Mon Apr 09 20:05:48 2012 +0200
+++ b/octave_to_python.cc	Mon Apr 09 21:22:32 2012 +0200
@@ -119,7 +119,7 @@
          dimensions[i] = dims(i);
       }
 
-      return (PyArrayObject *)PyArray_FromDims(
+      return (PyArrayObject *)PyArray_SimpleNew(
          len, dimensions, pyarrtype);
    }
 
@@ -248,15 +248,13 @@
             matrix.int8_array_value());
       }
       if (matrix.is_bool_type()) {
-#ifdef HAVE_NUMPY
          // NumPY has logical arrays, and even provides an old-style #define.
          return create_array<bool, boolNDArray>(
             matrix.bool_array_value(), PyArray_BOOL);
-#else
-         // Numeric does not support bools, use uint8.
-         return create_uint_array<uint8NDArray, sizeof(uint8_t)>(
-            matrix.uint8_array_value());
-#endif
+         // Numeric does not support bools, and we used to have uint8 as a
+         // fallback, back when we had support for Numeric.
+         // return create_uint_array<uint8NDArray, sizeof(uint8_t)>(
+         //    matrix.uint8_array_value());
       }
       if (matrix.is_string()) {
          return create_array<char, charNDArray>(
--- a/package/pytave.py	Mon Apr 09 20:05:48 2012 +0200
+++ b/package/pytave.py	Mon Apr 09 21:22:32 2012 +0200
@@ -38,17 +38,7 @@
 (OctaveError, ValueConvertError, ObjectConvertError, ParseError, \
  VarNameError) = _pytave.get_exceptions();
 
-# Dynamic import. *Must* go after _pytave.init() !
-__modname__ = _pytave.get_module_name()
-if __modname__ == 'numpy':
-    from numpy import oldnumeric as Numeric
-elif __modname__ == 'Numeric':
-    import Numeric
-elif __modname__ == 'numarray':
-    # FIXME: Is this OK?
-    import numarray as Numeric
-else:
-    raise ImportError("Failed to import module: %s" % __modname__)
+from numpy import oldnumeric as Numeric
 
 def _atexit():
 	_pytave.atexit()
--- a/pytave.cc	Mon Apr 09 20:05:48 2012 +0200
+++ b/pytave.cc	Mon Apr 09 21:22:32 2012 +0200
@@ -107,14 +107,9 @@
       // This is actually a macro that becomes a block expression. If an error
       // occurs, e.g. Numeric Array not installed, an exception is set.
       import_array()
-#ifdef HAVE_NUMPY
+
       // Let boost use numpy
       numeric::array::set_module_and_type ("numpy", "ndarray");
-#endif
-   }
-
-   string get_module_name () {
-      return numeric::array::get_module_name ();
    }
 
    boost::python::tuple get_exceptions() {
@@ -394,7 +389,6 @@
    using namespace boost::python;
 
    def("init", pytave::init);
-   def("get_module_name", pytave::get_module_name);
    def("feval", pytave::func_eval);
    def("eval", pytave::str_eval);
    def("getvar", pytave::getvar);
--- a/python_to_octave.cc	Mon Apr 09 20:05:48 2012 +0200
+++ b/python_to_octave.cc	Mon Apr 09 21:22:32 2012 +0200
@@ -191,10 +191,8 @@
          /* Commonly Numeric.array(..., Numeric.Complex) */
          ARRAYCASE(PyArray_CDOUBLE, Complex)
 
-#ifdef HAVE_NUMPY
          ARRAYCASE(PyArray_BOOL, bool)
          ARRAYCASE(PyArray_STRING, char)
-#endif
 
          ARRAYCASE(PyArray_OBJECT, PyObject *)
 
@@ -290,12 +288,15 @@
             // FIXME: is the following needed?
             octvalue = octvalue.convert_to_str(true, true, '"');
             break;
-#ifdef HAVE_NUMPY
          case PyArray_BOOL:
+            // PyArray_BOOL is an NumPy-ism (was not part of origin Numeric
+            // interface.)
             pyarrobj_to_octvalueNd<boolNDArray>(octvalue, pyarr, dims);
             break;
          case PyArray_STRING:
             {
+               // PyArray_STRING is an NumPy-ism (was not part of origin Numeric
+               // interface.)
                if (pyarr->descr->elsize == 1)
                   goto case_PyArray_CHAR;
                else {
@@ -310,7 +311,6 @@
                }
             }
             break;
-#endif
          case PyArray_OBJECT:
             pyarrobj_to_octvalueNd<Cell>(octvalue, pyarr, dims);
             break;