summaryrefslogtreecommitdiff
path: root/scipy/base/scimath.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2005-09-14 22:28:28 +0000
committerTravis Oliphant <oliphant@enthought.com>2005-09-14 22:28:28 +0000
commit61b48697e440f76b2337c790ec5ca763cd55200b (patch)
treeda64ece2ba0b6b97deb51c36ca320c64102e9baa /scipy/base/scimath.py
parent575d373479c63a42bc4a729a058da31a74e75d3e (diff)
downloadnumpy-61b48697e440f76b2337c790ec5ca763cd55200b.tar.gz
Moving things to live under scipy
Diffstat (limited to 'scipy/base/scimath.py')
-rw-r--r--scipy/base/scimath.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/scipy/base/scimath.py b/scipy/base/scimath.py
new file mode 100644
index 000000000..b53c89f3f
--- /dev/null
+++ b/scipy/base/scimath.py
@@ -0,0 +1,75 @@
+"""
+Wrapper functions to more user-friendly calling of certain math functions
+whose output is different than the input in certain domains of the input.
+"""
+
+__all__ = ['sqrt', 'log', 'log2','logn','log10', 'power', 'arccos',
+ 'arcsin', 'arctanh']
+
+import numerix as _nx
+from numerix import *
+
+from type_check import isreal, asarray
+
+__all__.extend([key for key in dir(_nx.fastumath) \
+ if key[0]!='_' and key not in __all__])
+
+def _tocomplex(arr):
+ if arr.typecode() in ['f', 's', 'b', '1','w']:
+ return arr.astype('F')
+ else:
+ return arr.astype('D')
+
+def _fix_real_lt_zero(x):
+ x = asarray(x)
+ if any(isreal(x) & (x<0)):
+ x = _tocomplex(x)
+ return asscalar(x)
+
+def _fix_real_abs_gt_1(x):
+ x = asarray(x)
+ if any(isreal(x) & (abs(x)>1)):
+ x = _tocomplex(x)
+ return x
+
+def sqrt(x):
+ x = _fix_real_lt_zero(x)
+ return fastumath.sqrt(x)
+
+def log(x):
+ x = _fix_real_lt_zero(x)
+ return fastumath.log(x)
+
+def log10(x):
+ x = _fix_real_lt_zero(x)
+ return fastumath.log10(x)
+
+def logn(n,x):
+ """ Take log base n of x.
+ """
+ x = _fix_real_lt_zero(x)
+ n = _fix_real_lt_zero(n)
+ return fastumath.log(x)/fastumath.log(n)
+
+def log2(x):
+ """ Take log base 2 of x.
+ """
+ x = _fix_real_lt_zero(x)
+ return fastumath.log(x)/fastumath.log(2)
+
+def power(x, p):
+ x = _fix_real_lt_zero(x)
+ return fastumath.power(x, p)
+
+
+def arccos(x):
+ x = _fix_real_abs_gt_1(x)
+ return fastumath.arccos(x)
+
+def arcsin(x):
+ x = _fix_real_abs_gt_1(x)
+ return fastumath.arcsin(x)
+
+def arctanh(x):
+ x = _fix_real_abs_gt_1(x)
+ return fastumath.arctanh(x)