Skip to content

Instantly share code, notes, and snippets.

@robertpi robertpi/rolly.fs
Created May 27, 2016

Embed
What would you like to do?
// 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
You can’t perform that action at this time.