- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.3k
lessons: actually use allocated buffers in Step12 lesson #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -221,7 +221,7 @@ | |
| "outputs": [], | ||
| "source": [ | ||
| "def pressure_poisson_periodic(p, dx, dy):\n", | ||
| " pn = numpy.empty_like(p)\n", | ||
| " pn[:] = numpy.empty_like(p)\n", | ||
| " \n", | ||
| " for q in range(nit):\n", | ||
| " pn = p.copy()\n", | ||
|  | @@ -313,10 +313,10 @@ | |
| "stepcount = 0\n", | ||
| "\n", | ||
| "while udiff > .001:\n", | ||
| " un = u.copy()\n", | ||
| " vn = v.copy()\n", | ||
| " un[:] = u.copy()\n", | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you allocate a temporary copy and then copy it again into  Would suggest this instead (fastest without allocation):  | ||
| " vn[:] = v.copy()\n", | ||
| "\n", | ||
| " b = build_up_b(rho, dt, dx, dy, u, v)\n", | ||
| " b[:] = build_up_b(rho, dt, dx, dy, u, v)\n", | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 to improve the performance here you would need to refactor   | ||
| " p = pressure_poisson_periodic(p, dx, dy)\n", | ||
| "\n", | ||
| " u[1:-1, 1:-1] = (un[1:-1, 1:-1] -\n", | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pndoesn’t exist yet, sopn[:] = ...will raise an erroreven if it did exist, you’d just be copying junk from a freshly allocated array into
pn—no gain here