Index: branches/numpy_misc/tools/test_numpy_numeric/test_numpy_numeric.py
===================================================================
--- branches/numpy_misc/tools/test_numpy_numeric/test_numpy_numeric.py	(revision 7244)
+++ branches/numpy_misc/tools/test_numpy_numeric/test_numpy_numeric.py	(revision 7245)
@@ -19,5 +19,72 @@
 
 ARRAY_SIZE = 1000 * 1000
-LOOP_SIZE = 1000
+
+
+# Numeric version
+def Numeric_ensure_numeric(A, typecode=None):
+    """Ensure that sequence is a numeric array.
+
+    Inputs:
+        A: Sequence. If A is already a Numeric array it will be returned
+                     unaltered
+                     If not, an attempt is made to convert it to a Numeric
+                     array
+        A: Scalar.   Return 0-dimensional array of length 1, containing that value
+        A: String.   Array of ASCII values
+        typecode: Numeric type. If specified, use this in the conversion.
+                                If not, let Numeric decide
+
+    This function is necessary as array(A) can cause memory overflow.
+    """
+
+    if typecode is None:
+        if type(A) == Numeric.ArrayType:
+            return A
+        else:
+            return Numeric.array(A)
+    else:
+        if type(A) == Numeric.ArrayType:
+            if A.typecode() == typecode:
+                return A
+            else:
+                return Numeric.array(A, typecode)
+        else:
+            return Numeric.array(A, typecode)
+
+
+# numpy version
+def numpy_ensure_numeric(A, typecode=None):
+    """Ensure that sequence is a numeric array.
+
+    Inputs:
+        A: Sequence. If A is already a numeric array it will be returned
+                     unaltered
+                     If not, an attempt is made to convert it to a numeric
+                     array
+        A: Scalar.   Return 0-dimensional array containing that value. Note
+                     that a 0-dim array DOES NOT HAVE A LENGTH UNDER numpy.
+        A: String.   Array of ASCII values (numpy can't handle this)
+
+        typecode:    numeric type. If specified, use this in the conversion.
+                     If not, let numeric package decide.
+                     typecode will always be one of num.float, num.int, etc.
+
+    Note that num.array(A, dtype) will sometimes copy.  Use 'copy=False' to
+    copy only when required.
+
+    This function is necessary as array(A) can cause memory overflow.
+    """
+
+#    if isinstance(A, basestring):
+#        msg = 'Sorry, cannot handle strings in ensure_numeric()'
+#        raise Exception, msg
+
+    if typecode is None:
+        if isinstance(A, numpy.ndarray):
+            return A
+        else:
+            return numpy.array(A)
+    else:
+        return numpy.array(A, dtype=typecode, copy=False)
 
 
@@ -82,52 +149,42 @@
         return int(memoryStatusEx.ullTotalPhys/_scale['KB'])
 
-def test_usage(module, A, B):
+
+def test_usage(module, f, en, ls):
+    start_time = time.time()
+    start_mem = mem_usage()
+
+    A = module.ones(ARRAY_SIZE, f)
+    B = module.ones(ARRAY_SIZE, f)
+    for i in xrange(ls):
+        A[i] *= float(i)
+        B[i] *= float(i)
+
     # do some numeric calculations
-    C = B
-    for i in xrange(LOOP_SIZE):
-        C = 2.6*A + B + C + i
+    A = en(A)
+    B = en(B)
+    C = module.ones(ARRAY_SIZE, f)
+    C = en(C)
+    for i in xrange(ls):
+        C = en(2.6*A + B + C + i)
 
-# Do numpy work
-start_time = time.time()
-start_mem = mem_usage()
+    stop_mem = mem_usage()
+    stop_time = time.time()
 
-A = numpy.ones(ARRAY_SIZE, numpy.float)
-B = numpy.ones(ARRAY_SIZE, numpy.float)
-for i in xrange(ARRAY_SIZE):
-    A[i] *= float(i)
-    B[i] *= float(i)
+    delta_time = stop_time - start_time
+    delta_mem = stop_mem - start_mem
 
-test_usage(numpy, A, B)
+    del A, B, C
+    gc.collect()
 
-stop_mem = mem_usage()
-stop_time = time.time()
+    return (delta_time, delta_mem)
 
-del A, B
-gc.collect()
+for loop_size in (10, 100, 1000):
+    # Do numpy work
+    (t, m) = test_usage(numpy, numpy.float, numpy_ensure_numeric, loop_size)
+    print('  numpy %4d loops: %5.1f s, %d KiB' % (loop_size, t, m))
 
-delta_time = stop_time - start_time
-delta_mem = stop_mem - start_mem
-print('  numpy: %.1f s, %d KiB' % (delta_time, delta_mem))
+    # Do Numeric work
+    (t, m) = test_usage(Numeric, Numeric.Float, Numeric_ensure_numeric,
+                        loop_size)
+    print('Numeric %4d loops: %5.1f s, %d KiB' % (loop_size, t, m))
 
-# Do Numeric work
-start_time = time.time()
-start_mem = mem_usage()
-
-A = Numeric.ones(ARRAY_SIZE, Numeric.Float)
-B = Numeric.ones(ARRAY_SIZE, Numeric.Float)
-for i in xrange(ARRAY_SIZE):
-    A[i] *= float(i)
-    B[i] *= float(i)
-
-test_usage(Numeric, A, B)
-
-stop_mem = mem_usage()
-stop_time = time.time()
-
-del A, B
-gc.collect()
-
-delta_time = stop_time - start_time
-delta_mem = stop_mem - start_mem
-print('Numeric: %.1f s, %d KiB' % (delta_time, delta_mem))
-
