You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It turn out move is not implemented correctly for unboxed vector which use structure of arrays (SoA) representation. Here is move's specification:
If the vectors do not overlap, then this is equivalent to copy. Otherwise, the copying is performed as if the source vector were copied to a temporary vector and then the temporary vector was copied to the target vector.
For tuples move is implemented as pairwise move each underlying array. However it's possible for arrays corresponding to different to alias thus breaking move implementation. As an example:
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TypeFamilies #-}
moduleMVwhereimportControl.Monad.PrimitiveimportData.Vector.UnboxedqualifiedasVUimportData.Vector.Unboxed.MutablequalifiedasMVUimportData.Vector.Generic.MutablequalifiedasMVG-- Reference implementation for move:moveSpec:: (MVG.MVectorva, PrimMonadm, PrimStatem~s) =>vsa->vsa->m()
moveSpec tgt src =do
tmp <-MVG.clone src
MVG.copy tgt tmp
problemSoA::IO()
problemSoA =doputStrLn"Reference impl"
testMove moveSpec
putStrLn"\nmove"
testMove MVU.move
where
testMove fun =do
va <-MVU.generate 4id
vb <-MVU.generate 4 (+100)
let src =MVU.zip va vb
dst =MVU.zip vb va
print. ("src = "++) .show=<<VU.freeze src
print. ("dst = "++) .show=<<VU.freeze dst
fun dst src
print. ("dst = "++) .show=<<VU.freeze dst
Which is obviously breaks specification. However I don't see any easy fix. We'll need to check all underlying arrays for overlap and we don't have machinery for that
The text was updated successfully, but these errors were encountered:
It turn out
move
is not implemented correctly for unboxed vector which use structure of arrays (SoA) representation. Here ismove
's specification:For tuples move is implemented as pairwise move each underlying array. However it's possible for arrays corresponding to different to alias thus breaking
move
implementation. As an example:produces
Which is obviously breaks specification. However I don't see any easy fix. We'll need to check all underlying arrays for overlap and we don't have machinery for that
The text was updated successfully, but these errors were encountered: