Skip to content

Fix doctest setup #150

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

Open
wants to merge 7 commits 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
29 changes: 18 additions & 11 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ jobs:
curl -L https://github.com/rubik/stack-hpc-coveralls/releases/download/v0.0.7.0/shc-Linux-X64.tar.bz2 | tar xj shc
./shc --repo-token="$COVERALLS_TOKEN" --partial-coverage --fetch-coverage combined custom
else
stack $STACK_ARGS test massiv:doctests
stack $STACK_ARGS test massiv-test:tests
fi

Expand Down Expand Up @@ -226,20 +225,28 @@ jobs:
restore-keys: |
cabal-${{ runner.os }}-${{ matrix.ghc }}-${{ env.cache-version }}
- name: Build
id: build
run: |
set -ex
cabal configure --haddock-all --enable-tests --project-file cabal-ci.project
cabal build all --write-ghc-environment-files=always --project-file cabal-ci.project
cabal configure --haddock-all
cabal build all
- name: Test
run: |
set -ex
cabal test all --project-file cabal-ci.project
# - name: Check Cabal Files
# run: |
# set -ex
# cd massiv
# cabal -vnormal check
# cd ..
cabal test all

- name: Install Doctest
id: install-doctest
if: steps.build.outcome == 'success'
run: |
set -ex
cabal install doctest --ignore-project --overwrite-policy=always

- name: Doctest
if: steps.install-doctest.outcome == 'success'
run: |
set -ex
./scripts/doctest.sh

massiv-bench:
name: Benchmarks
Expand All @@ -251,7 +258,7 @@ jobs:
resolver: [lts-22]
include:
- resolver: lts-22
ghc: 9.6.6
ghc: 9.6.7

env:
STACK_ARGS: '--resolver ${{ matrix.resolver }} --system-ghc'
Expand Down
4 changes: 1 addition & 3 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
packages:
massiv
--massiv-bench
massiv-test

write-ghc-environment-files: always
-- Always build tests and benchmarks.
-- Always build tests.
tests: true
benchmarks: true
-- The only sensible test display option
test-show-details: streaming
15 changes: 0 additions & 15 deletions massiv/massiv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,6 @@ library
-Wno-unused-imports
-Wno-unrecognised-pragmas

