Python numpy.csingle() Examples
The following are 30
code examples of numpy.csingle().
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_linalg.py From Computable with MIT License | 5 votes |
def get_rtol(dtype): # Choose a safe rtol if dtype in (single, csingle): return 1e-5 else: return 1e-11
Example #2
Source File: test_type_check.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_basic(self): ai32 = np.array([[1, 2], [3, 4]], dtype=np.int32) af16 = np.array([[1, 2], [3, 4]], dtype=np.float16) af32 = np.array([[1, 2], [3, 4]], dtype=np.float32) af64 = np.array([[1, 2], [3, 4]], dtype=np.float64) acs = np.array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=np.csingle) acd = np.array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=np.cdouble) assert_(common_type(ai32) == np.float64) assert_(common_type(af16) == np.float16) assert_(common_type(af32) == np.float32) assert_(common_type(af64) == np.float64) assert_(common_type(acs) == np.csingle) assert_(common_type(acd) == np.cdouble)
Example #3
Source File: test_linalg.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def get_complex_dtype(dtype): return {single: csingle, double: cdouble, csingle: csingle, cdouble: cdouble}[dtype]
Example #4
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def get_real_dtype(dtype): return {single: single, double: double, csingle: single, cdouble: double}[dtype]
Example #5
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def get_complex_dtype(dtype): return {single: csingle, double: cdouble, csingle: csingle, cdouble: cdouble}[dtype]
Example #6
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw): if asarray(a).dtype.type in (single, csingle): decimal = single_decimal else: decimal = double_decimal old_assert_almost_equal(a, b, decimal=decimal, **kw)
Example #7
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_complex_boolean_cast(self): # Ticket #2218 for tp in [np.csingle, np.cdouble, np.clongdouble]: x = np.array([0, 0+0.5j, 0.5+0j], dtype=tp) assert_equal(x.astype(bool), np.array([0, 1, 1], dtype=bool)) assert_(np.any(x)) assert_(np.all(x[1:]))
Example #8
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_complex_scalar_complex_cast(self): for tp in [np.csingle, np.cdouble, np.clongdouble]: x = tp(1+2j) assert_equal(complex(x), 1+2j)
Example #9
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_complex_scalar_warning(self): for tp in [np.csingle, np.cdouble, np.clongdouble]: x = tp(1+2j) assert_warns(np.ComplexWarning, float, x) with suppress_warnings() as sup: sup.filter(np.ComplexWarning) assert_equal(float(x), float(x.real))
Example #10
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_precisions_consistent(self): z = 1 + 1j for f in self.funcs: fcf = f(np.csingle(z)) fcd = f(np.cdouble(z)) fcl = f(np.clongdouble(z)) assert_almost_equal(fcf, fcd, decimal=6, err_msg='fch-fcd %s' % f) assert_almost_equal(fcl, fcd, decimal=15, err_msg='fch-fcl %s' % f)
Example #11
Source File: test_io.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_array(self): a = np.array([], float) self.check_roundtrips(a) a = np.array([[1, 2], [3, 4]], float) self.check_roundtrips(a) a = np.array([[1, 2], [3, 4]], int) self.check_roundtrips(a) a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.csingle) self.check_roundtrips(a) a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.cdouble) self.check_roundtrips(a)
Example #12
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) u, s, vh = linalg.svd(x) assert_equal(u.dtype, dtype) assert_equal(s.dtype, get_real_dtype(dtype)) assert_equal(vh.dtype, dtype) s = linalg.svd(x, compute_uv=False) assert_equal(s.dtype, get_real_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #13
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) w, v = np.linalg.eig(x) assert_equal(w.dtype, dtype) assert_equal(v.dtype, dtype) x = np.array([[1, 0.5], [-1, 1]], dtype=dtype) w, v = np.linalg.eig(x) assert_equal(w.dtype, get_complex_dtype(dtype)) assert_equal(v.dtype, get_complex_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #14
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) assert_equal(linalg.eigvals(x).dtype, dtype) x = np.array([[1, 0.5], [-1, 1]], dtype=dtype) assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #15
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) assert_equal(linalg.inv(x).dtype, dtype) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #16
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) assert_equal(np.linalg.det(x).dtype, dtype) ph, s = np.linalg.slogdet(x) assert_equal(s.dtype, get_real_dtype(dtype)) assert_equal(ph.dtype, dtype) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #17
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def get_complex_dtype(dtype): return {single: csingle, double: cdouble, csingle: csingle, cdouble: cdouble}[dtype]
Example #18
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def get_real_dtype(dtype): return {single: single, double: double, csingle: single, cdouble: double}[dtype]
Example #19
Source File: test_linalg.py From Computable with MIT License | 5 votes |
def assert_almost_equal(a, b, **kw): if asarray(a).dtype.type in (single, csingle): decimal = 6 else: decimal = 12 old_assert_almost_equal(a, b, decimal=decimal, **kw)
Example #20
Source File: test_io.py From Computable with MIT License | 5 votes |
def test_array(self): a = np.array([[1, 2], [3, 4]], float) self.roundtrip(a) a = np.array([[1, 2], [3, 4]], int) self.roundtrip(a) a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.csingle) self.roundtrip(a) a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.cdouble) self.roundtrip(a)
Example #21
Source File: test_regression.py From vnpy_crypto with MIT License | 5 votes |
def test_complex_scalar_complex_cast(self): for tp in [np.csingle, np.cdouble, np.clongdouble]: x = tp(1+2j) assert_equal(complex(x), 1+2j)
Example #22
Source File: test_regression.py From vnpy_crypto with MIT License | 5 votes |
def test_complex_scalar_warning(self): for tp in [np.csingle, np.cdouble, np.clongdouble]: x = tp(1+2j) assert_warns(np.ComplexWarning, float, x) with suppress_warnings() as sup: sup.filter(np.ComplexWarning) assert_equal(float(x), float(x.real))
Example #23
Source File: test_umath.py From vnpy_crypto with MIT License | 5 votes |
def test_precisions_consistent(self): z = 1 + 1j for f in self.funcs: fcf = f(np.csingle(z)) fcd = f(np.cdouble(z)) fcl = f(np.clongdouble(z)) assert_almost_equal(fcf, fcd, decimal=6, err_msg='fch-fcd %s' % f) assert_almost_equal(fcl, fcd, decimal=15, err_msg='fch-fcl %s' % f)
Example #24
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) w, v = np.linalg.eigh(x) assert_equal(w.dtype, get_real_dtype(dtype)) assert_equal(v.dtype, dtype) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #25
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) w = np.linalg.eigvalsh(x) assert_equal(w.dtype, get_real_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #26
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) u, s, vh = linalg.svd(x) assert_equal(u.dtype, dtype) assert_equal(s.dtype, get_real_dtype(dtype)) assert_equal(vh.dtype, dtype) s = linalg.svd(x, compute_uv=False) assert_equal(s.dtype, get_real_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #27
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) w, v = np.linalg.eig(x) assert_equal(w.dtype, dtype) assert_equal(v.dtype, dtype) x = np.array([[1, 0.5], [-1, 1]], dtype=dtype) w, v = np.linalg.eig(x) assert_equal(w.dtype, get_complex_dtype(dtype)) assert_equal(v.dtype, get_complex_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #28
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) assert_equal(linalg.eigvals(x).dtype, dtype) x = np.array([[1, 0.5], [-1, 1]], dtype=dtype) assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype)) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #29
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) assert_equal(linalg.inv(x).dtype, dtype) for dtype in [single, double, csingle, cdouble]: yield check, dtype
Example #30
Source File: test_linalg.py From vnpy_crypto with MIT License | 5 votes |
def test_types(self): def check(dtype): x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype) assert_equal(linalg.solve(x, x).dtype, dtype) for dtype in [single, double, csingle, cdouble]: yield check, dtype