Here are the examples of the python api numpy.copyto taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
81 Examples
5
View Complete Implementation : lwe_cpu.py
Copyright GNU General Public License v3.0
Author : nucypher
Copyright GNU General Public License v3.0
Author : nucypher
def LweLinearReference(result_shape_info, source_shape_info, add_result=False):
def _kernel(result_a, result_b, result_cv, source_a, source_b, source_cv, p):
p = Torus32(p)
numpy.copyto(result_a, (result_a if add_result else 0) + p * source_a)
numpy.copyto(result_b, (result_b if add_result else 0) + p * source_b)
numpy.copyto(result_cv, (result_cv if add_result else 0) + p**2 * source_cv)
return _kernel
3
View Complete Implementation : ArrayUtils.py
Copyright MIT License
Author : adamrehn
Copyright MIT License
Author : adamrehn
def arrayCast(source, dtype):
"""
Casts a NumPy array to the specified datatype, storing the copy
in memory if there is sufficient available space or else using a
memory-mapped temporary file to provide the underlying buffer.
"""
# Determine the number of bytes required to store the array
requiredBytes = _requiredSize(source.shape, dtype)
# Determine if there is sufficient available memory
vmem = psutil.virtual_memory()
if vmem.available > requiredBytes:
return source.astype(dtype, subok=False)
else:
dest = arrayFactory(source.shape, dtype)
np.copyto(dest, source, casting='unsafe')
return dest
3
View Complete Implementation : tensorrt.py
Copyright MIT License
Author : autorope
Copyright MIT License
Author : autorope
def run(self, image):
# Channel first image format
image = image.transpose((2,0,1))
# Flatten it to a 1D array.
image = image.ravel()
# The first input is the image. Copy to host memory.
image_input = self.inputs[0]
np.copyto(image_input.host_memory, image)
with self.engine.create_execution_context() as context:
[throttle, steering] = TensorRTLinear.infer(context=context, bindings=self.bindings, inputs=self.inputs, outputs=self.outputs, stream=self.stream)
return steering[0], throttle[0]
3
View Complete Implementation : numpy_backend.py
Copyright Apache License 2.0
Author : Blueqat
Copyright Apache License 2.0
Author : Blueqat
def prepare(self, cache):
"""Prepare to run next shot."""
if cache is not None:
np.copyto(self.qubits, cache)
else:
self.qubits.fill(0.0)
self.qubits[0] = 1.0
self.cregs = [0] * self.n_qubits
3
View Complete Implementation : numpy_backend.py
Copyright Apache License 2.0
Author : Blueqat
Copyright Apache License 2.0
Author : Blueqat
def gate_cx(self, gate, ctx):
qubits = ctx.qubits
newq = ctx.qubits_buf
n_qubits = ctx.n_qubits
i = ctx.indices
for control, target in gate.control_target_iter(n_qubits):
np.copyto(newq, qubits)
c1 = (i & (1 << control)) != 0
t0 = (i & (1 << target)) == 0
t1 = (i & (1 << target)) != 0
newq[c1 & t0] = qubits[c1 & t1]
newq[c1 & t1] = qubits[c1 & t0]
qubits, newq = newq, qubits
ctx.qubits = qubits
ctx.qubits_buf = newq
return ctx
3
View Complete Implementation : numpy_backend.py
Copyright Apache License 2.0
Author : Blueqat
Copyright Apache License 2.0
Author : Blueqat
def gate_crx(self, gate, ctx):
qubits = ctx.qubits
newq = ctx.qubits_buf
n_qubits = ctx.n_qubits
i = ctx.indices
halftheta = gate.theta / 2
for control, target in gate.control_target_iter(n_qubits):
np.copyto(newq, qubits)
c1 = (i & (1 << control)) != 0
c1t0 = ((i & (1 << target)) == 0) & c1
c1t1 = ((i & (1 << target)) != 0) & c1
newq[c1t0] = np.cos(halftheta) * qubits[c1t0] -1j * np.sin(halftheta) * qubits[c1t1]
newq[c1t1] = -1j * np.sin(halftheta) * qubits[c1t0] + np.cos(halftheta) * qubits[c1t1]
qubits, newq = newq, qubits
ctx.qubits = qubits
ctx.qubits_buf = newq
return ctx
3
View Complete Implementation : numpy_backend.py
Copyright Apache License 2.0
Author : Blueqat
Copyright Apache License 2.0
Author : Blueqat
def gate_cry(self, gate, ctx):
qubits = ctx.qubits
newq = ctx.qubits_buf
n_qubits = ctx.n_qubits
i = ctx.indices
theta = gate.theta
for control, target in gate.control_target_iter(n_qubits):
np.copyto(newq, qubits)
c1 = (i & (1 << control)) != 0
c1t0 = ((i & (1 << target)) == 0) & c1
c1t1 = ((i & (1 << target)) != 0) & c1
newq[c1t0] = np.cos(theta / 2) * qubits[c1t0] - np.sin(theta / 2) * qubits[c1t1]
newq[c1t1] = np.sin(theta / 2) * qubits[c1t0] + np.cos(theta / 2) * qubits[c1t1]
qubits, newq = newq, qubits
ctx.qubits = qubits
ctx.qubits_buf = newq
return ctx
3
View Complete Implementation : agents.py
Copyright MIT License
Author : BYU-PCCL
Copyright MIT License
Author : BYU-PCCL
def set_physics_state(self, location, rotation, velocity, angular_velocity):
"""Sets the location, rotation, velocity and angular velocity of an agent.
Args:
location (np.ndarray): New location (``[x, y, z]`` (see :ref:`coordinate-system`))
rotation (np.ndarray): New rotation (``[roll, pitch, yaw]``, see (see :ref:`rotations`))
velocity (np.ndarray): New velocity (``[x, y, z]`` (see :ref:`coordinate-system`))
angular_velocity (np.ndarray): New angular velocity (``[x, y, z]`` in **degrees**
(see :ref:`coordinate-system`))
"""
np.copyto(self._teleport_buffer[0:3], location)
np.copyto(self._teleport_buffer[3:6], rotation)
np.copyto(self._teleport_buffer[6:9], velocity)
np.copyto(self._teleport_buffer[9:12], angular_velocity)
self._teleport_type_buffer[0] = 15
3
View Complete Implementation : agents.py
Copyright MIT License
Author : BYU-PCCL
Copyright MIT License
Author : BYU-PCCL
def __act__(self, action):
if self._current_control_scheme is ControlSchemes.SPHERE_CONTINUOUS:
np.copyto(self._action_buffer, action)
elif self._current_control_scheme is ControlSchemes.SPHERE_DISCRETE:
# Move forward .185 meters (to match initial release)
# Turn 10/-10 degrees (to match initial release)
actions = np.array([[.185, 0], [-.185, 0], [0, 10], [0, -10]])
to_act = np.array(actions[action, :])
np.copyto(self._action_buffer, to_act)
3
View Complete Implementation : command.py
Copyright MIT License
Author : BYU-PCCL
Copyright MIT License
Author : BYU-PCCL
def _write_to_command_buffer(self, to_write):
"""Write input to the command buffer.
Reformat input string to the correct format.
Args:
to_write (:clast:`str`): The string to write to the command buffer.
"""
np.copyto(self._command_bool_ptr, True)
to_write += '0' # The gason JSON parser in holodeck expects a 0 at the end of the file.
input_bytes = str.encode(to_write)
if len(input_bytes) > self.max_buffer:
raise HolodeckException("Error: Command length exceeds buffer size")
for index, val in enumerate(input_bytes):
self._command_buffer_ptr[index] = val