Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure compatibility with random-1.3.0 #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ in-style: right-align
unicode: never
respectful: true
fixities: []
single-constraint-parens: never
4 changes: 2 additions & 2 deletions massiv/src/Data/Massiv/Array/Ops/Construct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion massiv/src/Data/Massiv/Array/Ops/Sort.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions massiv/src/Data/Massiv/Core/Index/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions massiv/src/Data/Massiv/Core/Index/Ix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 =
Expand Down
3 changes: 3 additions & 0 deletions massiv/src/Data/Massiv/Core/Index/Stride.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading