{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Massiv.Array.Manifest.List (
fromList,
fromListsM,
fromLists',
toList,
toLists,
toLists2,
toLists3,
toLists4,
) where
import Data.Massiv.Array.Manifest.Internal
import Data.Massiv.Array.Ops.Fold (foldrInner)
import Data.Massiv.Array.Ops.Fold.Internal (foldrFB)
import Data.Massiv.Core.Common
import Data.Massiv.Core.List
import qualified GHC.Exts as GHC (IsList (..), build)
fromList
:: forall r e
. Manifest r e
=> Comp
-> [e]
-> Vector r e
fromList :: forall r e. Manifest r e => Comp -> [e] -> Vector r e
fromList = Comp -> [e] -> Array r Ix1 e
Comp -> [ListItem Ix1 e] -> Array r Ix1 e
forall r ix e.
(HasCallStack, Ragged L ix e, Manifest r e) =>
Comp -> [ListItem ix e] -> Array r ix e
fromLists'
{-# INLINE fromList #-}
fromListsM
:: forall r ix e m
. (Ragged L ix e, Manifest r e, MonadThrow m)
=> Comp
-> [ListItem ix e]
-> m (Array r ix e)
fromListsM :: forall r ix e (m :: * -> *).
(Ragged L ix e, Manifest r e, MonadThrow m) =>
Comp -> [ListItem ix e] -> m (Array r ix e)
fromListsM Comp
comp = Array L ix e -> m (Array r ix e)
forall r ix e r' (m :: * -> *).
(Manifest r e, Ragged r' ix e, MonadThrow m) =>
Array r' ix e -> m (Array r ix e)
fromRaggedArrayM (Array L ix e -> m (Array r ix e))
-> ([ListItem ix e] -> Array L ix e)
-> [ListItem ix e]
-> m (Array r ix e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Comp -> Array L ix e -> Array L ix e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array L ix e -> Array L ix e
setComp Comp
comp (Array L ix e -> Array L ix e)
-> ([ListItem ix e] -> Array L ix e)
-> [ListItem ix e]
-> Array L ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ListItem ix e] -> Array L ix e
forall ix e.
IsList (Array L ix e) =>
[ListItem ix e] -> Array L ix e
fromListToListArray
{-# INLINE fromListsM #-}
fromListToListArray
:: forall ix e
. GHC.IsList (Array L ix e)
=> [ListItem ix e]
-> Array L ix e
fromListToListArray :: forall ix e.
IsList (Array L ix e) =>
[ListItem ix e] -> Array L ix e
fromListToListArray = [Item (Array L ix e)] -> Array L ix e
[ListItem ix e] -> Array L ix e
forall l. IsList l => [Item l] -> l
GHC.fromList
{-# INLINE fromListToListArray #-}
fromLists'
:: forall r ix e
. (HasCallStack, Ragged L ix e, Manifest r e)
=> Comp
-> [ListItem ix e]
-> Array r ix e
fromLists' :: forall r ix e.
(HasCallStack, Ragged L ix e, Manifest r e) =>
Comp -> [ListItem ix e] -> Array r ix e
fromLists' Comp
comp = Array L ix e -> Array r ix e
forall r ix e r'.
(HasCallStack, Manifest r e, Ragged r' ix e) =>
Array r' ix e -> Array r ix e
fromRaggedArray' (Array L ix e -> Array r ix e)
-> ([ListItem ix e] -> Array L ix e)
-> [ListItem ix e]
-> Array r ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Comp -> Array L ix e -> Array L ix e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array L ix e -> Array L ix e
setComp Comp
comp (Array L ix e -> Array L ix e)
-> ([ListItem ix e] -> Array L ix e)
-> [ListItem ix e]
-> Array L ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ListItem ix e] -> Array L ix e
forall ix e.
IsList (Array L ix e) =>
[ListItem ix e] -> Array L ix e
fromListToListArray
{-# INLINE fromLists' #-}
toList :: (Index ix, Source r e) => Array r ix e -> [e]
toList :: forall ix r e. (Index ix, Source r e) => Array r ix e -> [e]
toList !Array r ix e
arr = (forall b. (e -> b -> b) -> b -> b) -> [e]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
GHC.build (\e -> b -> b
c b
n -> (e -> b -> b) -> b -> Array r ix e -> b
forall ix r e b.
(Index ix, Source r e) =>
(e -> b -> b) -> b -> Array r ix e -> b
foldrFB e -> b -> b
c b
n Array r ix e
arr)
{-# INLINE toList #-}
toLists
:: (Ragged L ix e, Shape r ix, Source r e)
=> Array r ix e
-> [ListItem ix e]
toLists :: forall ix e r.
(Ragged L ix e, Shape r ix, Source r e) =>
Array r ix e -> [ListItem ix e]
toLists = Array L ix e -> [Item (Array L ix e)]
Array L ix e -> [ListItem ix e]
forall l. IsList l => l -> [Item l]
GHC.toList (Array L ix e -> [ListItem ix e])
-> (Array r ix e -> Array L ix e)
-> Array r ix e
-> [ListItem ix e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Array L ix e
forall ix e r.
(Ragged L ix e, Shape r ix, Source r e) =>
Array r ix e -> Array L ix e
toListArray
{-# INLINE toLists #-}
toLists2 :: (Source r e, Index ix, Index (Lower ix)) => Array r ix e -> [[e]]
toLists2 :: forall r e ix.
(Source r e, Index ix, Index (Lower ix)) =>
Array r ix e -> [[e]]
toLists2 = Array D (Lower ix) [e] -> [[e]]
forall ix r e. (Index ix, Source r e) => Array r ix e -> [e]
toList (Array D (Lower ix) [e] -> [[e]])
-> (Array r ix e -> Array D (Lower ix) [e])
-> Array r ix e
-> [[e]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> [e] -> [e]) -> [e] -> Array r ix e -> Array D (Lower ix) [e]
forall ix r e a.
(Index (Lower ix), Index ix, Source r e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) []
{-# INLINE toLists2 #-}
toLists3
:: (Source r e, Index ix, Index (Lower ix), Index (Lower (Lower ix))) => Array r ix e -> [[[e]]]
toLists3 :: forall r e ix.
(Source r e, Index ix, Index (Lower ix),
Index (Lower (Lower ix))) =>
Array r ix e -> [[[e]]]
toLists3 = Array D (Lower (Lower ix)) [[e]] -> [[[e]]]
forall ix r e. (Index ix, Source r e) => Array r ix e -> [e]
toList (Array D (Lower (Lower ix)) [[e]] -> [[[e]]])
-> (Array r ix e -> Array D (Lower (Lower ix)) [[e]])
-> Array r ix e
-> [[[e]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([e] -> [[e]] -> [[e]])
-> [[e]]
-> Array D (Lower ix) [e]
-> Array D (Lower (Lower ix)) [[e]]
forall ix r e a.
(Index (Lower ix), Index ix, Source r e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) [] (Array D (Lower ix) [e] -> Array D (Lower (Lower ix)) [[e]])
-> (Array r ix e -> Array D (Lower ix) [e])
-> Array r ix e
-> Array D (Lower (Lower ix)) [[e]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> [e] -> [e]) -> [e] -> Array r ix e -> Array D (Lower ix) [e]
forall ix r e a.
(Index (Lower ix), Index ix, Source r e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) []
{-# INLINE toLists3 #-}
toLists4
:: ( Source r e
, Index ix
, Index (Lower ix)
, Index (Lower (Lower ix))
, Index (Lower (Lower (Lower ix)))
)
=> Array r ix e
-> [[[[e]]]]
toLists4 :: forall r e ix.
(Source r e, Index ix, Index (Lower ix), Index (Lower (Lower ix)),
Index (Lower (Lower (Lower ix)))) =>
Array r ix e -> [[[[e]]]]
toLists4 = Array D (Lower (Lower (Lower ix))) [[[e]]] -> [[[[e]]]]
forall ix r e. (Index ix, Source r e) => Array r ix e -> [e]
toList (Array D (Lower (Lower (Lower ix))) [[[e]]] -> [[[[e]]]])
-> (Array r ix e -> Array D (Lower (Lower (Lower ix))) [[[e]]])
-> Array r ix e
-> [[[[e]]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([[e]] -> [[[e]]] -> [[[e]]])
-> [[[e]]]
-> Array D (Lower (Lower ix)) [[e]]
-> Array D (Lower (Lower (Lower ix))) [[[e]]]
forall ix r e a.
(Index (Lower ix), Index ix, Source r e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) [] (Array D (Lower (Lower ix)) [[e]]
-> Array D (Lower (Lower (Lower ix))) [[[e]]])
-> (Array r ix e -> Array D (Lower (Lower ix)) [[e]])
-> Array r ix e
-> Array D (Lower (Lower (Lower ix))) [[[e]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([e] -> [[e]] -> [[e]])
-> [[e]]
-> Array D (Lower ix) [e]
-> Array D (Lower (Lower ix)) [[e]]
forall ix r e a.
(Index (Lower ix), Index ix, Source r e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) [] (Array D (Lower ix) [e] -> Array D (Lower (Lower ix)) [[e]])
-> (Array r ix e -> Array D (Lower ix) [e])
-> Array r ix e
-> Array D (Lower (Lower ix)) [[e]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> [e] -> [e]) -> [e] -> Array r ix e -> Array D (Lower ix) [e]
forall ix r e a.
(Index (Lower ix), Index ix, Source r e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) []
{-# INLINE toLists4 #-}