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

Projects
None yet
3 participants
@jigold
Copy link
Collaborator

commented Nov 21, 2018

No description provided.

@tpoterba

This comment has been minimized.

Copy link
Collaborator

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, '')

This comment has been minimized.

Copy link
@tpoterba

tpoterba Nov 21, 2018

Collaborator

this is probably really inefficient

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

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

This comment has been minimized.

Copy link
@tpoterba

tpoterba Nov 21, 2018

Collaborator

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

@jigold

This comment has been minimized.

Copy link
Collaborator Author

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.

@danking
Copy link
Collaborator

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:

This comment has been minimized.

Copy link
@danking

danking Nov 26, 2018

Collaborator

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

This comment has been minimized.

Copy link
@jigold

jigold Nov 29, 2018

Author Collaborator

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

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 26, 2018

@tpoterba Are you okay with this?

@tpoterba

This comment has been minimized.

Copy link
Collaborator

commented Nov 26, 2018

yes totally!

done.

@jigold jigold force-pushed the jigold:reverse branch from 87a101d to 8abf0b7 Nov 28, 2018

@danking

danking approved these changes Dec 3, 2018

@danking danking merged commit 6801209 into hail-is:master Dec 3, 2018

1 check passed

hail-ci-0-1 successful build
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.