rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations

Home Page:https://docs.rs/ndarray/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Owned Lanes iterator

Zizico2 opened this issue · comments

Is there any way to get an iterator of rows, without borrowing? rows() takes &self. Is there any way to get the same behavior, but consume self? Some sort of into_rows?

Not that I know of. And it's not a goal of ndarray.

If your array is in c-order, you could call to_slice and chunk it into row length... But it still wouldn't consume your array as you want. Is there any reason why you want to consume it instead of simply using it and letting it drop out of scope?

Not that I know of. And it's not a goal of ndarray.

If your array is in c-order, you could call to_slice and chunk it into row length... But it still wouldn't consume your array as you want. Is there any reason why you want to consume it instead of simply using it and letting it drop out of scope?

A function consumes a struct for reasons not related to ndarray. This struct holds an ndarray and this function should return .rows() with some mapping. This isn't possible because the ndarray is getting dropped. For now I was able to refactor the function so that it can take a reference of the original struct.

I don't know precisely your problem, but returning the owned array (with some mapping) from that function should work. Then the caller will be able to call .rows() itself. At that point, it's more a question of refactoring and we can't help much with that.