Changeset 7278


Ignore:
Timestamp:
Jun 30, 2009, 2:30:16 PM (15 years ago)
Author:
rwilson
Message:

Minor changes to Numeric/numpy comparison code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy_misc/tools/test_numpy_numeric/test_numpy_numeric.py

    r7245 r7278  
    1818
    1919
    20 ARRAY_SIZE = 1000 * 1000
     20#ARRAY_SIZE = 1000 * 1000
     21ARRAY_SIZE = (40000, 3)
    2122
    2223
     
    7576    This function is necessary as array(A) can cause memory overflow.
    7677    """
    77 
    78 #    if isinstance(A, basestring):
    79 #        msg = 'Sorry, cannot handle strings in ensure_numeric()'
    80 #        raise Exception, msg
    8178
    8279    if typecode is None:
     
    150147
    151148
     149class Array(object):
     150    def __init__(self, module, f):
     151        self.array = module.ones(ARRAY_SIZE, f)
     152        for i in xrange(ARRAY_SIZE[0]):
     153            for j in xrange(ARRAY_SIZE[1]):
     154                self.array[i, j] *= float(i)+j
     155
    152156def test_usage(module, f, en, ls):
    153     start_time = time.time()
    154157    start_mem = mem_usage()
    155158
    156     A = module.ones(ARRAY_SIZE, f)
    157     B = module.ones(ARRAY_SIZE, f)
    158     for i in xrange(ls):
    159         A[i] *= float(i)
    160         B[i] *= float(i)
     159    A = Array(module, f)
     160    B = Array(module, f)
     161    C = Array(module, f)
     162    D = module.ones(ARRAY_SIZE[1], f)
     163
     164    start_time = time.time()
    161165
    162166    # do some numeric calculations
    163     A = en(A)
    164     B = en(B)
    165     C = module.ones(ARRAY_SIZE, f)
    166     C = en(C)
    167167    for i in xrange(ls):
    168         C = en(2.6*A + B + C + i)
     168        for j in xrange(ARRAY_SIZE[0]):
     169            for k in xrange(ARRAY_SIZE[1]):
     170                D[0] = A.array[j, k]
     171                D[1] = B.array[j, k]
     172                D[2] = C.array[j, k]
    169173
    170174    stop_mem = mem_usage()
     
    174178    delta_mem = stop_mem - start_mem
    175179
    176     del A, B, C
     180    del A, B, C, D
    177181    gc.collect()
    178182
    179183    return (delta_time, delta_mem)
    180184
    181 for loop_size in (10, 100, 1000):
    182     # Do numpy work
    183     (t, m) = test_usage(numpy, numpy.float, numpy_ensure_numeric, loop_size)
    184     print('  numpy %4d loops: %5.1f s, %d KiB' % (loop_size, t, m))
    185 
     185#for loop_size in (10, 100, 1000):
     186for loop_size in (10, 100):
    186187    # Do Numeric work
    187188    (t, m) = test_usage(Numeric, Numeric.Float, Numeric_ensure_numeric,
     
    189190    print('Numeric %4d loops: %5.1f s, %d KiB' % (loop_size, t, m))
    190191
     192    # Do numpy work
     193    (t, m) = test_usage(numpy, numpy.float, numpy_ensure_numeric, loop_size)
     194    print('  numpy %4d loops: %5.1f s, %d KiB' % (loop_size, t, m))
     195
Note: See TracChangeset for help on using the changeset viewer.