def get_tm_opp(pts1, pts2):
# Transformation matrix - ( Translation + Scaling + Rotation )
# using Procuster analysis
pts1 = np.float64(pts1)
pts2 = np.float64(pts2)
m1 = np.mean(pts1, axis = 0)
m2 = np.mean(pts2, axis = 0)
# Removing translation
pts1 -= m1
pts2 -= m2
std1 = np.std(pts1)
std2 = np.std(pts2)
std_r = std2/std1
# Removing scaling
pts1 /= std1
pts2 /= std2
U, S, V = np.linalg.svd(np.transpose(pts1) * pts2)
# Finding the rotation matrix
R = np.transpose(U * V)
return np.vstack([np.hstack((std_r * R,
np.transpose(m2) - std_r * R * np.transpose(m1))), np.matrix([0.0, 0.0, 1.0])])
python类float64()的实例源码
def sample(self, probs, temperature):
if temperature == 0:
return np.argmax(probs)
probs = probs.astype(np.float64) #convert to float64 for higher precision
probs = np.log(probs) / temperature
probs = np.exp(probs) / math.fsum(np.exp(probs))
return np.argmax(np.random.multinomial(1, probs, 1))
#generate a sentence given conv_hidden
def test_FFT(FFT):
N = FFT.N
if FFT.rank == 0:
A = random(N).astype(FFT.float)
if FFT.communication == 'AlltoallN':
C = empty(FFT.global_complex_shape(), dtype=FFT.complex)
C = rfftn(A, C, axes=(0,1,2))
C[:, :, -1] = 0 # Remove Nyquist frequency
A = irfftn(C, A, axes=(0,1,2))
B2 = zeros(FFT.global_complex_shape(), dtype=FFT.complex)
B2 = rfftn(A, B2, axes=(0,1,2))
else:
A = zeros(N, dtype=FFT.float)
B2 = zeros(FFT.global_complex_shape(), dtype=FFT.complex)
atol, rtol = (1e-10, 1e-8) if FFT.float is float64 else (5e-7, 1e-4)
FFT.comm.Bcast(A, root=0)
FFT.comm.Bcast(B2, root=0)
a = zeros(FFT.real_shape(), dtype=FFT.float)
c = zeros(FFT.complex_shape(), dtype=FFT.complex)
a[:] = A[FFT.real_local_slice()]
c = FFT.fftn(a, c)
#print abs((c - B2[FFT.complex_local_slice()])/c.max()).max()
assert all(abs((c - B2[FFT.complex_local_slice()])/c.max()) < rtol)
#assert allclose(c, B2[FFT.complex_local_slice()], rtol, atol)
a = FFT.ifftn(c, a)
#print abs((a - A[FFT.real_local_slice()])/a.max()).max()
assert all(abs((a - A[FFT.real_local_slice()])/a.max()) < rtol)
#assert allclose(a, A[FFT.real_local_slice()], rtol, atol)
def datatypes(precision):
"""Return datatypes associated with precision."""
assert precision in ("single", "double")
return {"single": (np.float32, np.complex64, MPI.C_FLOAT_COMPLEX),
"double": (np.float64, np.complex128, MPI.C_DOUBLE_COMPLEX)}[precision]
def set_analog_power_up_states_with_output_type(
self, power_up_states):
"""
Updates power up states for analog physical channels.
Args:
power_up_states (List[nidaqmx.types.AOPowerUpState]):
Contains the physical channels and power up states to
set. Each element of the list contains a physical channel
and the power up state to set for that physical channel.
- physical_channel (str): Specifies the physical channel to
modify.
- power_up_state (float): Specifies the power up state
to set for the physical channel specified with the
**physical_channel** input.
- channel_type (:class:`nidaqmx.constants.AOPowerUpOutputBehavior`):
Specifies the output type for the physical channel
specified with the **physical_channel** input.
"""
physical_channel = flatten_channel_string(
[p.physical_channel for p in power_up_states])
state = numpy.float64(
[p.power_up_state for p in power_up_states])
channel_type = numpy.int32(
[p.channel_type.value for p in power_up_states])
cfunc = lib_importer.cdll.DAQmxSetAnalogPowerUpStatesWithOutputType
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')),
wrapped_ndpointer(dtype=numpy.int32,
flags=('C','W'))]
error_code = cfunc(
physical_channel, state, channel_type, len(power_up_states))
check_for_error(error_code)
def ao_power_amp_scaling_coeff(self):
"""
List[float]: Indicates the coefficients of a polynomial equation
used to scale from pre-amplified values.
"""
cfunc = lib_importer.windll.DAQmxGetAOPowerAmpScalingCoeff
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_bridge_rngs(self):
"""
List[float]: Indicates pairs of input voltage ratio ranges, in
volts per volt, supported by devices that acquire using
ratiometric measurements. Each pair consists of the low
value followed by the high value.
"""
cfunc = lib_importer.windll.DAQmxGetDevAIBridgeRngs
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_current_int_excit_discrete_vals(self):
"""
List[float]: Indicates the set of discrete internal current
excitation values supported by this device.
"""
cfunc = lib_importer.windll.DAQmxGetDevAICurrentIntExcitDiscreteVals
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_current_rngs(self):
"""
List[float]: Indicates the pairs of current input ranges
supported by this device. Each pair consists of the low
value, followed by the high value.
"""
cfunc = lib_importer.windll.DAQmxGetDevAICurrentRngs
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_dig_fltr_lowpass_cutoff_freq_discrete_vals(self):
"""
List[float]: Indicates the set of discrete lowpass cutoff
frequencies supported by this device. If the device supports
ranges of lowpass cutoff frequencies, use
AI.DigFltr.Lowpass.CutoffFreq.RangeVals to determine
supported frequencies.
"""
cfunc = (lib_importer.windll.
DAQmxGetDevAIDigFltrLowpassCutoffFreqDiscreteVals)
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_dig_fltr_lowpass_cutoff_freq_range_vals(self):
"""
List[float]: Indicates pairs of lowpass cutoff frequency ranges
supported by this device. Each pair consists of the low
value, followed by the high value. If the device supports a
set of discrete lowpass cutoff frequencies, use
AI.DigFltr.Lowpass.CutoffFreq.DiscreteVals to determine the
supported frequencies.
"""
cfunc = (lib_importer.windll.
DAQmxGetDevAIDigFltrLowpassCutoffFreqRangeVals)
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_freq_rngs(self):
"""
List[float]: Indicates the pairs of frequency input ranges
supported by this device. Each pair consists of the low
value, followed by the high value.
"""
cfunc = lib_importer.windll.DAQmxGetDevAIFreqRngs
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_lowpass_cutoff_freq_discrete_vals(self):
"""
List[float]: Indicates the set of discrete lowpass cutoff
frequencies supported by this device. If the device supports
ranges of lowpass cutoff frequencies, use
**ai_lowpass_cutoff_freq_range_vals** to determine supported
frequencies.
"""
cfunc = (lib_importer.windll.
DAQmxGetDevAILowpassCutoffFreqDiscreteVals)
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_resistance_rngs(self):
"""
List[float]: Indicates pairs of input resistance ranges, in
ohms, supported by devices that have the necessary signal
conditioning to measure resistances. Each pair consists of
the low value followed by the high value.
"""
cfunc = lib_importer.windll.DAQmxGetDevAIResistanceRngs
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_voltage_int_excit_discrete_vals(self):
"""
List[float]: Indicates the set of discrete internal voltage
excitation values supported by this device. If the device
supports ranges of internal excitation values, use
**ai_voltage_int_excit_range_vals** to determine supported
excitation values.
"""
cfunc = lib_importer.windll.DAQmxGetDevAIVoltageIntExcitDiscreteVals
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_voltage_int_excit_range_vals(self):
"""
List[float]: Indicates pairs of internal voltage excitation
ranges supported by this device. Each pair consists of the
low value, followed by the high value. If the device
supports a set of discrete internal excitation values, use
**ai_voltage_int_excit_discrete_vals** to determine the
supported excitation values.
"""
cfunc = lib_importer.windll.DAQmxGetDevAIVoltageIntExcitRangeVals
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ao_current_rngs(self):
"""
List[float]: Indicates pairs of output current ranges supported
by this device. Each pair consists of the low value,
followed by the high value.
"""
cfunc = lib_importer.windll.DAQmxGetDevAOCurrentRngs
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ao_gains(self):
"""
List[float]: Indicates the output gain settings supported by
this device.
"""
cfunc = lib_importer.windll.DAQmxGetDevAOGains
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()
def ai_bridge_poly_forward_coeff(self, val):
val = numpy.float64(val)
cfunc = lib_importer.windll.DAQmxSetAIBridgePolyForwardCoeff
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
error_code = cfunc(
self._handle, self._name, val, len(val))
check_for_error(error_code)
def ai_bridge_poly_reverse_coeff(self):
"""
List[float]: Specifies an list of coefficients for the
polynomial that converts physical values to electrical
values. Each element of the list corresponds to a term of
the equation. For example, if index three of the list is 9,
the fourth term of the equation is 9x^3.
"""
cfunc = lib_importer.windll.DAQmxGetAIBridgePolyReverseCoeff
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes_byte_str,
wrapped_ndpointer(dtype=numpy.float64,
flags=('C','W')), ctypes.c_uint]
temp_size = 0
while True:
val = numpy.zeros(temp_size, dtype=numpy.float64)
size_or_code = cfunc(
self._handle, self._name, val, temp_size)
if is_array_buffer_too_small(size_or_code):
# Buffer size must have changed between calls; check again.
temp_size = 0
elif size_or_code > 0 and temp_size == 0:
# Buffer size obtained, use to retrieve data.
temp_size = size_or_code
else:
break
check_for_error(size_or_code)
return val.tolist()