summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-03-15 00:48:04 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-03-15 00:48:04 +0000
commit03736884e2fb993e096ef801dd49135b9292b823 (patch)
tree5556dc46592b881b33ae600e385c8578e3e4ebb6 /numpy/core/_internal.py
parent440214d5835da50d9dad3103835fb8b3967eb3b5 (diff)
downloadnumpy-03736884e2fb993e096ef801dd49135b9292b823.tar.gz
Changed the C-API by making the a.flags object a builtin object for speed. Also fixed issues with linalg and matrices.
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r--numpy/core/_internal.py151
1 files changed, 1 insertions, 150 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 66eff15f7..2517bf699 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -3,156 +3,7 @@
# that implements more complicated stuff.
import re
-from multiarray import _flagdict, dtype, ndarray
-
-_defflags = _flagdict.keys()
-
-_setable = ['WRITEABLE','UPDATEIFCOPY', 'ALIGNED',
- 'W','U','A']
-_setable2 = ['write','uic','align']*2
-_firstltr = {'W':'WRITEABLE',
- 'A':'ALIGNED',
- 'C':'CONTIGUOUS',
- 'F':'FORTRAN',
- 'O':'OWNDATA',
- 'U':'UPDATEIFCOPY'}
-
-_anum = _flagdict['ALIGNED']
-_wnum = _flagdict['WRITEABLE']
-_cnum = _flagdict['CONTIGUOUS']
-_fnum = _flagdict['FORTRAN']
-_unum = _flagdict['UPDATEIFCOPY']
-_onum = _flagdict['OWNDATA']
-
-class flagsobj(dict):
- def __init__(self, arr, flags, scalar):
- self._arr = arr
- self._flagnum = flags
- for k in _defflags:
- num = _flagdict[k]
- dict.__setitem__(self, k, flags & num == num)
- self.scalar = scalar
-
- def __getitem__(self, key):
- if not isinstance(key, str):
- raise KeyError, "Unknown flag %s" % key
- if len(key) == 1:
- try:
- return dict.__getitem__(self, _firstltr[key])
- except:
- if (key == 'B'):
- num = _anum + _wnum
- return self._flagnum & num == num
- else:
- try:
- return dict.__getitem__(self, key)
- except: # special cases
- if (key == 'FNC'):
- return (self._flagnum & _fnum == _fnum) and not \
- (self._flagnum & _cnum == _cnum)
- if (key == 'FORC'):
- return (self._flagnum & _fnum == _fnum) or \
- (self._flagnum & _cnum == _cnum)
- if (key == 'BEHAVED'):
- num = _anum + _wnum
- return self._flagnum & num == num
- if (key in ['CARRAY','CA']):
- num = _anum + _wnum + _cnum
- return self._flagnum & num == num
- if (key in ['FARRAY','FA']):
- num = _anum + _wnum + _fnum
- return (self._flagnum & num == num) and not \
- (self._flagnum & _cnum == _cnum)
- raise KeyError, "Unknown flag: %s" % key
-
- def __setitem__(self, item, val):
- if self.scalar:
- raise ValueError, "Cannot set flags on array scalars."
- val = not not val # convert to boolean
- if item not in _setable:
- raise KeyError, "Cannot set flag", item
- dict.__setitem__(self, item, val) # Does this matter?
-
- kwds = {}
- for k, name in enumerate(_setable):
- if item == name:
- kwds[_setable2[k]] = val
-
- # now actually update array flags
- self._arr.setflags(**kwds)
-
-
- def get_fnc(self):
- fl = self._flagnum
- return (fl & _fnum == _fnum) and \
- not (fl & _cnum == _cnum)
-
- def get_forc(self):
- fl = self._flagnum
- return (fl & _cnum == _cnum) or \
- (fl & _fnum == _fnum)
-
- def get_behaved(self):
- fl = self._flagnum
- return (fl & _anum == _anum) and \
- (fl & _wnum == _wnum)
-
- def get_carray(self):
- fl = self._flagnum
- return (fl & _anum == _anum) and \
- (fl & _wnum == _wnum) and \
- (fl & _cnum == _cnum)
-
- def get_farray(self):
- fl = self._flagnum
- return (fl & _anum == _anum) and \
- (fl & _wnum == _wnum) and \
- (fl & _fnum == _fnum) and \
- not (fl & _cnum == _cnum)
-
- def get_contiguous(self):
- return (self._flagnum & _cnum == _cnum)
-
- def get_fortran(self):
- return (self._flagnum & _fnum == _fnum)
-
- def get_updateifcopy(self):
- return (self._flagnum & _unum == _unum)
-
- def get_owndata(self):
- return (self._flagnum & _onum == _onum)
-
- def get_aligned(self):
- return (self._flagnum & _anum == _anum)
-
- def get_writeable(self):
- return (self._flagnum & _wnum == _wnum)
-
- def set_writeable(self, val):
- val = not not val
- self._arr.setflags(write=val)
-
- def set_aligned(self, val):
- val = not not val
- self._arr.setflags(align=val)
-
- def set_updateifcopy(self, val):
- val = not not val
- self._arr.setflags(uic=val)
-
- contiguous = property(get_contiguous, None, "")
- fortran = property(get_fortran, None, "")
- updateifcopy = property(get_updateifcopy, set_updateifcopy, "")
- owndata = property(get_owndata, None, "")
- aligned = property(get_aligned, set_aligned, "")
- writeable = property(get_writeable, set_writeable, "")
-
- fnc = property(get_fnc, None, "")
- forc = property(get_forc, None, "")
- behaved = property(get_behaved, None, "")
- carray = property(get_carray, None, "")
- farray = property(get_farray, None, "")
-
+from multiarray import dtype, ndarray
# make sure the tuple entries are PyArray_Descr
# or convert them