diff options
| author | Travis Oliphant <oliphant@enthought.com> | 2006-08-10 00:14:42 +0000 |
|---|---|---|
| committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-10 00:14:42 +0000 |
| commit | 8959e33dfc7c2eef00cfdca74d3b750675cfc79d (patch) | |
| tree | 88aafd83e5a25791b5dfa8e753a03ee0e69ccfb7 /numpy/core/_internal.py | |
| parent | 217ae0e1df7846bb902a0383c77af26c0c7993a0 (diff) | |
| download | numpy-8959e33dfc7c2eef00cfdca74d3b750675cfc79d.tar.gz | |
Fix byte-order problems in comma-string formats and size-specified fields.
Diffstat (limited to 'numpy/core/_internal.py')
| -rw-r--r-- | numpy/core/_internal.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 3d3c51841..6f64f40f4 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -4,6 +4,12 @@ import re from multiarray import dtype, ndarray +import sys + +if (sys.byteorder == 'little'): + _nbo = '<' +else: + _nbo = '>' def _makenames_list(adict): allfields = [] @@ -141,10 +147,15 @@ def _split(input): return newlist -format_re = re.compile(r'(?P<repeat> *[(]?[ ,0-9]*[)]? *)(?P<dtype>[><|A-Za-z0-9.]*)') +format_re = re.compile(r'(?P<order1>[<>|=]?)(?P<repeats> *[(]?[ ,0-9]*[)]? *)(?P<order2>[<>|=]?)(?P<dtype>[A-Za-z0-9.]*)') # astr is a string (perhaps comma separated) +_convorder = {'=': _nbo, + '|': '|', + '>': '>', + '<': '<'} + def _commastring(astr): res = _split(astr) if (len(res)) < 1: @@ -153,10 +164,24 @@ def _commastring(astr): for k,item in enumerate(res): # convert item try: - (repeats, dtype) = format_re.match(item).groups() + (order1, repeats, order2, dtype) = format_re.match(item).groups() except (TypeError, AttributeError): raise ValueError('format %s is not recognized' % item) + if order2 == '': + order = order1 + elif order1 == '': + order = order2 + else: + order1 = _convorder[order1] + order2 = _convorder[order2] + if (order1 != order2): + raise ValueError('in-consistent byte-order specification %s and %s' % (order1, order2)) + order = order1 + + if order in ['|', '=', _nbo]: + order = '' + dtype = '%s%s' % (order, dtype) if (repeats == ''): newitem = dtype else: |
