Hi Matthieu,

Yes, I made that mistake. As you mentioned, the strides are [6, 2].

Thanks for the correction.

Fran

On Mon, Dec 4, 2017, 07:40 Matthieu Pizenberg <[email protected]>
wrote:

> Hi Francisco,
> I think there is a confusion here. If you keep the same buffer, your
> matrice [1 3; 7 9] will be represented by { strides = (6, 2), shape = (2,2)
> } not strides = (2,2). Because 6 is the jump from one line to the other (1
> to 7).
> Let me know if I'm mistaking or not clear.
>
>
> On Friday, December 1, 2017 at 11:22:16 PM UTC+8, Francisco Ramos wrote:
>>
>> Hi guys,
>>
>> been trying to figure out for a while now how I can solve this problem.
>> I've implemented my own type of array, it's called NdArray. The way it
>> works is as follow:
>> It has a buffer (an array of something), a shape (list of dimensions),
>> strides (list of steps) and an offset. Imagine we have a NdArray with a
>> buffer of 9 numbers [1, 2, 3, 4, 5, 6, 7, 8, 9], shape [3, 3] (square
>> matrix) and this leads to a list of strides [3, 1]. This last one means,
>> there is a jump of 3 numbers for each of the first dimension. Better
>> visualised:
>>
>> buffer => [1, 2, 3, 4, 5, 6, 7, 8, 9]
>> view of this buffer with shape [3, 3] =>
>> [ 1, 2, 3
>> , 4, 5, 6
>> , 7, 8, 9
>> ]
>>
>> Now, imagine I change the strides to be [2, 2], that means, I'm jumping
>> one per dimension (in this square matrix I'm jumping one column and one
>> row). The result is:
>> [ 1, 3
>> , 7, 9
>> ]
>>
>> I'm jumping one number in the last dimension, and an entire row in the
>> first dimension. Shape is now [2, 2].
>>
>> So I have all this implemented already here
>> https://github.com/jscriptcoder/elm-ndarray. This is port of ndarray
>> by Mikola Lysenko, https://github.com/scijs/ndarray. But I got stuck how
>> to walk this array. I'm trying to implement map, filter and fold (foldl),
>> and to do so I must be able to walk this array, which is not that trivial
>> (or at least not for me). I have implemented a function "index" which takes
>> a location in the form of list of Int and calculates the index based on
>> shape, strides and offset. So I'm trying to find a way to implement this
>> functionality:
>> For example, for a [3, 3] shape then
>> nextLocation [0, 0] => Just [0, 1]
>> nextLocation [0, 1] => Just [0, 2]
>> nextLocation [0, 2] => Just [1, 0]
>> nextLocation [1, 0] => Just [1, 1]
>> nextLocation [1, 1] => Just [1, 2]
>> ...
>>  nextLocation [2, 2] => Nothing
>>
>> By far not an expert in functional programming, maybe someone can help me
>> to figur this one out?
>>
>> Thanks a lot.
>>
>> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to