Permalink
Browse files

Moved .dtypedescr to .dtype; .dtype->.dtype.type; .dtypestr ->.dtype.…

…str; .dtypechar -> .dtype.char
  • Loading branch information...
1 parent d04bb02 commit 0283b6f480b7239dc1390dadf29fcb5e1f2516e3 Travis Oliphant committed Jan 15, 2006
View
@@ -3,7 +3,7 @@
X.flat returns an indexable 1-D iterator (mostly similar to an array
but always 1-d) --- only has .copy and .__array__ attributes of an array!!!
-.typecode() --> .dtypechar
+.typecode() --> .dtype.char
.iscontiguous() --> .flags['CONTIGUOUS'] or .flags.contiguous
@@ -3,7 +3,7 @@
# that implements more complicated stuff.
import re
-from multiarray import _flagdict, dtypedescr, ndarray
+from multiarray import _flagdict, dtype, ndarray
_defflags = _flagdict.keys()
@@ -186,7 +186,7 @@ def _usefields(adict, align):
num = int(obj[1])
if (num < 0):
raise ValueError, "invalid offset."
- format = dtypedescr(obj[0])
+ format = dtype(obj[0])
if (format.itemsize == 0):
raise ValueError, "all itemsizes must be fixed."
if (n > 2):
@@ -213,10 +213,10 @@ def _usefields(adict, align):
else:
titles.append(None)
- return dtypedescr({"names" : names,
- "formats" : formats,
- "offsets" : offsets,
- "titles" : titles}, align)
+ return dtype({"names" : names,
+ "formats" : formats,
+ "offsets" : offsets,
+ "titles" : titles}, align)
# construct an array_protocol descriptor list
@@ -228,7 +228,7 @@ def _usefields(adict, align):
def _array_descr(descriptor):
fields = descriptor.fields
if fields is None:
- return descriptor.dtypestr
+ return descriptor.str
ordered_fields = [fields[x] + (x,) for x in fields[-1]]
result = []
@@ -145,7 +145,7 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ',
try:
format_function = a._format
except AttributeError:
- dtype = a.dtype
+ dtype = a.dtype.type
if issubclass(dtype, _nt.bool):
format = "%s"
format_function = lambda x, f = format: format % x
@@ -222,9 +222,12 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)
}
/* Choose which subtype to return */
- prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);
- prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);
- subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);
+ if (ap1->ob_type != ap2->ob_type) {
+ prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);
+ prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);
+ subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);
+ }
+ else subtype = ap1->ob_type;
ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,
typenum, NULL, NULL, 0, 0,
@@ -300,7 +300,7 @@ def array(obj, itemsize=None, copy=True, unicode=False, fortran=False):
if copy or (itemsize != obj.itemsize) \
or (not unicode and obj.dtype == unicode_) \
or (unicode and obj.dtype == string):
- return obj.astype("%s%d" % (obj.dtypechar, itemsize))
+ return obj.astype("%s%d" % (obj.dtype.char, itemsize))
else:
return obj
@@ -58,17 +58,17 @@ def __new__(subtype, data, dtype=None, copy=True):
dtype2 = data.dtype
if (dtype is None):
dtype = dtype2
- if (dtype2 is dtype) and (not copy):
+ if (dtype2 == dtype) and (not copy):
return data
return data.astype(dtype)
if isinstance(data, N.ndarray):
if dtype is None:
- intype = data.dtypedescr
+ intype = data.dtype
else:
- intype = N.dtypedescr(dtype)
+ intype = N.dtype(dtype)
new = data.view(matrix)
- if intype != data.dtypedescr:
+ if intype != data.dtype:
return new.astype(intype)
if copy: return new.copy()
else: return new
@@ -94,7 +94,7 @@ def __new__(subtype, data, dtype=None, copy=True):
if not (fortran or arr.flags.contiguous):
arr = arr.copy()
- ret = N.ndarray.__new__(subtype, shape, arr.dtypedescr,
+ ret = N.ndarray.__new__(subtype, shape, arr.dtype,
buffer=arr,
fortran=fortran)
return ret
@@ -199,7 +199,7 @@ def getT(self):
return self.transpose()
def getH(self):
- if issubclass(self.dtype, N.complexfloating):
+ if issubclass(self.dtype.type, N.complexfloating):
return self.transpose().conjugate()
else:
return self.transpose()
View
@@ -83,7 +83,7 @@ def default_fill_value (obj):
elif isinstance(obj, types.ComplexType):
return default_complex_fill_value
elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
- x = obj.dtypechar
+ x = obj.dtype.char
if x in typecodes['Float']:
return default_real_fill_value
if x in typecodes['Integer']:
@@ -105,7 +105,7 @@ def minimum_fill_value (obj):
elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):
return sys.maxint
elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
- x = obj.dtypechar
+ x = obj.dtype.char
if x in typecodes['Float']:
return numeric.inf
if x in typecodes['Integer']:
@@ -122,7 +122,7 @@ def maximum_fill_value (obj):
elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):
return -sys.maxint
elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
- x = obj.dtypechar
+ x = obj.dtype.char
if x in typecodes['Float']:
return -inf
if x in typecodes['Integer']:
@@ -161,7 +161,7 @@ def is_mask (m):
"""Is m a legal mask? Does not check contents, only type.
"""
if m is nomask or (isinstance(m, ndarray) and \
- m.dtype is MaskType):
+ m.dtype.type is MaskType):
return 1
else:
return 0
@@ -176,7 +176,7 @@ def make_mask (m, copy=0, flag=0):
if m is nomask:
return nomask
elif isinstance(m, ndarray):
- if m.dtype is MaskType:
+ if m.dtype.type is MaskType:
if copy:
result = numeric.array(m, dtype=MaskType, copy=copy)
else:
@@ -525,12 +525,12 @@ class MaskedArray (object):
then the candidate data is data.data and the
mask used is data.mask. If data is a numeric array,
it is used as the candidate raw data.
- If dtypechar is not None and
- is != data.dtypechar then a data copy is required.
+ If dtype.char is not None and
+ is != data.dtype.char then a data copy is required.
Otherwise, the candidate is used.
If a data copy is required, raw data stored is the result of:
- numeric.array(data, dtype=dtypechar, copy=copy)
+ numeric.array(data, dtype=dtype.char, copy=copy)
If mask is nomask there are no masked values. Otherwise mask must
be convertible to an array of booleans with the same shape as x.
@@ -549,7 +549,7 @@ def __init__(self, data, dtype=None, copy=True, fortran=False,
need_data_copied = copy
if isinstance(data, MaskedArray):
c = data.data
- ctc = c.dtypechar
+ ctc = c.dtype.char
if tc is None:
tc = ctc
elif dtype2char(tc) != ctc:
@@ -561,7 +561,7 @@ def __init__(self, data, dtype=None, copy=True, fortran=False,
elif isinstance(data, ndarray):
c = data
- ctc = c.dtypechar
+ ctc = c.dtype.char
if tc is None:
tc = ctc
elif dtype2char(tc) != ctc:
@@ -979,9 +979,9 @@ def __sqrt__(self):
def __iadd__(self, other):
"Add other to self in place."
- t = self._data.dtypechar
+ t = self._data.dtype.char
f = filled(other,0)
- t1 = f.dtypechar
+ t1 = f.dtype.char
if t == t1:
pass
elif t in typecodes['Integer']:
@@ -1022,9 +1022,9 @@ def __iadd__(self, other):
def __imul__(self, other):
"Add other to self in place."
- t = self._data.dtypechar
+ t = self._data.dtype.char
f = filled(other,0)
- t1 = f.dtypechar
+ t1 = f.dtype.char
if t == t1:
pass
elif t in typecodes['Integer']:
@@ -1065,9 +1065,9 @@ def __imul__(self, other):
def __isub__(self, other):
"Subtract other from self in place."
- t = self._data.dtypechar
+ t = self._data.dtype.char
f = filled(other,0)
- t1 = f.dtypechar
+ t1 = f.dtype.char
if t == t1:
pass
elif t in typecodes['Integer']:
@@ -1110,9 +1110,9 @@ def __isub__(self, other):
def __idiv__(self, other):
"Divide self by other in place."
- t = self._data.dtypechar
+ t = self._data.dtype.char
f = filled(other,0)
- t1 = f.dtypechar
+ t1 = f.dtype.char
if t == t1:
pass
elif t in typecodes['Integer']:
@@ -1348,10 +1348,6 @@ def _get_size (self):
size = property(fget=_get_size, doc="Number of elements in the array.")
## CHECK THIS: signature of numeric.array.size?
- def _get_dtypechar(self):
- return self._data.dtypechar
- dtypechar = property(fget=_get_dtypechar, doc="type character of the array.")
-
def _get_dtype(self):
return self._data.dtype
dtype = property(fget=_get_dtype, doc="type of the array elements.")
@@ -1464,7 +1460,7 @@ def masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):
"""
abs = umath.absolute
d = filled(data, value)
- if issubclass(d.dtype, numeric.floating):
+ if issubclass(d.dtype.type, numeric.floating):
m = umath.less_equal(abs(d-value), atol+rtol*abs(value))
m = make_mask(m, flag=1)
return array(d, mask = m, copy=copy,
@@ -1480,7 +1476,7 @@ def masked_object (data, value, copy=1):
def arrayrange(start, stop=None, step=1, dtype=None):
"""Just like range() except it returns a array whose type can be specified
- by the keyword argument dtypechar.
+ by the keyword argument dtype.
"""
return array(numeric.arrayrange(start, stop, step, dtype))
@@ -1573,7 +1569,7 @@ def power (a, b, third=None):
m = mask_or(ma, mb)
fa = filled(a, 1)
fb = filled(b, 1)
- if fb.dtypechar in typecodes["Integer"]:
+ if fb.dtype.char in typecodes["Integer"]:
return masked_array(umath.power(fa, fb), m)
md = make_mask(umath.less_equal (fa, 0), flag=1)
m = mask_or(m, md)
@@ -2143,8 +2139,6 @@ def _compress(self, cond, axis=None):
array.cumprod = _m(not_implemented)
array.cumsum = _m(not_implemented)
array.diagonal = _m(diagonal)
-array.dtypedescr = property(_m(not_implemented))
-array.dtypestr = property(_m(not_implemented))
array.dump = _m(not_implemented)
array.dumps = _m(not_implemented)
array.fill = _m(not_implemented)
@@ -1,7 +1,7 @@
__all__ = ['memmap']
import mmap
-from numeric import uint8, ndarray, dtypedescr
+from numeric import uint8, ndarray, dtype
from numerictypes import nbytes
valid_filemodes = ["r", "c", "r+", "w+"]
@@ -35,7 +35,7 @@ def __new__(subtype, name, dtype=uint8, mode='r+', offset=0,
fid.seek(0,2)
flen = fid.tell()
- descr = dtypedescr(dtype)
+ descr = dtype(dtype)
_dbytes = descr.itemsize
if shape is None:
View
@@ -1,5 +1,5 @@
__all__ = ['newaxis', 'ndarray', 'bigndarray', 'flatiter', 'ufunc',
- 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtypedescr',
+ 'arange', 'array', 'zeros', 'empty', 'broadcast', 'dtype',
'fromstring', 'fromfile', 'frombuffer','newbuffer','getbuffer',
'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',
'register_dtype', 'set_numeric_ops', 'can_cast',
@@ -45,7 +45,7 @@ def extend_all(module):
bigndarray = multiarray.bigndarray
flatiter = multiarray.flatiter
broadcast = multiarray.broadcast
-dtypedescr=multiarray.dtypedescr
+dtype=multiarray.dtype
ufunc = type(sin)
arange = multiarray.arange
@@ -223,7 +223,7 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
', ', "array(")
else: # show zero-length shape unless it is (0,)
lst = "[], shape=%s" % (repr(arr.shape),)
- typeless = arr.dtype in _typelessdata
+ typeless = arr.dtype.type in _typelessdata
if arr.__class__ is not ndarray:
cName= arr.__class__.__name__
@@ -232,10 +232,10 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
if typeless and arr.size:
return cName + "(%s)" % lst
else:
- typename=arr.dtype.__name__[:-8]
- if issubclass(arr.dtype, flexible):
+ typename=arr.dtype.type.__name__[:-8]
+ if issubclass(arr.dtype.type, flexible):
if typename not in ['unicode','string','void']:
- typename = arr.dtype.__name__
+ typename = arr.dtype.type.__name__
typename = "(%s,%d)" % (typename, arr.itemsize)
return cName + "(%s, dtype=%s)" % (lst, typename)
@@ -149,7 +149,7 @@ def _add_types():
name = a.lower()
if isinstance(typeinfo[a], type(())):
typeobj = typeinfo[a][-1]
-
+
# define C-name and insert typenum and typechar references also
allTypes[name] = typeobj
typeDict[name] = typeobj
@@ -313,7 +313,7 @@ def obj2dtype(rep, default=None):
if isinstance(rep, type):
return _python_type(rep)
if isinstance(rep, ndarray):
- return rep.dtype
+ return rep.dtype.type
res = typeDict.get(rep, default)
return res
@@ -371,7 +371,7 @@ def dtype2char(dtype):
if issubclass(key, allTypes['flexible']):
_typestr[key] = _dtype2char_dict[key]
else:
- _typestr[key] = empty((1,),key).dtypestr[1:]
+ _typestr[key] = empty((1,),key).dtype.str[1:]
# Now add the types we've determined to this module
for key in allTypes:
Oops, something went wrong.

0 comments on commit 0283b6f

Please sign in to comment.