Skip to main content
Code Review

Return to Answer

PQueue
Source Link
J_H
  • 41.7k
  • 3
  • 38
  • 157

Maintaining a priority queue of "big" cells ( ≥ 4 ) might help the algorithm to focus on dispersal in the central cells, at least initially.


The ⊔ trough function could perhaps be better named. Putting particles on top, falling into the abyss of NaNs on the side, seems more like a ⊓ table function, maybe? Not sure what the best name would be.

The ⊔ trough function could perhaps be better named. Putting particles on top, falling into the abyss of NaNs on the side, seems more like a ⊓ table function, maybe? Not sure what the best name would be.

Maintaining a priority queue of "big" cells ( ≥ 4 ) might help the algorithm to focus on dispersal in the central cells, at least initially.


The ⊔ trough function could perhaps be better named. Putting particles on top, falling into the abyss of NaNs on the side, seems more like a ⊓ table function, maybe? Not sure what the best name would be.

mention a 4X speedup
Source Link
J_H
  • 41.7k
  • 3
  • 38
  • 157

EDIT

Yup, sure enough, if I deposit a quarter million particles on an otherwise zero surface of 100 x 100, using this code we see a 4 X speedup thanks to arithmetic.

 k = 12
 while np.nanmax(P) >= 4:
 for i, j in np.ndindex(sP):
 if P[i, j] >= 4 * k and not np.isnan(P[i, j]):
 P[i, j] -= 4 * k
 P[i + 1, j] += k
 P[i - 1, j] += k
 P[i, j + 1] += k
 P[i, j - 1] += k
 if P[i, j] >= 4 and not np.isnan(P[i, j]):
 P[i, j] -= 4
 P[i + 1, j] += 1 ...

EDIT

Yup, sure enough, if I deposit a quarter million particles on an otherwise zero surface of 100 x 100, using this code we see a 4 X speedup thanks to arithmetic.

 k = 12
 while np.nanmax(P) >= 4:
 for i, j in np.ndindex(sP):
 if P[i, j] >= 4 * k and not np.isnan(P[i, j]):
 P[i, j] -= 4 * k
 P[i + 1, j] += k
 P[i - 1, j] += k
 P[i, j + 1] += k
 P[i, j - 1] += k
 if P[i, j] >= 4 and not np.isnan(P[i, j]):
 P[i, j] -= 4
 P[i + 1, j] += 1 ...
added 217 characters in body
Source Link
J_H
  • 41.7k
  • 3
  • 38
  • 157

The ⊔ trough function could perhaps be better named. Putting particles on top, falling into the abyss of NaNs on the side, seems more like a ⊓ table function, maybe? Not sure what the best name would be.


The ⊔ trough function could perhaps be better named. Putting particles on top, falling into the abyss of NaNs on the side, seems more like a ⊓ table function, maybe? Not sure what the best name would be.

Source Link
J_H
  • 41.7k
  • 3
  • 38
  • 157
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /