Skip to content
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 implementation of transpose/0 #2472

Closed
pkoppstein opened this issue Aug 29, 2022 · 1 comment
Closed

faster implementation of transpose/0 #2472

pkoppstein opened this issue Aug 29, 2022 · 1 comment

Comments

@pkoppstein
Copy link
Contributor

pkoppstein commented Aug 29, 2022

The following is much faster (3x in some instances) than the current def in builtins.jq

def transpose: [range(0; map( length ) | max) as $i | [.[][$i]]];

Even better would be to add stream-oriented versions of min/0 and max/0:

def min(s): reduce s as $x (first(s); if $x < . then $x else . end);
def max(s): reduce s as $x (first(s); if $x > . then $x else . end);

and then:

def transpose: [range(0; max(.[]|length)) as $i | [.[][$i]]];
@pkoppstein
Copy link
Contributor Author

Resolved by #2679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants