Francisco Ramos

2017-12-01 15:22:16 UTC

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

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 elm-discuss+***@googlegroups.com.

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 elm-discuss+***@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.