From c029f7d5edaed57c532f0d45fe6e1f41a0232fdb Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Sat, 28 Oct 2023 15:21:29 +0200 Subject: [PATCH] Ensure compatibility with random-1.3.0 --- fourmolu.yaml | 1 + massiv/src/Data/Massiv/Array/Ops/Construct.hs | 4 ++-- massiv/src/Data/Massiv/Array/Ops/Sort.hs | 2 +- massiv/src/Data/Massiv/Core/Index/Internal.hs | 10 ++++++++-- massiv/src/Data/Massiv/Core/Index/Ix.hs | 8 ++++++++ massiv/src/Data/Massiv/Core/Index/Stride.hs | 3 +++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/fourmolu.yaml b/fourmolu.yaml index 5785f267..6d593233 100644 --- a/fourmolu.yaml +++ b/fourmolu.yaml @@ -12,3 +12,4 @@ in-style: right-align unicode: never respectful: true fixities: [] +single-constraint-parens: never diff --git a/massiv/src/Data/Massiv/Array/Ops/Construct.hs b/massiv/src/Data/Massiv/Array/Ops/Construct.hs index 4f85fb96..a33eac89 100644 --- a/massiv/src/Data/Massiv/Array/Ops/Construct.hs +++ b/massiv/src/Data/Massiv/Array/Ops/Construct.hs @@ -317,7 +317,7 @@ randomArray -> Sz ix -- ^ Resulting size of the array. -> Array DL ix e -randomArray gen splitGen nextRandom comp sz = unsafeMakeLoadArray comp sz Nothing load +randomArray gen splitGen' nextRandom comp sz = unsafeMakeLoadArray comp sz Nothing load where !totalLength = totalElem sz load :: forall s. Scheduler s () -> Ix1 -> (Ix1 -> e -> ST s ()) -> ST s () @@ -332,7 +332,7 @@ randomArray gen splitGen nextRandom comp sz = unsafeMakeLoadArray comp sz Nothin let (genI0, genI1) = if numWorkers scheduler == 1 then (genI, genI) - else splitGen genI + else splitGen' genI scheduleWork_ scheduler $ void $ loopM start (< start + chunkLength) (+ 1) genI0 writeRandom diff --git a/massiv/src/Data/Massiv/Array/Ops/Sort.hs b/massiv/src/Data/Massiv/Array/Ops/Sort.hs index 10a42439..c0fe984e 100644 --- a/massiv/src/Data/Massiv/Array/Ops/Sort.hs +++ b/massiv/src/Data/Massiv/Array/Ops/Sort.hs @@ -199,7 +199,7 @@ quicksortInternalM_ fLT fEQ scheduler marr | otherwise = qsortPar depthPar 0 (k - 1) where -- How deep into the search tree should we continue scheduling jobs. Constants below - -- were discovered imperically: + -- were discovered empirically: depthPar = min (logNumWorkers + 4) (logSize - 10) k = unSz (sizeOfMArray marr) -- We must use log becuase decinding into a tree creates an exponential number of jobs diff --git a/massiv/src/Data/Massiv/Core/Index/Internal.hs b/massiv/src/Data/Massiv/Core/Index/Internal.hs index 45921380..98b74508 100644 --- a/massiv/src/Data/Massiv/Core/Index/Internal.hs +++ b/massiv/src/Data/Massiv/Core/Index/Internal.hs @@ -143,6 +143,9 @@ instance (UniformRange ix, Index ix) => Uniform (Sz ix) where instance UniformRange ix => UniformRange (Sz ix) where uniformRM (SafeSz l, SafeSz u) g = SafeSz <$> uniformRM (l, u) g {-# INLINE uniformRM #-} +#if MIN_VERSION_random(1,3,0) + isInRange (SafeSz l, SafeSz u) (SafeSz k) = isInRange (l, u) k +#endif instance (UniformRange ix, Index ix) => Random (Sz ix) @@ -365,6 +368,9 @@ instance Uniform Dim where instance UniformRange Dim where uniformRM r g = Dim <$> uniformRM (coerce r) g +#if MIN_VERSION_random(1,3,0) + isInRange = isInRangeOrd +#endif instance Random Dim @@ -736,7 +742,7 @@ class -- @since 1.0.2 iterF :: ix -> ix -> ix -> (Int -> Int -> Bool) -> f a -> (ix -> f a -> f a) -> f a default iterF - :: (Index (Lower ix)) + :: Index (Lower ix) => ix -> ix -> ix @@ -758,7 +764,7 @@ class -- @since 0.1.0 stepNextMF :: ix -> ix -> ix -> (Int -> Int -> Bool) -> (Maybe ix -> f a) -> f a default stepNextMF - :: (Index (Lower ix)) + :: Index (Lower ix) => ix -> ix -> ix diff --git a/massiv/src/Data/Massiv/Core/Index/Ix.hs b/massiv/src/Data/Massiv/Core/Index/Ix.hs index 3041c22e..896336cd 100644 --- a/massiv/src/Data/Massiv/Core/Index/Ix.hs +++ b/massiv/src/Data/Massiv/Core/Index/Ix.hs @@ -172,6 +172,10 @@ instance Uniform Ix2 where instance UniformRange Ix2 where uniformRM (l1 :. l2, u1 :. u2) g = (:.) <$> uniformRM (l1, u1) g <*> uniformRM (l2, u2) g {-# INLINE uniformRM #-} +#if MIN_VERSION_random(1,3,0) + isInRange (l1 :. l2, u1 :. u2) (i1 :. i2) = + isInRangeOrd (l1, u1) i1 && isInRangeOrd (l2, u2) i2 +#endif instance Random Ix2 @@ -182,6 +186,10 @@ instance Uniform (Ix (n - 1)) => Uniform (IxN n) where instance UniformRange (Ix (n - 1)) => UniformRange (IxN n) where uniformRM (l1 :> l2, u1 :> u2) g = (:>) <$> uniformRM (l1, u1) g <*> uniformRM (l2, u2) g {-# INLINE uniformRM #-} +#if MIN_VERSION_random(1,3,0) + isInRange (l1 :> l2, u1 :> u2) (i1 :> i2) = + isInRangeOrd (l1, u1) i1 && isInRange (l2, u2) i2 +#endif instance Random (Ix (n - 1)) => Random (IxN n) where random g = diff --git a/massiv/src/Data/Massiv/Core/Index/Stride.hs b/massiv/src/Data/Massiv/Core/Index/Stride.hs index edbb8354..686fb354 100644 --- a/massiv/src/Data/Massiv/Core/Index/Stride.hs +++ b/massiv/src/Data/Massiv/Core/Index/Stride.hs @@ -72,6 +72,9 @@ instance (UniformRange ix, Index ix) => Uniform (Stride ix) where instance UniformRange ix => UniformRange (Stride ix) where uniformRM (SafeStride l, SafeStride u) g = SafeStride <$> uniformRM (l, u) g {-# INLINE uniformRM #-} +#if MIN_VERSION_random(1,3,0) + isInRange (SafeStride l, SafeStride u) (SafeStride k) = isInRange (l, u) k +#endif instance (UniformRange ix, Index ix) => Random (Stride ix)