test-suite doctests
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: doctests.hs
build-depends: base >= 4.9 && < 5
, doctest >=0.15
if impl(ghc >= 8.2) && impl(ghc < 8.10)
build-depends: QuickCheck
, massiv
, mersenne-random-pure64
, random >= 1.2.0
, mwc-random >= 0.15.0.1
, splitmix >= 0.0.1
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/lehins/massiv
Expand Down
2 changes: 1 addition & 1 deletion massiv/src/Data/Massiv/Array/Manifest/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fromListToListArray = GHC.fromList
--
-- Above example implemented using GHC's `OverloadedLists` extension:
--
-- >>> :set -XOverloadedLists
-- >>> :seti -XOverloadedLists
-- >>> [[1,2,3],[4,5,6]] :: Array U Ix2 Int
-- Array U Seq (Sz (2 :. 3))
-- [ [ 1, 2, 3 ]
Expand Down
2 changes: 2 additions & 0 deletions massiv/src/Data/Massiv/Array/Manifest/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
-- Disable warning due to `sizeofMutableByteArray` for now
{-# OPTIONS_GHC -Wno-deprecations #-}

-- |
-- Module : Data.Massiv.Array.Manifest.Primitive
Expand Down
39 changes: 32 additions & 7 deletions massiv/src/Data/Massiv/Array/Mutable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@ flattenMArray marr = unsafeResizeMArray (toLinearSz (sizeOfMArray marr)) marr
-- dimensionality by one. Same as `Data.Massiv.Array.!?>` operator, but for
-- mutable arrays.
--
-- ====__Examples__
--
-- >>> import Data.Massiv.Array
-- >>> marr <- makeMArrayLinear @P Seq (Sz2 4 7) (pure . (+10))
-- >>> freezeS marr
-- Array P Seq (Sz (4 :. 7))
-- [ [ 10, 11, 12, 13, 14, 15, 16 ]
-- , [ 17, 18, 19, 20, 21, 22, 23 ]
-- , [ 24, 25, 26, 27, 28, 29, 30 ]
-- , [ 31, 32, 33, 34, 35, 36, 37 ]
-- ]
--
-- Let's say our goal is to swap row at index 0 with the one with index 2:
--
-- >>> row0 <- outerSliceMArrayM marr 0
-- >>> row2 <- outerSliceMArrayM marr 2
-- >>> zipSwapM_ 0 row0 row2
-- >>> freezeS marr
-- Array P Seq (Sz (4 :. 7))
-- [ [ 24, 25, 26, 27, 28, 29, 30 ]
-- , [ 17, 18, 19, 20, 21, 22, 23 ]
-- , [ 10, 11, 12, 13, 14, 15, 16 ]
-- , [ 31, 32, 33, 34, 35, 36, 37 ]
-- ]
--
-- @since 1.0.0
outerSliceMArrayM
:: forall r ix e m s
Expand Down Expand Up @@ -188,7 +213,7 @@ outerSliceMArrayM !marr !i = do
-- , [ 31, 32, 33, 34, 35, 36, 37 ]
-- ]
--
-- Here we can see we can get individual rows from a mutable matrix
-- Here is how we can get individual rows from a mutable matrix
--
-- >>> marr <- thawS arr
-- >>> import Control.Monad ((<=<))
Expand Down Expand Up @@ -255,7 +280,7 @@ outerSlicesMArray comp marr =
--
-- Or using @TypeApplications@:
--
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> newMArray' @P @Ix2 @Int (Sz2 2 6) >>= freezeS
-- Array P Seq (Sz (2 :. 6))
-- [ [ 0, 0, 0, 0, 0, 0 ]
Expand All @@ -279,7 +304,7 @@ newMArray' sz = unsafeNew sz >>= \ma -> ma <$ initialize ma
-- ==== __Example__
--
-- >>> import Data.Massiv.Array
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> arr <- fromListsM @U @Ix2 @Double Par [[12,21],[13,31]]
-- >>> marr <- thaw arr
-- >>> modify marr (pure . (+ 10)) (1 :. 0)
Expand Down Expand Up @@ -314,7 +339,7 @@ thaw arr =
-- ==== __Example__
--
-- >>> import Data.Massiv.Array
-- >>> :set -XOverloadedLists
-- >>> :seti -XOverloadedLists
-- >>> thawS @P @Ix1 @Double [1..10]
-- >>> marr <- thawS @P @Ix1 @Double [1..10]
-- >>> writeM marr 5 100
Expand Down Expand Up @@ -505,7 +530,7 @@ makeMArrayLinear comp sz f = do
--
-- ====__Examples__
--
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> import Data.Massiv.Array
-- >>> createArray_ @P @_ @Int Seq (Sz1 2) (\ s marr -> scheduleWork s (writeM marr 0 10) >> scheduleWork s (writeM marr 1 11))
-- Array P Seq (Sz1 2)
Expand Down Expand Up @@ -554,7 +579,7 @@ createArray comp sz action = do
--
-- ====__Examples__
--
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> import Data.Massiv.Array
-- >>> createArrayS_ @P @_ @Int (Sz1 2) (\ marr -> write marr 0 10 >> write marr 1 12)
-- Array P Seq (Sz1 2)
Expand Down Expand Up @@ -1346,7 +1371,7 @@ modifyM marr f ix
--
-- ====__Examples__
--
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> import Control.Monad.ST
-- >>> import Data.Massiv.Array
-- >>> runST $ newMArray' @P @Ix1 @Int (Sz1 3) >>= (\ma -> modifyM_ ma (pure . (+10)) 1 >> freezeS ma)
Expand Down
2 changes: 1 addition & 1 deletion massiv/src/Data/Massiv/Array/Mutable/Algorithms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Data.Massiv.Core.Common
--
-- >>> import Data.Massiv.Array as A
-- >>> import Data.Massiv.Array.Mutable.Algorithms
-- >>> :set -XOverloadedLists
-- >>> :seti -XOverloadedLists
-- >>> m <- thaw ([2,1,50,10,20,8] :: Array P Ix1 Int)
-- >>> unstablePartitionM m (pure . (<= 10))
-- 4
Expand Down
41 changes: 36 additions & 5 deletions massiv/src/Data/Massiv/Array/Ops/Construct.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
Expand Down Expand Up @@ -201,7 +202,7 @@ iiterateN sz f = iunfoldrS_ sz $ \a ix -> let !a' = f a ix in (a', a')
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array
-- >>> unfoldrS_ (Sz1 10) (\xs -> (Prelude.head xs, Prelude.tail xs)) ([10 ..] :: [Int])
-- >>> unfoldrS_ (Sz1 10) (Data.Maybe.fromJust . Data.List.uncons) ([10 ..] :: [Int])
-- Array DL Seq (Sz1 10)
-- [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
--
Expand Down Expand Up @@ -293,7 +294,7 @@ iunfoldlS_ sz f acc0 = DLArray{dlComp = Seq, dlSize = sz, dlLoad = load}
-- >>> import Data.Massiv.Array
-- >>> import System.Random as Random
-- >>> gen = Random.mkStdGen 217
-- >>> randomArray gen Random.split Random.random (ParN 2) (Sz2 2 3) :: Array DL Ix2 Double
-- >>> randomArray gen Random.splitGen Random.random (ParN 2) (Sz2 2 3) :: Array DL Ix2 Double
-- Array DL (ParN 2) (Sz (2 :. 3))
-- [ [ 0.2616843941380331, 0.600959468331641, 0.4382415961606372 ]
-- , [ 0.27812817813217605, 0.2993277194932741, 0.2774105268603957 ]
Expand Down Expand Up @@ -385,6 +386,19 @@ makeSplitSeedArray it seed splitSeed comp sz genFunc =
-- | Generate a random array where all elements are sampled from a uniform distribution.
--
-- @since 1.0.0
#if MIN_VERSION_random(1,3,0)
uniformArray
:: forall ix e g
. (Index ix, SplitGen g, Uniform e)
=> g
-- ^ Initial random value generator.
-> Comp
-- ^ Computation strategy.
-> Sz ix
-- ^ Resulting size of the array.
-> Array DL ix e
uniformArray gen = randomArray gen splitGen uniform
#else
uniformArray
:: forall ix e g
. (Index ix, RandomGen g, Uniform e)
Expand All @@ -396,11 +410,27 @@ uniformArray
-- ^ Resulting size of the array.
-> Array DL ix e
uniformArray gen = randomArray gen split uniform
#endif
{-# INLINE uniformArray #-}

-- | Same as `uniformArray`, but will generate values in a supplied range.
--
-- @since 1.0.0
#if MIN_VERSION_random(1,3,0)
uniformRangeArray
:: forall ix e g
. (Index ix, SplitGen g, UniformRange e)
=> g
-- ^ Initial random value generator.
-> (e, e)
-- ^ Inclusive range in which values will be generated in.
-> Comp
-- ^ Computation strategy.
-> Sz ix
-- ^ Resulting size of the array.
-> Array DL ix e
uniformRangeArray gen r = randomArray gen splitGen (uniformR r)
#else
uniformRangeArray
:: forall ix e g
. (Index ix, RandomGen g, UniformRange e)
Expand All @@ -414,6 +444,7 @@ uniformRangeArray
-- ^ Resulting size of the array.
-> Array DL ix e
uniformRangeArray gen r = randomArray gen split (uniformR r)
#endif
{-# INLINE uniformRangeArray #-}

-- | Similar to `randomArray` but performs generation sequentially, which means it doesn't
Expand Down Expand Up @@ -485,12 +516,12 @@ randomArrayS gen sz nextRandom =
-- >>> import System.Random.MWC as MWC (initialize)
-- >>> import System.Random.Stateful (uniformRM)
-- >>> import Control.Scheduler (initWorkerStates, getWorkerId)
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> gens <- initWorkerStates Par (MWC.initialize . A.toPrimitiveVector . A.singleton @P @Ix1 . fromIntegral . getWorkerId)
-- >>> randomArrayWS gens (Sz2 2 3) (uniformRM (0, 9)) :: IO (Matrix P Double)
-- Array P Par (Sz (2 :. 3))
-- [ [ 8.999240522095299, 6.832223390653755, 3.065728078741671 ]
-- , [ 7.242581103346686, 2.4565807301968623, 0.4514262066689775 ]
-- [ [ 8.999240522095299, 6.832223390653754, 1.434271921258329 ]
-- , [ 7.242581103346687, 2.0434192698031377, 4.048573793331022 ]
-- ]
-- >>> randomArrayWS gens (Sz1 6) (uniformRM (0, 9)) :: IO (Vector P Int)
-- Array P Par (Sz1 6)
Expand Down
2 changes: 1 addition & 1 deletion massiv/src/Data/Massiv/Array/Ops/Fold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ifoldlWithin dim = ifoldlWithin' (fromDimension dim)
-- ====__Example__
--
-- >>> import Data.Massiv.Array
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> arr = makeArrayLinear @U Seq (Sz (2 :. 5)) id
-- >>> arr
-- Array U Seq (Sz (2 :. 5))
Expand Down
4 changes: 2 additions & 2 deletions massiv/src/Data/Massiv/Array/Ops/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ transposeInner !arr = makeArray (getComp arr) newsz newVal
-- ====__Examples__
--
-- >>> import Data.Massiv.Array
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> arr = makeArrayLinear @U Seq (Sz (2 :> 3 :. 4)) id
-- >>> arr
-- Array U Seq (Sz (2 :> 3 :. 4))
Expand Down Expand Up @@ -472,7 +472,7 @@ reverse' dim = throwEither . reverseM dim
-- ===__Examples__
--
-- >>> import Data.Massiv.Array
-- >>> :set -XTypeApplications
-- >>> :seti -XTypeApplications
-- >>> arr = makeArrayLinear @D Seq (Sz (2 :> 3 :. 4)) id
-- >>> arr
-- Array D Seq (Sz (2 :> 3 :. 4))
Expand Down
Loading
Loading