(array, shape, subok, readonly)
| 338 | |
| 339 | |
| 340 | def _broadcast_to(array, shape, subok, readonly): |
| 341 | shape = tuple(shape) if np.iterable(shape) else (shape,) |
| 342 | array = np.array(array, copy=False, subok=subok) |
| 343 | if not shape and array.shape: |
| 344 | raise ValueError('cannot broadcast a non-scalar to a scalar array') |
| 345 | if any(size < 0 for size in shape): |
| 346 | raise ValueError('all elements of broadcast shape must be non-' |
| 347 | 'negative') |
| 348 | extras = [] |
| 349 | it = np.nditer( |
| 350 | (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras, |
| 351 | op_flags=['readonly'], itershape=shape, order='C') |
| 352 | with it: |
| 353 | # never really has writebackifcopy semantics |
| 354 | broadcast = it.itviews[0] |
| 355 | result = _maybe_view_as_subclass(array, broadcast) |
| 356 | # In a future version this will go away |
| 357 | if not readonly and array.flags._writeable_no_warn: |
| 358 | result.flags.writeable = True |
| 359 | result.flags._warn_on_write = True |
| 360 | return result |
| 361 | |
| 362 | |
| 363 | def _broadcast_to_dispatcher(array, shape, subok=None): |
no test coverage detected