rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.43k stars 295 forks source link

Owned Lanes iterator #1349

Closed Zizico2 closed 5 months ago

Zizico2 commented 5 months ago

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?

nilgoyette commented 5 months ago

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?

Zizico2 commented 5 months ago

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.

nilgoyette commented 5 months ago

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.