本文整理汇总了Python中numpy.complex64函数的典型用法代码示例。如果您正苦于以下问题:Python complex64函数的具体用法?Python complex64怎么用?Python complex64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了complex64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCountingLoopHandrolledC64
def testCountingLoopHandrolledC64(self):
# Define a function for the loop body
@function.Defun(dtypes.int32, dtypes.complex64)
def loop_body(step, rsum):
step_out = step + constant_op.constant(1, dtype=dtypes.int32)
sum_out = rsum + constant_op.constant(1.5 + 2j, dtype=dtypes.complex64)
return step_out, sum_out
# Define a function for the loop condition
@function.Defun(dtypes.int32, dtypes.complex64)
def loop_cond(step, rsum):
del rsum
return step < 10
with self.cached_session() as sess:
init_index = array_ops.placeholder(dtypes.int32, [])
init_sum = array_ops.placeholder(dtypes.complex64, [])
with self.test_scope():
loop_outputs = xla.while_loop([init_index, init_sum], loop_cond,
loop_body)
result = sess.run(loop_outputs, {init_index: 0, init_sum: 0.0})
self.assertAllClose(result[1], np.complex64(15 + 20j), rtol=1e-3)
no_iters_result = sess.run(loop_outputs, {init_index: 10, init_sum: 0.0})
self.assertAllClose(no_iters_result[1], np.complex64(0), rtol=1e-3)
示例2: test_cublasCgemmBatched
def test_cublasCgemmBatched(self):
l, m, k, n = 11, 7, 5, 3
A = (np.random.rand(l, m, k)+1j*np.random.rand(l, m, k)).astype(np.complex64)
B = (np.random.rand(l, k, n)+1j*np.random.rand(l, k, n)).astype(np.complex64)
C_res = np.einsum('nij,njk->nik', A, B)
a_gpu = gpuarray.to_gpu(A)
b_gpu = gpuarray.to_gpu(B)
c_gpu = gpuarray.empty((l, m, n), np.complex64)
alpha = np.complex64(1.0)
beta = np.complex64(0.0)
a_arr = bptrs(a_gpu)
b_arr = bptrs(b_gpu)
c_arr = bptrs(c_gpu)
cublas.cublasCgemmBatched(self.cublas_handle, 'n','n',
n, m, k, alpha,
b_arr.gpudata, n,
a_arr.gpudata, k,
beta, c_arr.gpudata, n, l)
assert np.allclose(C_res, c_gpu.get())
示例3: runTest
def runTest(self):
node_list = ['n1', 'n2', 'n3']
V = np.complex64(( 1.02500000+0.0j, 1.00057074-0.03669173j, 1.02970624+0.0245978j))
phase = np.complex64((0.0, -0.03665437, 0.02388363))
P = np.complex64((1.00010597, -4.0, 3.0))
Q = np.complex64((0.90512173, -2.0, 1.36935805))
netlist = Netlist()
# Check values are close to what we expect
try:
netlist.load_from_file("testing/inputfile2.txt")
netlist.run()
# print abs(netlist.result.V)- abs(V)
print netlist.result.V
print netlist.result.P
# assert (np.allclose(netlist.result.V, V, rtol=1e-3, atol=1e-3))
# assert (np.allclose(netlist.result.phase, phase, rtol=1e-3, atol=1e-3))
# assert (np.allclose(netlist.result.P, P, rtol=1e-3, atol=1e-3))
# assert (np.allclose(netlist.result.Q, Q, rtol=1e-3, atol=1e-3))
finally:
del netlist
示例4: test_numpy
def test_numpy(self):
assert chash(np.bool_(True)) == chash(np.bool_(True))
assert chash(np.int8(1)) == chash(np.int8(1))
assert chash(np.int16(1))
assert chash(np.int32(1))
assert chash(np.int64(1))
assert chash(np.uint8(1))
assert chash(np.uint16(1))
assert chash(np.uint32(1))
assert chash(np.uint64(1))
assert chash(np.float32(1)) == chash(np.float32(1))
assert chash(np.float64(1)) == chash(np.float64(1))
assert chash(np.float128(1)) == chash(np.float128(1))
assert chash(np.complex64(1+1j)) == chash(np.complex64(1+1j))
assert chash(np.complex128(1+1j)) == chash(np.complex128(1+1j))
assert chash(np.complex256(1+1j)) == chash(np.complex256(1+1j))
assert chash(np.datetime64('2000-01-01')) == chash(np.datetime64('2000-01-01'))
assert chash(np.timedelta64(1,'W')) == chash(np.timedelta64(1,'W'))
self.assertRaises(ValueError, chash, np.object())
assert chash(np.array([[1, 2], [3, 4]])) == \
chash(np.array([[1, 2], [3, 4]]))
assert chash(np.array([[1, 2], [3, 4]])) != \
chash(np.array([[1, 2], [3, 4]]).T)
assert chash(np.array([1, 2, 3])) == chash(np.array([1, 2, 3]))
assert chash(np.array([1, 2, 3], dtype=np.int32)) != \
chash(np.array([1, 2, 3], dtype=np.int64))
示例5: test_dump_np_scalars
def test_dump_np_scalars():
data = [
int8(-27),
complex64(exp(1)+37j),
(
{
'alpha': float64(-exp(10)),
'str-only': complex64(-1-1j),
},
uint32(123456789),
float16(exp(-1)),
{
int64(37),
uint64(-0),
},
),
]
replaced = encode_scalars_inplace(deepcopy(data))
json = dumps(replaced)
rec = loads(json)
print(data)
print(rec)
assert data[0] == rec[0]
assert data[1] == rec[1]
assert data[2][0] == rec[2][0]
assert data[2][1] == rec[2][1]
assert data[2][2] == rec[2][2]
assert data[2][3] == rec[2][3]
assert data[2] == tuple(rec[2])
示例6: __get_excit_wfm
def __get_excit_wfm(filepath):
"""
Returns the excitation BE waveform present in the more parms.mat file
Parameters
------------
filepath : String / unicode
Absolute filepath of the .mat parameter file
Returns
-----------
ex_wfm : 1D numpy float array
Band Excitation waveform
"""
if not path.exists(filepath):
warn('BEPSndfTranslator - NO more_parms.mat file found')
return np.zeros(1000, dtype=np.float32)
if 'more_parms' in filepath:
matread = loadmat(filepath, variable_names=['FFT_BE_wave'])
fft_full = np.complex64(np.squeeze(matread['FFT_BE_wave']))
bin_inds = None
fft_full_rev = None
else:
matread = loadmat(filepath, variable_names=['FFT_BE_wave', 'FFT_BE_rev_wave', 'BE_bin_ind'])
bin_inds = np.uint(np.squeeze(matread['BE_bin_ind'])) - 1
fft_full = np.complex64(np.squeeze(matread['FFT_BE_wave']))
fft_full_rev = np.complex64(np.squeeze(matread['FFT_BE_rev_wave']))
return fft_full, fft_full_rev, bin_inds
示例7: test_arrays_replicated_3d
def test_arrays_replicated_3d(self):
s = readsav(path.join(DATA_PATH, 'struct_arrays_replicated_3d.sav'), verbose=False)
# Check column types
assert_(s.arrays_rep.a.dtype.type is np.object_)
assert_(s.arrays_rep.b.dtype.type is np.object_)
assert_(s.arrays_rep.c.dtype.type is np.object_)
assert_(s.arrays_rep.d.dtype.type is np.object_)
# Check column shapes
assert_equal(s.arrays_rep.a.shape, (4, 3, 2))
assert_equal(s.arrays_rep.b.shape, (4, 3, 2))
assert_equal(s.arrays_rep.c.shape, (4, 3, 2))
assert_equal(s.arrays_rep.d.shape, (4, 3, 2))
# Check values
for i in range(4):
for j in range(3):
for k in range(2):
assert_array_identical(s.arrays_rep.a[i, j, k],
np.array([1, 2, 3], dtype=np.int16))
assert_array_identical(s.arrays_rep.b[i, j, k],
np.array([4., 5., 6., 7.],
dtype=np.float32))
assert_array_identical(s.arrays_rep.c[i, j, k],
np.array([np.complex64(1+2j),
np.complex64(7+8j)]))
assert_array_identical(s.arrays_rep.d[i, j, k],
np.array([b"cheese", b"bacon", b"spam"],
dtype=np.object))
示例8: generate
def generate(self, width, height, real_axis_range, imag_axis_range, tasks):
if not is_gpu_accelerated():
self._logger.error(
'No GPU acceleration is available, please use CPU.')
return
iterations = np.empty(width * height, np.int32)
iterations_gpu = gpuarray.to_gpu(iterations)
z_values = np.empty(width * height, np.float32)
z_values_gpu = gpuarray.to_gpu(z_values)
cmin = complex(real_axis_range[0], imag_axis_range[0])
cmax = complex(real_axis_range[1], imag_axis_range[1])
dc = cmax - cmin
dx, mx = divmod(width, self._block_size[0])
dy, my = divmod(height, self._block_size[1])
grid_size = ((dx + (mx > 0)), (dy + (my > 0)))
self._get_pixel_iterations(
iterations_gpu, z_values_gpu,
np.int32(width), np.int32(height),
np.complex64(cmin), np.complex64(dc),
block=self._block_size, grid=grid_size)
return (iterations_gpu, z_values_gpu, abs(dc))
示例9: hiss_removal
def hiss_removal(audio):
pend = len(audio)-(4410+1102)
song = sonify(audio, 44100)
song.FrameGenerator().__next__()
song.window()
song.Spectrum()
noise_fft = song.fft(song.windowed_x)[:song.H+1]
noise_power = np.log10(np.abs(noise_fft + 2 ** -16))
noise_floor = np.exp(2.0 * noise_power.mean())
mn = song.magnitude_spectrum
e_n = energy(mn)
pin = 0
output = np.zeros(len(audio))
hold_time = 0
ca = 0
cr = 0
amp = audio.max()
while pin < pend:
selection = pin+2048
song.frame = audio[pin:selection]
song.window()
song.M = 2048
song.Spectrum()
e_m = energy(song.magnitude_spectrum)
SNR = 10 * np.log10(e_m / e_n)
ft = song.fft(song.windowed_x)[:song.H+1]
power_spectral_density = np.abs(ft) ** 2
song.Envelope()
song.AttackTime()
rel_time = rel(song.attack_time)
rel_coef = to_coef(rel_time, 44100)
at_coef = to_coef(song.attack_time, 44100)
ca = ca + song.attack_time
cr = cr + rel_time
if SNR > 0:
np.add.at(output, range(pin, selection), audio[pin:selection])
else:
if np.any(power_spectral_density < noise_floor):
gc = dyn_constraint_satis(ft, [power_spectral_density, noise_floor], 0.12589254117941673)
if ca > hold_time:
gc = np.complex64([at_coef * gc[i- 1] + (1 - at_coef) * x if x > gc[i- 1] else x for i,x in enumerate(gc)])
if ca <= hold_time:
gc = np.complex64([gc[i- 1] for i,x in enumerate(gc)])
if cr > hold_time:
gc = np.complex64([rel_coef * gc[i- 1] + (1 - rel_coef) * x if x <= gc[i- 1] else x for i,x in enumerate(gc)])
if cr <= hold_time:
gc = np.complex64([gc[i- 1] for i,x in enumerate(gc)])
print ("Reducing noise floor, this is taking some time")
song.Phase(song.fft(song.windowed_x))
song.phase = song.phase[:song.magnitude_spectrum.size]
ft *= gc
song.magnitude_spectrum = np.sqrt(pow(ft.real,2) + pow(ft.imag,2))
np.add.at(output, range(pin, selection), song.ISTFT(song.magnitude_spectrum))
else:
np.add.at(output, range(pin, selection), audio[pin:selection])
pin = pin + song.H
hold_time += selection/44100
hissless = amp * output / output.max() #amplify to normal level
return np.float32(hissless)
示例10: energy_density_at_origin
def energy_density_at_origin(k):
K = complex64(ellipk(k**2))
E = complex64(ellipe(k**2))
k1 = sqrt(1-k**2)
A = 32*(k**2 *(-K**2 * k**2 +E**2-4*E*K+3* K**2 + k**2)-2*(E-K)**2)**2/(k**8 * K**4 * k1**2)
return A.real
示例11: sc_complex_dot
def sc_complex_dot(x_gpu, y_gpu, c_gpu, transa='N', transb='N', handle=None):
"""
modified version of linalg.dot which allows for the target output array to be specified.
This function does not return anything.
"""
if handle is None:
handle = scikits.cuda.misc._global_cublas_handle
assert len(x_gpu.shape) == 2
assert len(y_gpu.shape) == 2
assert len(c_gpu.shape) == 2
assert x_gpu.dtype == np.complex64
assert y_gpu.dtype == np.complex64
assert c_gpu.dtype == np.complex64
# Get the shapes of the arguments
x_shape = x_gpu.shape
y_shape = y_gpu.shape
# Perform matrix multiplication for 2D arrays:
alpha = np.complex64(1.0)
beta = np.complex64(0.0)
transa = string.lower(transa)
transb = string.lower(transb)
if transb in ['t', 'c']:
m, k = y_shape
elif transb in ['n']:
k, m = y_shape
else:
raise ValueError('invalid value for transb')
if transa in ['t', 'c']:
l, n = x_shape
elif transa in ['n']:
n, l = x_shape
else:
raise ValueError('invalid value for transa')
if l != k:
raise ValueError('objects are not aligned')
if transb == 'n':
lda = max(1, m)
else:
lda = max(1, k)
if transa == 'n':
ldb = max(1, k)
else:
ldb = max(1, n)
ldc = max(1, m)
cublas.cublasCgemm(handle, transb, transa, m, n, k, alpha, y_gpu.gpudata,
lda, x_gpu.gpudata, ldb, beta, c_gpu.gpudata, ldc)
示例12: _update_filtered
def _update_filtered(self, translated):
if translated is not None and self._taps_n is not None and self._taps_p is not None:
filtered_data_1 = TimeData(numpy.complex64(scipy.signal.lfilter(self._taps_n, 1, translated.samples)), translated.sampling_rate)
filtered_data_2 = TimeData(numpy.complex64(scipy.signal.lfilter(self._taps_p, 1, translated.samples)), translated.sampling_rate)
self.eye_view.data = (filtered_data_1.abs, filtered_data_2.abs)
self.burst.filtered = TimeData(filtered_data_2.abs.samples - filtered_data_1.abs.samples, filtered_data_1.sampling_rate)
else:
self.eye_view.data = (None, None)
self.burst.filtered = None
示例13: __init__
def __init__(self,timeSeries=None,
lenSeries=2**18,
numChannels=1,
fMin=400,fMax=800,
sampTime=None,
noiseRMS=0.1):
""" Initializes the AmplitudeTimeSeries instance.
If a array is not passed, then a random whitenoise dataset is generated.
Inputs:
Len -- Number of time data points (usually a power of 2) 2^38 gives about 65 seconds
of 400 MHz sampled data
The time binning is decided by the bandwidth
fMin -- lowest frequency (MHz)
fMax -- highest frequency (MHz)
noiseRMS -- RMS value of noise (TBD)
noiseAlpha -- spectral slope (default is white noise) (TBD)
ONLY GENERATES WHITE NOISE RIGHT NOW!
"""
self.shape = (np.uint(numChannels),np.uint(lenSeries))
self.fMax = fMax
self.fMin = fMin
if sampTime is None:
self.sampTime = np.uint(numChannels)*1E-6/(fMax-fMin)
else:
self.sampTime = sampTime
if timeSeries is None:
# then use the rest of the data to generate a random timeseries
if VERBOSE:
print "AmplitudeTimeSeries __init__ did not get new data, generating white noise data"
self.timeSeries = np.complex64(noiseRMS*(np.float16(random.standard_normal(self.shape))
+np.float16(random.standard_normal(self.shape))*1j)/np.sqrt(2))
else:
if VERBOSE:
print "AmplitudeTimeSeries __init__ got new data, making sure it is reasonable."
if len(timeSeries.shape) == 1:
self.shape = (1,timeSeries.shape[0])
else:
self.shape = timeSeries.shape
self.timeSeries = np.reshape(np.complex64(timeSeries),self.shape)
self.fMin = fMin
self.fMax = fMax
if sampTime is None:
self.sampTime = numChannels*1E-6/(fMax-fMin)
else:
self.sampTime = sampTime
return None
示例14: add_vdot
def add_vdot(M, v, out, beta=0.0, transM='N', handle=None):
if handle is None:
handle = scm._global_cublas_handle
assert M.strides[1] <= M.strides[0], 'only C-order arrays supported'
transM = transM.lower()
if transM == 'n':
trans = 't'
m = M.shape[1]
n = M.shape[0]
alpha = 1.0
lda = M.strides[0] // M.dtype.itemsize
if v.shape[0] != M.shape[1] or out.shape[0] != M.shape[0]:
raise ValueError('dimension mismatch: %s %s %s' %
(M.shape, v.shape, out.shape))
elif transM == 't':
trans = 'n'
m = M.shape[1]
n = M.shape[0]
alpha = 1.0
lda = M.strides[0] // M.dtype.itemsize
if v.shape[0] != M.shape[0] or out.shape[0] != M.shape[1]:
raise ValueError('dimension mismatch: %s %s %s' %
(M.shape, v.shape, out.shape))
else:
raise ValueError('transM must be n or t')
if (M.dtype == np.complex64 and v.dtype == np.complex64):
cublas_func = scikits.cuda.cublas.cublasCgemv
alpha = np.complex64(alpha)
beta = np.complex64(beta)
elif (M.dtype == np.float32 and v.dtype == np.float32):
cublas_func = scikits.cuda.cublas.cublasSgemv
alpha = np.float32(alpha)
beta = np.float32(beta)
elif (M.dtype == np.complex128 and v.dtype == np.complex128):
cublas_func = scikits.cuda.cublas.cublasZgemv
alpha = np.complex128(alpha)
beta = np.complex128(beta)
elif (M.dtype == np.float64 and v.dtype == np.float64):
cublas_func = scikits.cuda.cublas.cublasDgemv
alpha = np.float64(alpha)
beta = np.float64(beta)
else:
raise ValueError('unsupported combination of input types')
incx = 1
incy = 1
cublas_func(handle,
trans, m, n,
alpha,
M.gpudata, lda,
v.gpudata, incx,
beta,
out.gpudata, incy)
示例15: test_compressed
def test_compressed(self):
s = idlsave.read(path.join(DATA_PATH, 'various_compressed.sav'), verbose=False)
assert_identical(s.i8u, np.uint8(234))
assert_identical(s.f32, np.float32(-3.1234567e+37))
assert_identical(s.c64, np.complex128(1.1987253647623157e+112-5.1987258887729157e+307j))
assert_equal(s.array5d.shape, (4, 3, 4, 6, 5))
assert_identical(s.arrays.a[0], np.array([1, 2, 3], dtype=np.int16))
assert_identical(s.arrays.b[0], np.array([4., 5., 6., 7.], dtype=np.float32))
assert_identical(s.arrays.c[0], np.array([np.complex64(1+2j), np.complex64(7+8j)]))
assert_identical(s.arrays.d[0], np.array(asbytes_nested(["cheese", "bacon", "spam"]), dtype=np.object))