(array, shape, subok, readonly)
| 445 | |
| 446 | |
| 447 | def _broadcast_to(array, shape, subok, readonly): |
| 448 | shape = tuple(shape) if np.iterable(shape) else (shape,) |
| 449 | array = np.array(array, copy=None, subok=subok) |
| 450 | if not shape and array.shape: |
| 451 | raise ValueError('cannot broadcast a non-scalar to a scalar array') |
| 452 | if any(size < 0 for size in shape): |
| 453 | raise ValueError('all elements of broadcast shape must be non-' |
| 454 | 'negative') |
| 455 | extras = [] |
| 456 | it = np.nditer( |
| 457 | (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras, |
| 458 | op_flags=['readonly'], itershape=shape, order='C') |
| 459 | with it: |
| 460 | # never really has writebackifcopy semantics |
| 461 | broadcast = it.itviews[0] |
| 462 | result = _maybe_view_as_subclass(array, broadcast) |
| 463 | # In a future version this will go away |
| 464 | if not readonly and array.flags._writeable_no_warn: |
| 465 | result.flags.writeable = True |
| 466 | result.flags._warn_on_write = True |
| 467 | return result |
| 468 | |
| 469 | |
| 470 | def _broadcast_to_dispatcher(array, shape, subok=None): |
no test coverage detected
searching dependent graphs…