3
���h�9 � @ s0 d Z ddljjZddljjZddlmZm Z ddl
mZ ddlm
Z
dddd d
ddd
dg Zejd�Zdd� Zdd� Zdd� Zdd� Zdd� Zee�dd� �Zee�dd� �Zee�dd
� �Zdd� Zee�dd � �Zee�d d� �Zd!d"� Zee�d#d� �Zee�d$d� �Zee�d%d
� �Zee�d&d� �ZdS )'aD
Wrapper functions to more user-friendly calling of certain math functions
whose output data-type is different than the input data-type in certain
domains of the input.
For example, for functions like `log` with branch cuts, the versions in this
module provide the mathematically valid answers in the complex plane::
>>> import math
>>> from numpy.lib import scimath
>>> scimath.log(-math.exp(1)) == (1+1j*math.pi)
True
Similarly, `sqrt`, other base logarithms, `power` and trig functions are
correctly handled. See their respective docstrings for specific examples.
� N)�asarray�any)�array_function_dispatch)�isreal�sqrt�log�log2�logn�log10�power�arccos�arcsin�arctanhg @c C sB t | jjtjtjtjtjtjtj f�r2| j
tj �S | j
tj�S dS )a_ Convert its input `arr` to a complex array.
The input is returned as a complex array of the smallest type that will fit
the original data: types like single, byte, short, etc. become csingle,
while others become cdouble.
A copy of the input is always made.
Parameters
----------
arr : array
Returns
-------
array
An array with the same input data as the input but in complex form.
Examples
--------
First, consider an input of type short:
>>> a = np.array([1,2,3],np.short)
>>> ac = np.lib.scimath._tocomplex(a); ac
array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64)
>>> ac.dtype
dtype('complex64')
If the input is of type double, the output is correspondingly of the
complex double type as well:
>>> b = np.array([1,2,3],np.double)
>>> bc = np.lib.scimath._tocomplex(b); bc
array([1.+0.j, 2.+0.j, 3.+0.j])
>>> bc.dtype
dtype('complex128')
Note that even if the input was complex to begin with, a copy is still
made, since the astype() method always copies:
>>> c = np.array([1,2,3],np.csingle)
>>> cc = np.lib.scimath._tocomplex(c); cc
array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64)
>>> c *= 2; c
array([2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64)
>>> cc
array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64)
N)�
issubclassZdtype�type�ntZsingleZbyte�shortZubyteZushortZcsingleZastypeZcdouble)Zarr� r �2/tmp/pip-build-5_djhm0z/numpy/numpy/lib/scimath.py�
_tocomplex" |