Commit 1ebf1c3
committed
Avoid unneeded copies from flatten().
flatten() always returns a new copy, but nearly all places that use
flatten() in the codebase don't need to pay that cost; the only place
that needed it did an additional copy. Fix them.
As a replacement, there's ravel(), which only makes a copy if the input
is not C-contiguous to start with, and reshape(..., -1) which never
makes a copy (as long as the input is already an ndarray), so prefer the
latter.
Note that in the changed snippet in mplot3d, the AttributeError would
never be raised, as x/y/z are converted to arrays and thus always have a
flatten() method.1 parent 2d05981 commit 1ebf1c3
2 files changed
Lines changed: 14 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
| 416 | + | |
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
422 | | - | |
| 422 | + | |
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
| |||
1758 | 1758 | | |
1759 | 1759 | | |
1760 | 1760 | | |
1761 | | - | |
| 1761 | + | |
1762 | 1762 | | |
1763 | 1763 | | |
1764 | | - | |
| 1764 | + | |
1765 | 1765 | | |
1766 | 1766 | | |
1767 | 1767 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
506 | 501 | | |
507 | | - | |
508 | | - | |
| 502 | + | |
509 | 503 | | |
510 | 504 | | |
511 | 505 | | |
| |||
0 commit comments