-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
faster version of _nwise #1572
Comments
@pkoppstein Very nice! Yeah, we should probably audit |
@nicowilliams - btw, since (a) _nwise isn’t documented and (b) it begins with |
I really hope def nwise($n): while(.!=[]; .[$n:])[:$n]; |
Agree, think it would be a good addition.
Neat implementation! Do we want it to work with strings? currently this one gets stuck with a string as input. |
Fixing this is easy. def nwise($n): while(length>0; .[$n:])[:$n]; |
shouldn't it be |
Good question, what to do on non-even length? think i would expect to get a short last output. Also need a check for $n > 0 i think? |
Please note that this issue (the efficiency of implementation of I left the issue open because of @itchyny's remark:
thus tying this issue to PR #2786, in which
(Since @nicowilliams suggested that As for the discussion about an implementation using |
Since the original intention of this issue is already resolved by #2641 (I've forgot this until now; please do not mixing things in a PR), I'm closing this issue. |
Here are plug-in replacements for the existing defs. These replacements use 0-arity filters to effect the recursion, and are ridiculously faster even for arrays of size 10^4. (*)
(*) [[range(0;n)] | _nwise(3)] | length
The text was updated successfully, but these errors were encountered: