Skip to content

Commit

Permalink
Tutorial: fix numpy deprecation warning
Browse files Browse the repository at this point in the history
Numpy 1.26.2 now complains about casting a Python integer to a numpy
dtype for which it is out of range. Work around that by first converting
to np.int_.
  • Loading branch information
bmerry committed Jan 23, 2024
1 parent 8d0ee69 commit f6d5125
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions doc/tut-4-send-perf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ following:
.. code-block:: python
:dedent: 0
item_group["adc_samples"].value = np.full(heap_size, i, np.int8)
item_group["adc_samples"].value = np.full(heap_size, np.int_(i), np.int8)
.. code-block:: c++
:dedent: 0

std::fill(adc_samples.begin(), adc_samples.end(), i);

We're filling each heap with the loop index — not particularly meaningful for
simulation, but it has the bonus that we can easily see on the receiver side
if we've accidentally transmitted data for the wrong heap.
We're filling each heap with the loop index (truncated to an 8-bit integer) —
not particularly meaningful for simulation, but it has the bonus that we can
easily see on the receiver side if we've accidentally transmitted data for the
wrong heap.

This dramatically improves performance: around 1400 MB/s for Python and 1600
MB/s for C++ — assuming you're running the receiver. Somewhat surprisingly,
Expand Down
2 changes: 1 addition & 1 deletion examples/tut_4_send_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main():
start = time.perf_counter()
for i in range(n_heaps):
item_group["timestamp"].value = i * heap_size
item_group["adc_samples"].value = np.full(heap_size, i, np.int8)
item_group["adc_samples"].value = np.full(heap_size, np.int_(i), np.int8)
heap = item_group.get_heap()
stream.send_heap(heap)
elapsed = time.perf_counter() - start
Expand Down
2 changes: 1 addition & 1 deletion examples/tut_5_send_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def main():
for i in range(n_heaps):
new_state = State()
item_group["timestamp"].value = i * heap_size
item_group["adc_samples"].value = np.full(heap_size, i, np.int8)
item_group["adc_samples"].value = np.full(heap_size, np.int_(i), np.int8)
heap = item_group.get_heap()
new_state.future = stream.async_send_heap(heap)
if old_state is not None:
Expand Down
2 changes: 1 addition & 1 deletion examples/tut_6_send_pktsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def main():
for i in range(n_heaps):
new_state = State()
item_group["timestamp"].value = i * heap_size
item_group["adc_samples"].value = np.full(heap_size, i, np.int8)
item_group["adc_samples"].value = np.full(heap_size, np.int_(i), np.int8)
heap = item_group.get_heap()
new_state.future = stream.async_send_heap(heap)
if old_state is not None:
Expand Down
2 changes: 1 addition & 1 deletion examples/tut_8_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def main():
for i in range(n_heaps):
state = states[i % len(states)]
await state.future # Wait for any previous use of this state to complete
state.adc_samples.fill(i)
state.adc_samples.fill(np.int_(i))
item_group["timestamp"].value = i * heap_size
item_group["adc_samples"].value = state.adc_samples
heap = item_group.get_heap()
Expand Down

0 comments on commit f6d5125

Please sign in to comment.