diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-12-06 00:49:43 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-12-06 00:49:43 +0000 |
commit | cb2f58fe323d9753b45ecd9f877f6acb99c7c94b (patch) | |
tree | 3fcace566a0808e8d2897c31078faa4334ba041d /scipy/base/_internal.py | |
parent | 4772f10191f87a3446f4862de6d4b953e0dd95ff (diff) | |
download | numpy-cb2f58fe323d9753b45ecd9f877f6acb99c7c94b.tar.gz |
Field specification possible with two-kinds of dictionaries
Diffstat (limited to 'scipy/base/_internal.py')
-rw-r--r-- | scipy/base/_internal.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/scipy/base/_internal.py b/scipy/base/_internal.py index 6d3aa611e..626a8439f 100644 --- a/scipy/base/_internal.py +++ b/scipy/base/_internal.py @@ -1,6 +1,6 @@ -from multiarray import _flagdict +from multiarray import _flagdict, dtypedescr _defflags = _flagdict.keys() @@ -186,3 +186,48 @@ class flagsobj(dict): carray = property(get_carray, None, "") farray = property(get_farray, None, "") + + +# make sure the tuple entries are PyArray_Descr +# or convert them +# +# make sure offsets are all interpretable +# as positive integers and +# convert them to positive integers if so +# +# +# return totalsize from last offset and size + +def _usefields(adict): + names = [] + formats = [] + offsets = [] + titles = [] + fnames = adict.keys() + for fname in fnames: + obj = adict[fname] + n = len(obj) + if not isinstance(obj, tuple) or n not in [2,3]: + raise ValueError, "entry not a 2- or 3- tuple" + if (n > 2) and (obj[2] == fname): + continue + num = int(obj[1]) + if (num < 0): + raise ValueError, "invalid offset." + names.append(fname) + offsets.append(num) + formats.append(dtypedescr(obj[0])) + if (n > 2): + title = obj[2] + else: + title = None + titles.append(title) + return dtypedescr({"names" : names, + "formats" : formats, + "offsets" : offsets, + "titles" : titles}) + + + + + |