haskell / vector

An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Other
365 stars 139 forks source link

Document that `force` always copies #511

Open jorisdral opened 2 days ago

jorisdral commented 2 days ago

The haddocks of the force function mentions that the input vector is possibly copied into a new return vector.

image

It seems however that force always copies regardless of the vector type, because the implementation for each vector type calls Data.Vector.Generic.force, which uses basicUnsafeCopy.

If my understanding is correct, should the haddocks be updated to specify that the function always copies?

Shimuuar commented 21 hours ago

It's poorly worded. force always creates copy except when optimized is able to elide that copy. Specifically after using slice it will perform copy.

On the other hand output in some very special cases there're rules that could elide that copy. force (generate 10 f).