Here are the examples of the python api numpy.complex128 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
591 Examples
5
Source : fft.py
with GNU General Public License v3.0
from nucypher
with GNU General Public License v3.0
from nucypher
def fft512(use_constant_memory=False):
module = Module(
TEMPLATE.get_def('fft512'),
render_kwds=dict(
elem_ctype=dtypes.ctype(numpy.complex128),
temp_ctype=dtypes.ctype(numpy.float64),
cdata_ctype=dtypes.ctype(numpy.complex128),
polar_unit=functions.polar_unit(numpy.float64),
mul=functions.mul(numpy.complex128, numpy.complex128),
use_constant_memory=use_constant_memory,
))
return FFT512(module, use_constant_memory)
def fft512_requirements():
3
Source : test_umath.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_division_complex(self):
# check that implementation is correct
msg = "Complex division implementation check"
x = np.array([1. + 1.*1j, 1. + .5*1j, 1. + 2.*1j], dtype=np.complex128)
assert_almost_equal(x**2/x, x, err_msg=msg)
# check overflow, underflow
msg = "Complex division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = x**2/x
assert_almost_equal(y/x, [1, 1], err_msg=msg)
def test_zero_division_complex(self):
3
Source : test_umath.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_floor_division_complex(self):
# check that implementation is correct
msg = "Complex floor division implementation check"
x = np.array([.9 + 1j, -.1 + 1j, .9 + .5*1j, .9 + 2.*1j], dtype=np.complex128)
y = np.array([0., -1., 0., 0.], dtype=np.complex128)
assert_equal(np.floor_divide(x**2, x), y, err_msg=msg)
# check overflow, underflow
msg = "Complex floor division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = np.floor_divide(x**2, x)
assert_equal(y, [1.e+110, 0], err_msg=msg)
def floor_divide_and_remainder(x, y):
3
Source : test_eval.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_result_types2(self):
# xref https://github.com/pandas-dev/pandas/issues/12293
pytest.skip("unreliable tests on complex128")
# Did not test complex64 because DataFrame is converting it to
# complex128. Due to https://github.com/pandas-dev/pandas/issues/10952
self.check_result_type(np.complex128, np.complex128)
def test_undefined_func(self):
3
Source : test_coercion.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_setitem_series_complex128(self, val, exp_dtype):
obj = pd.Series([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j])
assert obj.dtype == np.complex128
exp = pd.Series([1 + 1j, val, 3 + 3j, 4 + 4j])
self._assert_setitem_series_conversion(obj, val, exp, exp_dtype)
@pytest.mark.parametrize("val,exp_dtype", [
3
Source : test_coercion.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_where_int64(self, klass, fill_val, exp_dtype):
if klass is pd.Index and exp_dtype is np.complex128:
pytest.skip("Complex Index not supported")
obj = klass([1, 2, 3, 4])
assert obj.dtype == np.int64
cond = klass([True, False, True, False])
exp = klass([1, fill_val, 3, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = klass([True, False, True, True])
else:
values = klass(x * fill_val for x in [5, 6, 7, 8])
exp = klass([1, values[1], 3, values[3]])
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize("klass", [pd.Series, pd.Index],
3
Source : test_coercion.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_where_float64(self, klass, fill_val, exp_dtype):
if klass is pd.Index and exp_dtype is np.complex128:
pytest.skip("Complex Index not supported")
obj = klass([1.1, 2.2, 3.3, 4.4])
assert obj.dtype == np.float64
cond = klass([True, False, True, False])
exp = klass([1.1, fill_val, 3.3, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = klass([True, False, True, True])
else:
values = klass(x * fill_val for x in [5, 6, 7, 8])
exp = klass([1.1, values[1], 3.3, values[3]])
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize("fill_val,exp_dtype", [
3
Source : test_coercion.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_where_series_complex128(self, fill_val, exp_dtype):
obj = pd.Series([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j])
assert obj.dtype == np.complex128
cond = pd.Series([True, False, True, False])
exp = pd.Series([1 + 1j, fill_val, 3 + 3j, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = pd.Series([True, False, True, True])
else:
values = pd.Series(x * fill_val for x in [5, 6, 7, 8])
exp = pd.Series([1 + 1j, values[1], 3 + 3j, values[3]])
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize("fill_val,exp_dtype", [
3
Source : test_packers.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_dict_numpy_complex(self):
x = {'foo': np.complex128(1.0 + 1.0j),
'bar': np.complex128(2.0 + 2.0j)}
x_rec = self.encode_decode(x)
tm.assert_dict_equal(x, x_rec)
for key in x:
tm.assert_class_equal(x[key], x_rec[key], obj="numpy complex128")
def test_numpy_array_float(self):
3
Source : test_pytables.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_complex_indexing_error(self):
complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j],
dtype=np.complex128)
df = DataFrame({'A': [1, 2, 3, 4],
'B': ['a', 'b', 'c', 'd'],
'C': complex128},
index=list('abcd'))
with ensure_clean_store(self.path) as store:
pytest.raises(TypeError, store.append,
'df', df, data_columns=['C'])
def test_complex_series_error(self):
3
Source : test_pytables.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_complex_append(self):
df = DataFrame({'a': np.random.randn(100).astype(np.complex128),
'b': np.random.randn(100)})
with ensure_clean_store(self.path) as store:
store.append('df', df, data_columns=['b'])
store.append('df', df)
result = store.select('df')
assert_frame_equal(pd.concat([df, df], 0), result)
class TestTimezones(Base):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_fft(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_1d(fft, dtype, (16,), -1, overwritable)
self._check_1d(fft, dtype, (16, 2), 0, overwritable)
self._check_1d(fft, dtype, (2, 16), 1, overwritable)
def test_ifft(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_ifft(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_1d(ifft, dtype, (16,), -1, overwritable)
self._check_1d(ifft, dtype, (16, 2), 0, overwritable)
self._check_1d(ifft, dtype, (2, 16), 1, overwritable)
def test_rfft(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_fftn(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_nd(fftn, dtype, overwritable)
def test_ifftn(self):
3
Source : test_idl.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_pointers(self):
s = readsav(path.join(DATA_PATH, 'scalar_heap_pointer.sav'), verbose=False)
assert_identical(s.c64_pointer1, np.complex128(1.1987253647623157e+112-5.1987258887729157e+307j))
assert_identical(s.c64_pointer2, np.complex128(1.1987253647623157e+112-5.1987258887729157e+307j))
assert_(s.c64_pointer1 is s.c64_pointer2)
class TestPointerArray:
3
Source : interpolative.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def _is_real(A):
try:
if A.dtype == np.complex128:
return False
elif A.dtype == np.float64:
return True
else:
raise _DTYPE_ERROR
except AttributeError:
raise _TYPE_ERROR
def seed(seed=None):
3
Source : test_cython_blas.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_double_complex_args(self):
cx = np.array([.5 + 1.j, .25 - .375j, 13. - 4.j], np.complex128)
cy = np.array([.875 + 2.j, .875 - .625j, -1. + 2.j], np.complex128)
assert_equal(blas._test_izamax(cx), 3)
assert_allclose(blas._test_zdotc(cx, cy), -18.109375+22.296875j, 10)
assert_allclose(blas._test_zdotu(cx, cy), -6.578125+31.390625j, 10)
assert_allclose(blas._test_zdotc(cx[::2], cy[::2]),
-18.5625+22.125j, 10)
assert_allclose(blas._test_zdotu(cx[::2], cy[::2]),
-6.5625+31.875j, 10)
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_complex(self):
x = np.zeros(16, np.complex128)
x[0] = 1.0 + 2.0j
f, p = periodogram(x, return_onesided=False)
assert_allclose(f, fftpack.fftfreq(16, 1.0))
q = 5.0*np.ones(16)/16.0
q[0] = 0
assert_allclose(p, q)
def test_unk_scaling(self):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_complex(self):
x = np.zeros(16, np.complex128)
x[0] = 1.0 + 2.0j
x[8] = 1.0 + 2.0j
f, p = welch(x, nperseg=8, return_onesided=False)
assert_allclose(f, fftpack.fftfreq(8, 1.0))
q = np.array([0.41666667, 0.38194444, 0.55555556, 0.55555556,
0.55555556, 0.55555556, 0.55555556, 0.38194444])
assert_allclose(p, q, atol=1e-7, rtol=1e-7)
def test_unk_scaling(self):
3
Source : test_spectral.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_complex(self):
x = np.zeros(16, np.complex128)
x[0] = 1.0 + 2.0j
x[8] = 1.0 + 2.0j
f, p = csd(x, x, nperseg=8, return_onesided=False)
assert_allclose(f, fftpack.fftfreq(8, 1.0))
q = np.array([0.41666667, 0.38194444, 0.55555556, 0.55555556,
0.55555556, 0.55555556, 0.55555556, 0.38194444])
assert_allclose(p, q, atol=1e-7, rtol=1e-7)
def test_unk_scaling(self):
3
Source : test_matfuncs.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_padecases_dtype_sparse_complex(self):
# float32 and complex64 lead to errors in spsolve/UMFpack
dtype = np.complex128
for scale in [1e-2, 1e-1, 5e-1, 1, 10]:
a = scale * speye(3, 3, dtype=dtype, format='csc')
e = exp(scale) * eye(3, dtype=dtype)
with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning,
"Changing the sparsity structure of a csc_matrix is expensive.")
assert_array_almost_equal_nulp(expm(a).toarray(), e, nulp=100)
def test_logm_consistency(self):
3
Source : test_basic.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_sph_harm_ufunc_loop_selection():
# see https://github.com/scipy/scipy/issues/4895
dt = np.dtype(np.complex128)
assert_equal(special.sph_harm(0, 0, 0, 0).dtype, dt)
assert_equal(special.sph_harm([0], 0, 0, 0).dtype, dt)
assert_equal(special.sph_harm(0, [0], 0, 0).dtype, dt)
assert_equal(special.sph_harm(0, 0, [0], 0).dtype, dt)
assert_equal(special.sph_harm(0, 0, 0, [0]).dtype, dt)
assert_equal(special.sph_harm([0], [0], [0], [0]).dtype, dt)
class TestStruve(object):
3
Source : test_lambertw.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_lambertw_ufunc_loop_selection():
# see https://github.com/scipy/scipy/issues/4895
dt = np.dtype(np.complex128)
assert_equal(lambertw(0, 0, 0).dtype, dt)
assert_equal(lambertw([0], 0, 0).dtype, dt)
assert_equal(lambertw(0, [0], 0).dtype, dt)
assert_equal(lambertw(0, 0, [0]).dtype, dt)
assert_equal(lambertw([0], [0], [0]).dtype, dt)
3
Source : sumrate_BER.py
with GNU General Public License v3.0
from Agrim9
with GNU General Public License v3.0
from Agrim9
def get_candidates(H,Es):
candidates=np.zeros(shape=(256,4),dtype=np.complex128)
for i in range(256):
bit_stream=np.array(list(np.binary_repr(i).zfill(8))).astype(np.int8)
bpsk_stream=2*bit_stream-1
combined=np.hsplit(bpsk_stream,4)
comp_vec=np.array([(combined[j][0]+1j*combined[j][1])*(Es/np.sqrt(2)) for j in range(4)])
candidates[i]=np.matmul(H,comp_vec)
return candidates
3
Source : catch22.py
with BSD 3-Clause "New" or "Revised" License
from alan-turing-institute
with BSD 3-Clause "New" or "Revised" License
from alan-turing-institute
def _multiply_complex_arr(X_fft):
c = np.zeros(len(X_fft), dtype=np.complex128)
for i, n in enumerate(X_fft):
c[i] = n * (n.real + 1j * -n.imag)
return c
@njit(fastmath=True, cache=True)
3
Source : test_umath.py
with Apache License 2.0
from awslabs
with Apache License 2.0
from awslabs
def test_floor_division_complex(self):
# check that implementation is correct
msg = "Complex floor division implementation check"
x = np.array([.9 + 1j, -.1 + 1j, .9 + .5*1j, .9 + 2.*1j], dtype=np.complex128)
y = np.array([0., -1., 0., 0.], dtype=np.complex128)
assert_equal(np.floor_divide(x**2, x), y, err_msg=msg)
# check overflow, underflow
msg = "Complex floor division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = np.floor_divide(x**2, x)
assert_equal(y, [1.e+110, 0], err_msg=msg)
def test_floor_division_signed_zero(self):
3
Source : test_propagation.py
with MIT License
from brandondube
with MIT License
from brandondube
def test_can_mul_wavefronts():
data = np.random.rand(2, 2).astype(np.complex128)
wf = propagation.Wavefront(cmplx_field=data, dx=1, wavelength=.6328)
wf2 = wf * 2
assert wf2
def test_can_div_wavefronts():
3
Source : test_propagation.py
with MIT License
from brandondube
with MIT License
from brandondube
def test_can_div_wavefronts():
data = np.random.rand(2, 2).astype(np.complex128)
wf = propagation.Wavefront(cmplx_field=data, dx=1, wavelength=.6328)
wf2 = wf / 2
assert wf2
def test_precomputed_angular_spectrum_functions():
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_fft_ifft(self, dtype, fftsize, overwrite_x, shape, axes):
overwritable = (np.complex128, np.complex64)
self._check_1d(fft, dtype, shape, axes, overwritable,
fftsize, overwrite_x)
self._check_1d(ifft, dtype, shape, axes, overwritable,
fftsize, overwrite_x)
@pytest.mark.parametrize('dtype', real_dtypes)
3
Source : test_basic.py
with MIT License
from buds-lab
with MIT License
from buds-lab
def test_fftn_ifftn(self, dtype, overwrite_x, shape, axes):
overwritable = (np.complex128, np.complex64)
self._check_nd_one(fftn, dtype, shape, axes, overwritable,
overwrite_x)
self._check_nd_one(ifftn, dtype, shape, axes, overwritable,
overwrite_x)
3
Source : test_io.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_complex_negative_exponent(self):
# Previous to 1.15, some formats generated x+-yj, gh 7895
ncols = 2
nrows = 2
a = np.zeros((ncols, nrows), dtype=np.complex128)
re = np.pi
im = np.e
a[:] = re - 1.0j * im
c = BytesIO()
np.savetxt(c, a, fmt='%.3e')
c.seek(0)
lines = c.readlines()
assert_equal(
lines,
[b' (3.142e+00-2.718e+00j) (3.142e+00-2.718e+00j)\n',
b' (3.142e+00-2.718e+00j) (3.142e+00-2.718e+00j)\n'])
def test_custom_writer(self):
3
Source : test_eval.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_result_complex128(self):
# xref https://github.com/pandas-dev/pandas/issues/12293
# this fails on Windows, apparently a floating point precision issue
# Did not test complex64 because DataFrame is converting it to
# complex128. Due to https://github.com/pandas-dev/pandas/issues/10952
self.check_result_type(np.complex128, np.complex128)
def test_undefined_func(self):
3
Source : test_coercion.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_setitem_series_complex128(self, val, exp_dtype):
obj = pd.Series([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j])
assert obj.dtype == np.complex128
exp = pd.Series([1 + 1j, val, 3 + 3j, 4 + 4j])
self._assert_setitem_series_conversion(obj, val, exp, exp_dtype)
@pytest.mark.parametrize(
3
Source : test_coercion.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_where_int64(self, index_or_series, fill_val, exp_dtype):
klass = index_or_series
if klass is pd.Index and exp_dtype is np.complex128:
pytest.skip("Complex Index not supported")
obj = klass([1, 2, 3, 4])
assert obj.dtype == np.int64
cond = klass([True, False, True, False])
exp = klass([1, fill_val, 3, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = klass([True, False, True, True])
else:
values = klass(x * fill_val for x in [5, 6, 7, 8])
exp = klass([1, values[1], 3, values[3]])
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize(
3
Source : test_coercion.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_where_float64(self, index_or_series, fill_val, exp_dtype):
klass = index_or_series
if klass is pd.Index and exp_dtype is np.complex128:
pytest.skip("Complex Index not supported")
obj = klass([1.1, 2.2, 3.3, 4.4])
assert obj.dtype == np.float64
cond = klass([True, False, True, False])
exp = klass([1.1, fill_val, 3.3, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = klass([True, False, True, True])
else:
values = klass(x * fill_val for x in [5, 6, 7, 8])
exp = klass([1.1, values[1], 3.3, values[3]])
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize(
3
Source : test_coercion.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_where_series_complex128(self, fill_val, exp_dtype):
obj = pd.Series([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j])
assert obj.dtype == np.complex128
cond = pd.Series([True, False, True, False])
exp = pd.Series([1 + 1j, fill_val, 3 + 3j, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = pd.Series([True, False, True, True])
else:
values = pd.Series(x * fill_val for x in [5, 6, 7, 8])
exp = pd.Series([1 + 1j, values[1], 3 + 3j, values[3]])
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize(
3
Source : test_complex.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_complex_indexing_error(setup_path):
complex128 = np.array(
[1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j], dtype=np.complex128
)
df = DataFrame(
{"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128},
index=list("abcd"),
)
with ensure_clean_store(setup_path) as store:
with pytest.raises(TypeError):
store.append("df", df, data_columns=["C"])
def test_complex_series_error(setup_path):
3
Source : test_complex.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_complex_append(setup_path):
df = DataFrame(
{"a": np.random.randn(100).astype(np.complex128), "b": np.random.randn(100)}
)
with ensure_clean_store(setup_path) as store:
store.append("df", df, data_columns=["b"])
store.append("df", df)
result = store.select("df")
tm.assert_frame_equal(pd.concat([df, df], 0), result)
3
Source : test_spectral.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_complex(self):
x = np.zeros(16, np.complex128)
x[0] = 1.0 + 2.0j
f, p = periodogram(x, return_onesided=False)
assert_allclose(f, fftfreq(16, 1.0))
q = np.full(16, 5.0/16.0)
q[0] = 0
assert_allclose(p, q)
def test_unk_scaling(self):
3
Source : test_spectral.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_complex(self):
x = np.zeros(16, np.complex128)
x[0] = 1.0 + 2.0j
x[8] = 1.0 + 2.0j
f, p = welch(x, nperseg=8, return_onesided=False)
assert_allclose(f, fftfreq(8, 1.0))
q = np.array([0.41666667, 0.38194444, 0.55555556, 0.55555556,
0.55555556, 0.55555556, 0.55555556, 0.38194444])
assert_allclose(p, q, atol=1e-7, rtol=1e-7)
def test_unk_scaling(self):
3
Source : test_spectral.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_complex(self):
x = np.zeros(16, np.complex128)
x[0] = 1.0 + 2.0j
x[8] = 1.0 + 2.0j
f, p = csd(x, x, nperseg=8, return_onesided=False)
assert_allclose(f, fftfreq(8, 1.0))
q = np.array([0.41666667, 0.38194444, 0.55555556, 0.55555556,
0.55555556, 0.55555556, 0.55555556, 0.38194444])
assert_allclose(p, q, atol=1e-7, rtol=1e-7)
def test_unk_scaling(self):
3
Source : test_base.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_dot(self):
A = zeros((10, 10), np.complex128)
A[0, 3] = 10
A[5, 6] = 20j
B = lil_matrix((10, 10), dtype=np.complex128)
B[0, 3] = 10
B[5, 6] = 20j
# TODO: properly handle this assertion on ppc64le
if platform.machine() != 'ppc64le':
assert_array_equal(A @ A.T, (B * B.T).todense())
assert_array_equal(A @ A.conjugate().T, (B * B.H).todense())
def test_scalar_mul(self):
3
Source : csdm_indexing_test.py
with BSD 3-Clause "New" or "Revised" License
from deepanshs
with BSD 3-Clause "New" or "Revised" License
from deepanshs
def test_index_2():
l_test = a_obj[:, :, 0].astype(np.complex128)
assert l_test.shape == (10, 20)
assert l_test.dimensions[0] == d0
assert l_test.dimensions[1] == d1
assert np.allclose(l_test.dependent_variables[0].components, array[0, :, :])
assert l_test.dependent_variables[0].numeric_type == "complex128"
assert l_test.dependent_variables[0].components.dtype == np.complex128
assert str(l_test.dependent_variables[0].unit) == "A"
assert l_test.description == "This is a test."
save_and_load(l_test)
def test_index_3():
3
Source : test_coercion.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_where_series_complex128(self, fill_val, exp_dtype):
klass = pd.Series
obj = klass([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j])
assert obj.dtype == np.complex128
cond = klass([True, False, True, False])
exp = klass([1 + 1j, fill_val, 3 + 3j, fill_val])
self._assert_where_conversion(obj, cond, fill_val, exp, exp_dtype)
if fill_val is True:
values = klass([True, False, True, True])
else:
values = klass(x * fill_val for x in [5, 6, 7, 8])
exp = klass([1 + 1j, values[1], 3 + 3j, values[3]], dtype=exp_dtype)
self._assert_where_conversion(obj, cond, values, exp, exp_dtype)
@pytest.mark.parametrize(
3
Source : test_complex.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_complex_append(setup_path):
df = DataFrame(
{"a": np.random.randn(100).astype(np.complex128), "b": np.random.randn(100)}
)
with ensure_clean_store(setup_path) as store:
store.append("df", df, data_columns=["b"])
store.append("df", df)
result = store.select("df")
tm.assert_frame_equal(pd.concat([df, df], axis=0), result)
3
Source : circuit.py
with Apache License 2.0
from epiqc
with Apache License 2.0
from epiqc
def pick_long_idle_channel(self, state, buffer, index):
weights = []
for gate_error_matrix in self.long_idle_channel_operators:
gate_error_matrix = gate_error_matrix.astype(np.complex128).reshape((3,) * 2)
linalg.targeted_left_multiply(gate_error_matrix, state[:], [index], out=buffer)
weights.append(np.linalg.norm(buffer) ** 2)
index = weighted_draw(weights)
return self.short_idle_channel_operators[index]
def pick_short_idle_channel(self, state, buffer, index):
3
Source : circuit.py
with Apache License 2.0
from epiqc
with Apache License 2.0
from epiqc
def pick_short_idle_channel(self, state, buffer, index):
weights = []
for gate_error_matrix in self.short_idle_channel_operators:
gate_error_matrix = gate_error_matrix.astype(np.complex128).reshape((3,) * 2)
linalg.targeted_left_multiply(gate_error_matrix, state[:], [index], out=buffer)
weights.append(np.linalg.norm(buffer) ** 2)
index = weighted_draw(weights)
return self.long_idle_channel_operators[index]
class CurrentSuperconductingQCErrors(GenericQutritErrors):
3
Source : merge_interactions.py
with Apache License 2.0
from epiqc
with Apache License 2.0
from epiqc
def _flip_kron_order(mat4x4: np.ndarray) -> np.ndarray:
"""Given M = sum(kron(a_i, b_i)), returns M' = sum(kron(b_i, a_i))."""
result = np.array([[0] * 4] * 4, dtype=np.complex128)
order = [0, 2, 1, 3]
for i in range(4):
for j in range(4):
result[order[i], order[j]] = mat4x4[i, j]
return result
3
Source : merge_single_qubit_gates.py
with Apache License 2.0
from epiqc
with Apache License 2.0
from epiqc
def _merge_into_matrix_gate_op(qubit: ops.QubitId,
operations: Iterable[ops.Operation]
) -> ops.Operation:
matrix = linalg.dot(
np.eye(2, dtype=np.complex128),
*(reversed([protocols.unitary(op) for op in operations]))
)
return ops.SingleQubitMatrixGate(matrix).on(qubit)
3
Source : merge_rotations.py
with Apache License 2.0
from epiqc
with Apache License 2.0
from epiqc
def _merge_rotations(
self,
qubit: ops.QubitId,
operations: Iterable[ops.Operation]
) -> List[ops.Operation]:
matrix = linalg.dot(
np.eye(2, dtype=np.complex128),
*reversed([protocols.unitary(op) for op in operations]))
out_gates = single_qubit_matrix_to_native_gates(matrix, self.tolerance)
return [gate(qubit) for gate in out_gates]
See More Examples