boris-kz / CogAlg

This project is a Computer Vision implementation of general hierarchical pattern discovery principles introduced in README
http://www.cognitivealgorithm.info
MIT License
91 stars 41 forks source link

Skip-unpacking of selected tuple elements: for y,x, _, _, _, _ in P[2]: ... #23

Closed Twenkid closed 4 years ago

Twenkid commented 5 years ago

Do you know that syntax trick? Probably a bit faster, too. If there are elements of a tuple that won't be used, they could be skipped (readability ("remindability") could be preserved with a comment):

  for y, x, _, _, _, _ in P[2]: #   y, x, i, dy, dx, g
                    map[y, x] = True

instead of the full form:

  for y, x, i, dy, dx, g in P[2]:
                    map[y, x] = True

It could be done for any of the positions: for y, _, _, dy, _, g in P[2]:... etc.

https://stackoverflow.com/questions/9532576/ignore-part-of-a-python-tuple

https://github.com/boris-kz/CogAlg/blob/1ce8aa2c3e4bdcc0259ce2a8c6e83b6a1143a83e/frame_2D_alg/frame_blobs.py#L229

boris-kz commented 5 years ago

Thanks, I will keep that in mind. Right now it's mostly for "remindability", less clutter than comments. For speed, I plan to move to Julia when it gets too slow anyway.

On Wed, Mar 20, 2019 at 7:05 AM Todor Arnaudov notifications@github.com wrote:

Do you know that syntax trick? Probably a bit faster, too. If there are elements of a tuple that won't be used, they could be skipped (readability ("remindability") could be preserved with a comment):

for y, x, , , , in P[2]: # y, x, i, dy, dx, g map[y, x] = True

instead of the full form:

for y, x, i, dy, dx, g in P[2]: map[y, x] = True

It could be done for any of the positions: for y, , , dy, _, g in P[2]: ... etc.

https://stackoverflow.com/questions/9532576/ignore-part-of-a-python-tuple

https://github.com/boris-kz/CogAlg/blob/1ce8aa2c3e4bdcc0259ce2a8c6e83b6a1143a83e/frame_2D_alg/frame_blobs.py#L229

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/boris-kz/CogAlg/issues/23, or mute the thread https://github.com/notifications/unsubscribe-auth/AUAXGcAPV_pzois-Kb1QlGmuo-LPTYv_ks5vYhX1gaJpZM4b_CM4 .