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

segmented exclusive scan #3

Open
melsman opened this issue Oct 11, 2018 · 3 comments
Open

segmented exclusive scan #3

melsman opened this issue Oct 11, 2018 · 3 comments

Comments

@melsman
Copy link
Contributor

melsman commented Oct 11, 2018

We need such a beast...

@athas
Copy link
Member

athas commented Oct 11, 2018

What should the type be? In particular, what should be the size of the resulting array?

@melsman
Copy link
Contributor Author

melsman commented Oct 11, 2018

The type of segmented_excl_scan:

val segmented_excl_scan [n] 't : (t -> t -> t) -> t -> [n]bool -> [n]t -> [n]t 

This type is the same as the type for segmented_scan. The semantics, however, is different:

segmented_excl_scan (+) 0 [true,false,false,true,false,false] [1,2,3,4,5,6]  
--> [0,1,3,0,4,9]

Do we have an excl_scan somewhere in the libraries?

@melsman
Copy link
Contributor Author

melsman commented Oct 11, 2018

Here is an implementation:

let segmented_excl_scan [n] 't (op: t -> t -> t) (ne:t) (flags:[n]bool) (data:[n]t) : [n]t =
  let data = map (\i -> if i == 0 || flags[i] then ne
                        else data[i-1]) (iota n)
  in segmented_scan op ne flags data

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

No branches or pull requests

2 participants