Skip to content

Commit

Permalink
Ensure compatibility with random-1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Oct 28, 2023
1 parent ef637b5 commit 9387aef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions fourmolu.yaml
Expand Up @@ -12,3 +12,4 @@ in-style: right-align
unicode: never
respectful: true
fixities: []
single-constraint-parens: never
2 changes: 1 addition & 1 deletion massiv/src/Data/Massiv/Array/Ops/Sort.hs
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
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
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

0 comments on commit 9387aef

Please sign in to comment.