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

Added reversed Python function for arrays and strings #4820

Merged
merged 4 commits into from Dec 3, 2018

Conversation

@jigold
Copy link
Collaborator

@jigold jigold commented Nov 21, 2018

No description provided.

@tpoterba
Copy link
Collaborator

@tpoterba tpoterba commented Nov 21, 2018

how hard would it be to add a step argument for StringSlice and ArraySlice? Then this would just be a[::-1]!

def reverse(seq):
seq = range(0, len(seq)).map(lambda i: seq[len(seq) - 1 - i])
if x.dtype == tstr:
seq = hl.delimit(seq, '')
Copy link
Collaborator

@tpoterba tpoterba Nov 21, 2018

this is probably really inefficient

seq = hl.delimit(seq, '')
return seq

return bind(lambda seq: cond(len(seq) != 0, reverse(seq), seq), x)
Copy link
Collaborator

@tpoterba tpoterba Nov 21, 2018

why do you need the length-0 check here? it'll work either way, no?

@jigold
Copy link
Collaborator Author

@jigold jigold commented Nov 21, 2018

I think it would be relatively straightforward to add the step to array slicing. I looked at StringSlice and it's implemented by doing a memcpy of the bytes for the entire slice. I'd have to think about it some more.

Copy link
Collaborator

@danking danking left a comment

modulo the one code change this seems fine to me.


typ = x.dtype
x = range(0, len(x)).map(lambda i: x[len(x) - 1 - i])
if typ == tstr:
Copy link
Collaborator

@danking danking Nov 26, 2018

typ is only used once, so just inline x.dtype here.

Copy link
Collaborator Author

@jigold jigold Nov 29, 2018

I can't inline the type because x is mutated and will always be Array[String] after line 2 even if the input is a string.

@jigold
Copy link
Collaborator Author

@jigold jigold commented Nov 26, 2018

@tpoterba Are you okay with this?

@tpoterba
Copy link
Collaborator

@tpoterba tpoterba commented Nov 26, 2018

yes totally!

danking
danking approved these changes Dec 3, 2018
@danking danking merged commit 6801209 into hail-is:master Dec 3, 2018
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants