diff options
author | Travis Oliphant <oliphant@enthought.com> | 2008-08-27 14:31:18 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2008-08-27 14:31:18 +0000 |
commit | eda3f09142f08498f479f6353c5c063ecef4aac0 (patch) | |
tree | 390a4bec0155841536b83da26bb5c17860ee6fe6 /numpy/core | |
parent | 6aa2c46129ca2e18aa5e720a9a45f8830f1bfb58 (diff) | |
download | numpy-eda3f09142f08498f479f6353c5c063ecef4aac0.tar.gz |
Apply modified version of Andrew Dalke's patch in #874 to create a quicker-loading numpy.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/memmap.py | 3 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 19 |
2 files changed, 18 insertions, 4 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 05aaefef0..dd09b8e28 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -1,6 +1,5 @@ __all__ = ['memmap'] -import mmap import warnings from numeric import uint8, ndarray, dtype @@ -173,6 +172,8 @@ class memmap(ndarray): __array_priority__ = -100.0 def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0, shape=None, order='C'): + # Import here to minimize 'import numpy' overhead + import mmap try: mode = mode_equivalents[mode] except KeyError: diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index a368a2bec..8a89f40c6 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -88,9 +88,22 @@ from __builtin__ import bool, int, long, float, complex, object, unicode, str # String-handling utilities to avoid locale-dependence. -import string -LOWER_TABLE = string.maketrans(string.ascii_uppercase, string.ascii_lowercase) -UPPER_TABLE = string.maketrans(string.ascii_lowercase, string.ascii_uppercase) +# "import string" is costly to import! +# Construct the translation tables directly +# "A" = chr(65), "a" = chr(97) +_all_chars = map(chr, range(256)) +_ascii_upper = _all_chars[65:65+26] +_ascii_lower = _all_chars[97:97+26] +LOWER_TABLE="".join(_all_chars[:65] + _ascii_lower + _all_chars[65+26:]) +UPPER_TABLE="".join(_all_chars[:97] + _ascii_upper + _all_chars[97+26:]) + +#import string +# assert (string.maketrans(string.ascii_uppercase, string.ascii_lowercase) == \ +# LOWER_TABLE) +# assert (string.maketrnas(string_ascii_lowercase, string.ascii_uppercase) == \ +# UPPER_TABLE) +#LOWER_TABLE = string.maketrans(string.ascii_uppercase, string.ascii_lowercase) +#UPPER_TABLE = string.maketrans(string.ascii_lowercase, string.ascii_uppercase) def english_lower(s): """ Apply English case rules to convert ASCII strings to all lower case. |