Python numpy.arcsinh() Examples
The following are 30
code examples of numpy.arcsinh().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)
Example #2
Source File: test_umath.py From recruit with Apache License 2.0 | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
Example #3
Source File: relativity.py From tf-pose with Apache License 2.0 | 6 votes |
def hypTStep(dt, v0, x0, tau0, g): ## Hyperbolic step. ## If an object has proper acceleration g and starts at position x0 with speed v0 and proper time tau0 ## as seen from an inertial frame, then return the new v, x, tau after time dt has elapsed. if g == 0: return v0, x0 + v0*dt, tau0 + dt * (1. - v0**2)**0.5 v02 = v0**2 g2 = g**2 tinit = v0 / (g * (1 - v02)**0.5) B = (1 + (g2 * (dt+tinit)**2))**0.5 v1 = g * (dt+tinit) / B dtau = (np.arcsinh(g * (dt+tinit)) - np.arcsinh(g * tinit)) / g tau1 = tau0 + dtau x1 = x0 + (1.0 / g) * ( B - 1. / (1.-v02)**0.5 ) return v1, x1, tau1
Example #4
Source File: test_umath.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64 yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64 yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 # check against bogus branch cuts: assert continuity between quadrants yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64 yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64 yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64
Example #5
Source File: test_umath.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(np.complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #6
Source File: test_umath.py From vnpy_crypto with MIT License | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True # check against bogus branch cuts: assert continuity between quadrants yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1 yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1 yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1 yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1 yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1 yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1
Example #7
Source File: test_umath.py From vnpy_crypto with MIT License | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64 yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64 yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 # check against bogus branch cuts: assert continuity between quadrants yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64 yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64 yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64
Example #8
Source File: test_umath.py From vnpy_crypto with MIT License | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #9
Source File: test_umath.py From Computable with MIT License | 6 votes |
def test_against_cmath(self): import cmath, sys points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(np.complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s"%(fname, p, a, b))
Example #10
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)
Example #11
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
Example #12
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #13
Source File: test_umath.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)
Example #14
Source File: test_umath.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
Example #15
Source File: test_umath.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #16
Source File: test_umath.py From pySINDy with MIT License | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)
Example #17
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
Example #18
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #19
Source File: test_umath.py From recruit with Apache License 2.0 | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)
Example #20
Source File: test_umath.py From pySINDy with MIT License | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
Example #21
Source File: test_umath.py From pySINDy with MIT License | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #22
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_branch_cuts(self): # check branch cuts and continuity on them yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True # check against bogus branch cuts: assert continuity between quadrants yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1 yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1 yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1 yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1 yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1 yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1
Example #23
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True, np.complex64 yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64 yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64 yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64 yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64 # check against bogus branch cuts: assert continuity between quadrants yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64 yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64 yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64 yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64
Example #24
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_against_cmath(self): import cmath points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(np.complex).eps for func in self.funcs: fname = func.__name__.split('.')[-1] cname = name_map.get(fname, fname) try: cfunc = getattr(cmath, cname) except AttributeError: continue for p in points: a = complex(func(np.complex_(p))) b = cfunc(p) assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
Example #25
Source File: test_quantum.py From thewalrus with Apache License 2.0 | 6 votes |
def test_two_mode_squeezing(choi_r, tol): r"""Tests the selection rules of a two mode squeezing operation. If one writes the squeezing gate as :math:`S_2` and its matrix elements as :math:`\langle p_0 p_1|S_2|q_0 q_1 \rangle` then these elements are nonzero if and only if :math:`p_0 - q_0 = p_1 - q_1`. This test checks that this selection rule holds. """ cutoff = 5 nmodes = 2 s = np.arcsinh(1.0) phi = np.pi / 6 alphas = np.zeros([nmodes]) S = two_mode_squeezing(s, phi) T = fock_tensor(S, alphas, cutoff, choi_r=choi_r) for p in product(list(range(cutoff)), repeat=nmodes): for q in product(list(range(cutoff)), repeat=nmodes): if p[0] - q[0] != p[1] - q[1]: t = tuple(list(p) + list(q)) assert np.allclose(T[t], 0, atol=tol, rtol=0)
Example #26
Source File: test_symplectic.py From thewalrus with Apache License 2.0 | 6 votes |
def test_is_symplectic(): """ Tests that the matrices generated in the symplectic module are indeed symplectic""" theta = np.pi / 6 r = np.arcsinh(1.0) phi = np.pi / 8 S = symplectic.rotation(theta) assert symplectic.is_symplectic(S) S = symplectic.squeezing(r, theta) assert symplectic.is_symplectic(S) S = symplectic.beam_splitter(theta, phi) assert symplectic.is_symplectic(S) S = symplectic.two_mode_squeezing(r, theta) assert symplectic.is_symplectic(S) A = np.array([[2.0, 3.0], [4.0, 6.0]]) assert not symplectic.is_symplectic(A) A = np.identity(3) assert not symplectic.is_symplectic(A) A = np.array([[2.0, 3.0], [4.0, 6.0], [4.0, 6.0]]) assert not symplectic.is_symplectic(A)
Example #27
Source File: test_samples.py From thewalrus with Apache License 2.0 | 6 votes |
def test_single_squeezed_state_hafnian(self): """Test the sampling routines by comparing the photon number frequencies and the exact probability distribution of a single mode squeezed vacuum state """ n_samples = 1000 mean_n = 1.0 r = np.arcsinh(np.sqrt(mean_n)) sigma = np.array([[np.exp(2 * r), 0.0], [0.0, np.exp(-2 * r)]]) n_cut = 10 samples = hafnian_sample_state(sigma, samples=n_samples, cutoff=n_cut) bins = np.arange(0, max(samples) + 1, 1) (freq, _) = np.histogram(samples, bins=bins) rel_freq = freq / n_samples nm = max(samples) // 2 x = nbinom.pmf(np.arange(0, nm, 1), 0.5, np.tanh(np.arcsinh(np.sqrt(mean_n))) ** 2) x2 = np.zeros(2 * len(x)) x2[::2] = x rel_freq = freq[0:-1] / n_samples x2 = x2[0 : len(rel_freq)] assert np.allclose( rel_freq, x2, atol=rel_tol / np.sqrt(n_samples), rtol=rel_tol / np.sqrt(n_samples) )
Example #28
Source File: test_samples.py From thewalrus with Apache License 2.0 | 6 votes |
def test_single_squeezed_state_torontonian(self): """Test the sampling routines by comparing the photon number frequencies and the exact probability distribution of a single mode squeezed vacuum state """ n_samples = 10000 mean_n = 1.0 r = np.arcsinh(np.sqrt(mean_n)) sigma = np.array([[np.exp(2 * r), 0.0], [0.0, np.exp(-2 * r)]]) samples = torontonian_sample_state(sigma, samples=n_samples) samples_list = list(samples) rel_freq = np.array([samples_list.count(0), samples_list.count(1)]) / n_samples x2 = np.empty([2]) x2[0] = 1.0 / np.sqrt(1.0 + mean_n) x2[1] = 1.0 - x2[0] assert np.allclose( rel_freq, x2, atol=rel_tol / np.sqrt(n_samples), rtol=rel_tol / np.sqrt(n_samples) )
Example #29
Source File: test_fock_gradients.py From thewalrus with Apache License 2.0 | 6 votes |
def test_S2_selection_rules(tol): r"""Tests the selection rules of a two mode squeezing operation. If one writes the squeezing gate as :math:`S_2` and its matrix elements as :math:`\langle p_0 p_1|S_2|q_0 q_1 \rangle` then these elements are nonzero if and only if :math:`p_0 - q_0 = p_1 - q_1`. This test checks that this selection rule holds. """ cutoff = 5 s = np.arcsinh(1.0) phi = np.pi / 6 T = two_mode_squeezing(s, phi, cutoff) m = np.arange(cutoff).reshape(-1, 1, 1, 1) n = np.arange(cutoff).reshape(1, -1, 1, 1) k = np.arange(cutoff).reshape(1, 1, -1, 1) l = np.arange(cutoff).reshape(1, 1, 1, -1) # create a copy of T, but replace all elements where # m+n != k+l with 0. S = np.where(m - n != k - l, 0, T) # check that S and T remain equal assert np.allclose(S, T, atol=tol, rtol=0)
Example #30
Source File: samples.py From thewalrus with Apache License 2.0 | 6 votes |
def _hafnian_sample_graph_rank_one(G, n_mean): r"""Returns a sample from a rank one adjacency matrix `\bm{A} = \bm{G} \bm{G}^T` where :math:`\bm{G}` is a row vector. Args: G (array): factorization of the rank-one matrix A = G @ G.T. nmean (float): Total mean photon number. Returns: (array): sample. """ s = np.arcsinh(np.sqrt(n_mean)) q = 1.0 - np.tanh(s) ** 2 total_photon_num = 2 * np.random.negative_binomial(0.5, q, 1)[0] sample = np.zeros(len(G)) single_ph_ps = np.abs(G) ** 2 single_ph_ps /= np.sum(single_ph_ps) for _ in range(total_photon_num): detector = np.random.choice(len(G), p=single_ph_ps) sample[detector] += 1 return sample