Hi Matthieu,
Yes, I made that mistake. As you mentioned, the strides are [6, 2].
Thanks for the correction.
Fran
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
location : Int -> Int -> Strides -> Shape -> Maybe Location
location bufferIndex bufferOffset (stride1, stride2) (height, width) =
let
unOffset =
bufferIndex - bufferOffset
line =
unOffset // stride1
column =
unOffset % stride1
in
if line < height && column < width then
Just (line, column)
else
Nothing
location : Int -> Int -> ( Int, Int ) -> ( Int, Int ) -> Maybe ( Int, Int )
location bufferIndex offset ( str1, str2 ) ( height, width ) =
let
unOffset =
bufferIndex - offset
( line, lineRest ) =
( unOffset // str1
, unOffset % str1
)
( column, columnRest ) =
( lineRest // str2
, lineRest % str2
)
locationOk =
line < height && column < width && columnRest == 0
in
if locationOk then
Just ( line, column )
else
Nothing
import TheFile
import List
List.range 0 8 |> List.map (\id -> TheFile.location id 0 (6,2) (2,2))
I had similar idea, walking the entire buffer and somehow check boundaries (dimension size) but I was wondering if there is a better way since we could have a huge buffer (this might be shared across multiple ndarrays), let's say a couple of hundred thousands items, but a ndarray with a small view of this buffer, let's say a thousand items. I wouldn't want to go through hundreds of thousands for just one thousand. That's why I'm trying to come up with a function that have the behavior I described initially, "nextlocation". Along with "index" function I can work out in O(1) the index for the next one
Thanks,
Fran
--
I wouldn't want to go through hundreds of thousands for just one thousand. That's why I'm trying to come up with a function that have the behavior I described initially, "nextlocation". Along with "index" function I can work out in O(1) the index for the next one
nextLocation : Location -> Shape -> Maybe Location
nextLocation location shape =
let
increment (loc, size) (locationAcc, shouldInc) =
if shouldInc then
if loc + 1 < size then
( loc + 1 :: locationAcc, False )
else
( 0 :: locationAcc, True )
else
( loc :: locationAcc, False )
newLocation =
List.map2 (,) location shape
|> List.foldr increment ([],True)
in
if Tuple.second newLocation then
Nothing
else
Tuple.first newLocation