summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2007-02-01 20:34:56 +0000
committerTravis Oliphant <oliphant@enthought.com>2007-02-01 20:34:56 +0000
commit4a56cabed8811301838d2bbc67482bbc8ae56135 (patch)
treebd22be2517edd18bb976f9d60a15a1b5dc73e06f /numpy/lib
parentc1bcd900a33726ff05cab668bf03207a4e0614ca (diff)
downloadnumpy-4a56cabed8811301838d2bbc67482bbc8ae56135.tar.gz
Allow matrices to pass through more functions.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/type_check.py24
-rw-r--r--numpy/lib/ufunclike.py6
2 files changed, 16 insertions, 14 deletions
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 1571c2e6c..265b071fc 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -6,7 +6,8 @@ __all__ = ['iscomplexobj','isrealobj','imag','iscomplex',
'common_type']
import numpy.core.numeric as _nx
-from numpy.core.numeric import asarray, array, isnan, obj2sctype, zeros
+from numpy.core.numeric import asarray, asanyarray, array, isnan, \
+ obj2sctype, zeros
from ufunclike import isneginf, isposinf
_typecodes_by_elsize = 'GDFgdfQqLlIiHhBb?'
@@ -45,22 +46,21 @@ def asfarray(a, dtype=_nx.float_):
dtype = _nx.obj2sctype(dtype)
if not issubclass(dtype, _nx.inexact):
dtype = _nx.float_
- a = asarray(a,dtype=dtype)
- return a
+ return asanyarray(a,dtype=dtype)
def real(val):
"""Return the real part of val.
Useful if val maybe a scalar or an array.
"""
- return asarray(val).real
+ return asanyarray(val).real
def imag(val):
"""Return the imaginary part of val.
Useful if val maybe a scalar or an array.
"""
- return asarray(val).imag
+ return asanyarray(val).imag
def iscomplex(x):
"""Return a boolean array where elements are True if that element
@@ -68,7 +68,7 @@ def iscomplex(x):
For scalars, return a boolean.
"""
- ax = asarray(x)
+ ax = asanyarray(x)
if issubclass(ax.dtype.type, _nx.complexfloating):
return ax.imag != 0
res = zeros(ax.shape, bool)
@@ -105,7 +105,7 @@ def _getmaxmin(t):
def nan_to_num(x):
"""
- Replaces NaN's with 0 and infinities with large numbers
+ Returns a copy of replacing NaN's with 0 and Infs with large numbers
The following mappings are applied:
NaN -> 0
@@ -118,10 +118,12 @@ def nan_to_num(x):
t = obj2sctype(type(x))
if issubclass(t, _nx.complexfloating):
y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)
- elif issubclass(t, _nx.integer):
- y = array(x)
else:
- y = array(x)
+ try:
+ y = x.copy()
+ except AttributeError:
+ y = array(x)
+ if not issubclass(t, _nx.integer):
if not y.shape:
y = array([x])
scalar = True
@@ -146,7 +148,7 @@ def real_if_close(a,tol=100):
"Close enough" is defined as tol*(machine epsilon of a's element type).
"""
- a = asarray(a)
+ a = asanyarray(a)
if not issubclass(a.dtype.type, _nx.complexfloating):
return a
if tol > 1:
diff --git a/numpy/lib/ufunclike.py b/numpy/lib/ufunclike.py
index 509756a1f..cf014e77d 100644
--- a/numpy/lib/ufunclike.py
+++ b/numpy/lib/ufunclike.py
@@ -5,13 +5,13 @@ storing results in an output array.
__all__ = ['fix', 'isneginf', 'isposinf', 'log2']
import numpy.core.numeric as nx
-from numpy.core.numeric import asarray, empty, isinf, signbit
+from numpy.core.numeric import asarray, empty, isinf, signbit, asanyarray
import numpy.core.umath as umath
def fix(x, y=None):
""" Round x to nearest integer towards zero.
"""
- x = asarray(x)
+ x = asanyarray(x)
if y is None:
y = nx.floor(x)
else:
@@ -49,7 +49,7 @@ def log2(x, y=None):
If y is an array, the result replaces the contents of y.
"""
- x = asarray(x)
+ x = asanyarray(x)
if y is None:
y = umath.log(x)
else: