Skip to content

Instantly share code, notes, and snippets.

@robertpi
Created May 27, 2016 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertpi/ef6bff4131598de2ded381b459fb6d38 to your computer and use it in GitHub Desktop.
Save robertpi/ef6bff4131598de2ded381b459fb6d38 to your computer and use it in GitHub Desktop.
// 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