Created
May 27, 2016 06:57
-
-
Save robertpi/ef6bff4131598de2ded381b459fb6d38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// this roll why function seems to work on a small 5 x 5 matrix | |
// but doesn't for bigger 227 x 227 image | |
// no idea why | |
let rollArrayY yLength shift (data:'t[]) = | |
let shift = | |
if shift > 0 then | |
shift | |
else | |
yLength + shift | |
let out:'t[] = Array.zeroCreate data.Length | |
for i in 0 .. data.Length - 1 do | |
let shiftIndex = (i + (shift * yLength)) % data.Length | |
out.[shiftIndex] <- data.[i] | |
out | |
// add these as unit test somewhere | |
let test = | |
[| 0. .. 24. |] | |
let printArrayBy x (data:'t[]) = | |
for i in 0 .. data.Length - 1 do | |
printf "%f\t" data.[i] | |
if i % x = x - 1 then printfn "" | |
printfn "" | |
printArrayBy 5 test | |
let testy' = rollArrayY 5 2 test | |
printArrayBy 5 testy' | |
let testy'' = rollArrayY 5 -2 testy' | |
printArrayBy 5 testy'' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment