# Matrix blocked question

Hello !

I have the following question: if i have a NXN matrix ([[f32; MAX]; MAX]) that is ordered by blocks, for example BLOCK_SIZE = 64. How can i get the blocks ? If i do:

``````matrix.windows(BLOCK_SIZE)

[ [0, 1, 2, 3, 4]
[5, 6, 7, 8]
[9, 10, 11, 12]
[13, 14, 15, 16]
]
``````

if I do:
` matrix.windows(2)`
it gives me:
[
[0, 1, 2, 3, 4]
[5, 6, 7, 8]
]
[
[5, 6, 7, 8] ]
[9, 10, 11, 12]
]
[
[9, 10, 11, 12]
[13, 14, 15, 16]
]

but i need

``````[
[0, 1, 2, 3, 4]
[5, 6, 7, 8]
]
[
[9, 10, 11, 12]
[13, 14, 15, 16]
]
``````

Any suggestions ? Thank you very much !

If you want to get the 2D blocks which your matrix is made out of, you'll need to make a custom iterator for that probably.

Note however that you can't return a `& [mut] [& [mut] [f32]]` since that would imply the references live somewhere but iterators can't return references to their own belongings.

My problem is that

``````matrix.windows(BLOCK_SIZE)
``````

it returns a the same last elements. Here is an example:

``````[ [0, 1, 2, 3, 4]
[5, 6, 7, 8]
[9, 10, 11, 12]
[13, 14, 15, 16]
]
``````

if I do:
matrix.windows(2)
it gives me:
[
[0, 1, 2, 3, 4]
[5, 6, 7, 8]
]
[
[5, 6, 7, 8] ]
[9, 10, 11, 12]
]
[
[9, 10, 11, 12]
[13, 14, 15, 16]
]

but i need

``````[
[0, 1, 2, 3, 4]
[5, 6, 7, 8]
]
[
[9, 10, 11, 12]
[13, 14, 15, 16]
]
``````

Any ideas ? Thanks

You want `chunks` or `chunks_exact` they don't overlap where `windows` does.

Thank you so much !

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.