Created
March 9, 2019 20:42
-
-
Save athas/05023461a97739f08a30d3e555b927df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let safescatter 't [m] [n] (dest: *[m]t) (is: [n]i32) (vs: [n]t): *[m]t = | |
let dest' = scatter dest is vs | |
let in_bounds = scatter (replicate 1 true) | |
(map (\i -> if i >= 0 && i < m then -1 else 0) is) | |
(replicate n false) | |
in assert in_bounds[0] dest' | |
-- == | |
-- entry: test_scatter test_safescatter | |
-- random input { 100 [1000000]i32 } auto output | |
-- random input { 1000 [1000000]i32 } auto output | |
-- random input { 10000 [1000000]i32 } auto output | |
-- random input { 1000 [1000000]i32 } auto output | |
-- random input { 10000 [1000000]i32 } auto output | |
-- random input { 100000 [1000000]i32 } auto output | |
entry test_scatter (m: i32) (is: []i32) = | |
scatter (replicate m 0) (map (%m) is) (map (%m) is) | |
entry test_safescatter (m: i32) (is: []i32) = | |
safescatter (replicate m 0) (map (%m) is) (map (%m) is) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment