{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
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 GHC.Exts (build)
fromList ::
forall r e. Mutable r Ix1 e
=> Comp
-> [e]
-> Array r Ix1 e
fromList :: Comp -> [e] -> Array r Ix1 e
fromList = Comp -> [e] -> Array r Ix1 e
forall r ix e.
(Nested LN ix e, Ragged L ix e, Mutable r ix e) =>
Comp -> [ListItem ix e] -> Array r ix e
fromLists'
{-# INLINE fromList #-}
fromListsM :: forall r ix e m . (Nested LN ix e, Ragged L ix e, Mutable r ix e, MonadThrow m)
=> Comp -> [ListItem ix e] -> m (Array r ix e)
fromListsM :: 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 :: * -> *).
(Mutable r ix e, Ragged r' ix e, Load 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.
Construct r ix e =>
Comp -> Array r ix e -> Array r 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. Nested LN ix e => [ListItem ix e] -> Array L ix e
throughNested
{-# INLINE fromListsM #-}
fromLists' :: forall r ix e . (Nested LN ix e, Ragged L ix e, Mutable r ix e)
=> Comp
-> [ListItem ix e]
-> Array r ix e
fromLists' :: Comp -> [ListItem ix e] -> Array r ix e
fromLists' Comp
comp = Array L ix e -> Array r ix e
forall r ix e r'.
(Mutable r ix e, Load r' ix 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.
Construct r ix e =>
Comp -> Array r ix e -> Array r 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. Nested LN ix e => [ListItem ix e] -> Array L ix e
throughNested
{-# INLINE fromLists' #-}
throughNested :: forall ix e . Nested LN ix e => [ListItem ix e] -> Array L ix e
throughNested :: [ListItem ix e] -> Array L ix e
throughNested [ListItem ix e]
xs = NestedStruct L ix e -> Array L ix e
forall r ix e. Nested r ix e => NestedStruct r ix e -> Array r ix e
fromNested (NestedStruct LN ix e -> Array LN ix e
forall r ix e. Nested r ix e => NestedStruct r ix e -> Array r ix e
fromNested [ListItem ix e]
NestedStruct LN ix e
xs :: Array LN ix e)
{-# INLINE throughNested #-}
toList :: Source r ix e => Array r ix e -> [e]
toList :: 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]
build (\ e -> b -> b
c b
n -> (e -> b -> b) -> b -> Array r ix e -> b
forall r ix e b.
Source r ix 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 :: (Nested LN ix e, Construct L ix e, Source r ix e)
=> Array r ix e
-> [ListItem ix e]
toLists :: Array r ix e -> [ListItem ix e]
toLists = Array LN ix e -> [ListItem ix e]
forall r ix e. Nested r ix e => Array r ix e -> NestedStruct r ix e
toNested (Array LN ix e -> [ListItem ix e])
-> (Array r ix e -> Array LN ix e)
-> Array r ix e
-> [ListItem ix e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array L ix e -> Array LN ix e
forall r ix e. Nested r ix e => Array r ix e -> NestedStruct r ix e
toNested (Array L ix e -> Array LN ix e)
-> (Array r ix e -> Array L ix e) -> Array r ix e -> Array LN ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Array L ix e
forall ix e r.
(Construct L ix e, Source r ix e) =>
Array r ix e -> Array L ix e
toListArray
{-# INLINE toLists #-}
toLists2 :: (Source r ix e, Index (Lower ix)) => Array r ix e -> [[e]]
toLists2 :: Array r ix e -> [[e]]
toLists2 = Array D (Lower ix) [e] -> [[e]]
forall r ix e. Source r ix 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), Source r ix e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) []
{-# INLINE toLists2 #-}
toLists3 :: (Index (Lower (Lower ix)), Index (Lower ix), Source r ix e) => Array r ix e -> [[[e]]]
toLists3 :: Array r ix e -> [[[e]]]
toLists3 = Array D (Lower (Lower ix)) [[e]] -> [[[e]]]
forall r ix e. Source r ix 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), Source r ix 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), Source r ix e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) []
{-# INLINE toLists3 #-}
toLists4 ::
( Index (Lower (Lower (Lower ix)))
, Index (Lower (Lower ix))
, Index (Lower ix)
, Source r ix e
)
=> Array r ix e
-> [[[[e]]]]
toLists4 :: Array r ix e -> [[[[e]]]]
toLists4 = Array D (Lower (Lower (Lower ix))) [[[e]]] -> [[[[e]]]]
forall r ix e. Source r ix 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), Source r ix 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), Source r ix 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), Source r ix e) =>
(e -> a -> a) -> a -> Array r ix e -> Array D (Lower ix) a
foldrInner (:) []
{-# INLINE toLists4 #-}