Complete worked example
python
import numpy as np
def inspect_example(values):
if any(type(value) is not int or not -128 <= value <= 127 for value in values):
raise ValueError("expected int8-range whole counters")
stored = np.asarray(values, dtype=np.int8)
wide = stored.astype(np.int64)
return wide * 2- Reasoning
- The worked example validates a one-dimensional list of small whole-number counters, stores them as int8 to make the storage limit visible, and widens to int64 before doubling. The returned ndarray therefore preserves results such as 200 rather than wrapping them. Tests check int64 explicitly as well as the numerical answer. A wider dtype consumes more bytes per element, so this is a correctness decision with a measurable storage cost. Keep input validation separate from arithmetic. Values outside the declared storage range are rejected before construction; that rejection is not a technique for preventing overflow in every later expression. The later operation still needs an appropriate intermediate type.