{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE DeriveTraversable          #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures             #-}
{-# OPTIONS_HADDOCK not-home            #-}

module Data.Vector.Generic.Sized.Internal
  ( Vector(..)
  )
where

import           Control.DeepSeq                ( NFData )
import           Data.Data                      ( Data
                                                , Typeable
                                                )
import           Data.Functor.Classes           ( Eq1
                                                , Ord1
                                                , Show1
                                                )
import           Data.Vector                   as V
                                                ( and
                                                , foldl'
                                                , null
                                                , zipWith
                                                , zipWith3
                                                )
import qualified Data.Vector.Generic           as VG
                                                ( Vector
                                                , convert
                                                , empty
                                                , fromList
                                                , toList
                                                )
import           GHC.Arr                        ( Ix
                                                  ( inRange
                                                  , range
                                                  , unsafeIndex
                                                  , unsafeRangeSize
                                                  )
                                                )
import           GHC.TypeLits                   ( Nat )

-- | A wrapper to tag vectors with a type level length.
--
-- Be careful when using the constructor here to not construct sized vectors
-- which have a different length than that specified in the type parameter!
newtype Vector v (n :: Nat) a = Vector (v a)
  deriving ( Int -> Vector v n a -> ShowS
[Vector v n a] -> ShowS
Vector v n a -> String
(Int -> Vector v n a -> ShowS)
-> (Vector v n a -> String)
-> ([Vector v n a] -> ShowS)
-> Show (Vector v n a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (v :: * -> *) (n :: Nat) a.
Show (v a) =>
Int -> Vector v n a -> ShowS
forall (v :: * -> *) (n :: Nat) a.
Show (v a) =>
[Vector v n a] -> ShowS
forall (v :: * -> *) (n :: Nat) a.
Show (v a) =>
Vector v n a -> String
$cshowsPrec :: forall (v :: * -> *) (n :: Nat) a.
Show (v a) =>
Int -> Vector v n a -> ShowS
showsPrec :: Int -> Vector v n a -> ShowS
$cshow :: forall (v :: * -> *) (n :: Nat) a.
Show (v a) =>
Vector v n a -> String
show :: Vector v n a -> String
$cshowList :: forall (v :: * -> *) (n :: Nat) a.
Show (v a) =>
[Vector v n a] -> ShowS
showList :: [Vector v n a] -> ShowS
Show, Vector v n a -> Vector v n a -> Bool
(Vector v n a -> Vector v n a -> Bool)
-> (Vector v n a -> Vector v n a -> Bool) -> Eq (Vector v n a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (v :: * -> *) (n :: Nat) a.
Eq (v a) =>
Vector v n a -> Vector v n a -> Bool
$c== :: forall (v :: * -> *) (n :: Nat) a.
Eq (v a) =>
Vector v n a -> Vector v n a -> Bool
== :: Vector v n a -> Vector v n a -> Bool
$c/= :: forall (v :: * -> *) (n :: Nat) a.
Eq (v a) =>
Vector v n a -> Vector v n a -> Bool
/= :: Vector v n a -> Vector v n a -> Bool
Eq, Eq (Vector v n a)
Eq (Vector v n a) =>
(Vector v n a -> Vector v n a -> Ordering)
-> (Vector v n a -> Vector v n a -> Bool)
-> (Vector v n a -> Vector v n a -> Bool)
-> (Vector v n a -> Vector v n a -> Bool)
-> (Vector v n a -> Vector v n a -> Bool)
-> (Vector v n a -> Vector v n a -> Vector v n a)
-> (Vector v n a -> Vector v n a -> Vector v n a)
-> Ord (Vector v n a)
Vector v n a -> Vector v n a -> Bool
Vector v n a -> Vector v n a -> Ordering
Vector v n a -> Vector v n a -> Vector v n a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall (v :: * -> *) (n :: Nat) a. Ord (v a) => Eq (Vector v n a)
forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Bool
forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Ordering
forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Vector v n a
$ccompare :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Ordering
compare :: Vector v n a -> Vector v n a -> Ordering
$c< :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Bool
< :: Vector v n a -> Vector v n a -> Bool
$c<= :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Bool
<= :: Vector v n a -> Vector v n a -> Bool
$c> :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Bool
> :: Vector v n a -> Vector v n a -> Bool
$c>= :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Bool
>= :: Vector v n a -> Vector v n a -> Bool
$cmax :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Vector v n a
max :: Vector v n a -> Vector v n a -> Vector v n a
$cmin :: forall (v :: * -> *) (n :: Nat) a.
Ord (v a) =>
Vector v n a -> Vector v n a -> Vector v n a
min :: Vector v n a -> Vector v n a -> Vector v n a
Ord, (forall a b. (a -> b) -> Vector v n a -> Vector v n b)
-> (forall a b. a -> Vector v n b -> Vector v n a)
-> Functor (Vector v n)
forall a b. a -> Vector v n b -> Vector v n a
forall a b. (a -> b) -> Vector v n a -> Vector v n b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (v :: * -> *) (n :: Nat) a b.
Functor v =>
a -> Vector v n b -> Vector v n a
forall (v :: * -> *) (n :: Nat) a b.
Functor v =>
(a -> b) -> Vector v n a -> Vector v n b
$cfmap :: forall (v :: * -> *) (n :: Nat) a b.
Functor v =>
(a -> b) -> Vector v n a -> Vector v n b
fmap :: forall a b. (a -> b) -> Vector v n a -> Vector v n b
$c<$ :: forall (v :: * -> *) (n :: Nat) a b.
Functor v =>
a -> Vector v n b -> Vector v n a
<$ :: forall a b. a -> Vector v n b -> Vector v n a
Functor, (forall m. Monoid m => Vector v n m -> m)
-> (forall m a. Monoid m => (a -> m) -> Vector v n a -> m)
-> (forall m a. Monoid m => (a -> m) -> Vector v n a -> m)
-> (forall a b. (a -> b -> b) -> b -> Vector v n a -> b)
-> (forall a b. (a -> b -> b) -> b -> Vector v n a -> b)
-> (forall b a. (b -> a -> b) -> b -> Vector v n a -> b)
-> (forall b a. (b -> a -> b) -> b -> Vector v n a -> b)
-> (forall a. (a -> a -> a) -> Vector v n a -> a)
-> (forall a. (a -> a -> a) -> Vector v n a -> a)
-> (forall a. Vector v n a -> [a])
-> (forall a. Vector v n a -> Bool)
-> (forall a. Vector v n a -> Int)
-> (forall a. Eq a => a -> Vector v n a -> Bool)
-> (forall a. Ord a => Vector v n a -> a)
-> (forall a. Ord a => Vector v n a -> a)
-> (forall a. Num a => Vector v n a -> a)
-> (forall a. Num a => Vector v n a -> a)
-> Foldable (Vector v n)
forall a. Eq a => a -> Vector v n a -> Bool
forall a. Num a => Vector v n a -> a
forall a. Ord a => Vector v n a -> a
forall m. Monoid m => Vector v n m -> m
forall a. Vector v n a -> Bool
forall a. Vector v n a -> Int
forall a. Vector v n a -> [a]
forall a. (a -> a -> a) -> Vector v n a -> a
forall m a. Monoid m => (a -> m) -> Vector v n a -> m
forall b a. (b -> a -> b) -> b -> Vector v n a -> b
forall a b. (a -> b -> b) -> b -> Vector v n a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Eq a) =>
a -> Vector v n a -> Bool
forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Num a) =>
Vector v n a -> a
forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Ord a) =>
Vector v n a -> a
forall (v :: * -> *) (n :: Nat) m.
(Foldable v, Monoid m) =>
Vector v n m -> m
forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
Vector v n a -> Bool
forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
Vector v n a -> Int
forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
Vector v n a -> [a]
forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
(a -> a -> a) -> Vector v n a -> a
forall (v :: * -> *) (n :: Nat) m a.
(Foldable v, Monoid m) =>
(a -> m) -> Vector v n a -> m
forall (v :: * -> *) (n :: Nat) b a.
Foldable v =>
(b -> a -> b) -> b -> Vector v n a -> b
forall (v :: * -> *) (n :: Nat) a b.
Foldable v =>
(a -> b -> b) -> b -> Vector v n a -> b
$cfold :: forall (v :: * -> *) (n :: Nat) m.
(Foldable v, Monoid m) =>
Vector v n m -> m
fold :: forall m. Monoid m => Vector v n m -> m
$cfoldMap :: forall (v :: * -> *) (n :: Nat) m a.
(Foldable v, Monoid m) =>
(a -> m) -> Vector v n a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Vector v n a -> m
$cfoldMap' :: forall (v :: * -> *) (n :: Nat) m a.
(Foldable v, Monoid m) =>
(a -> m) -> Vector v n a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Vector v n a -> m
$cfoldr :: forall (v :: * -> *) (n :: Nat) a b.
Foldable v =>
(a -> b -> b) -> b -> Vector v n a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Vector v n a -> b
$cfoldr' :: forall (v :: * -> *) (n :: Nat) a b.
Foldable v =>
(a -> b -> b) -> b -> Vector v n a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Vector v n a -> b
$cfoldl :: forall (v :: * -> *) (n :: Nat) b a.
Foldable v =>
(b -> a -> b) -> b -> Vector v n a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Vector v n a -> b
$cfoldl' :: forall (v :: * -> *) (n :: Nat) b a.
Foldable v =>
(b -> a -> b) -> b -> Vector v n a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Vector v n a -> b
$cfoldr1 :: forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
(a -> a -> a) -> Vector v n a -> a
foldr1 :: forall a. (a -> a -> a) -> Vector v n a -> a
$cfoldl1 :: forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
(a -> a -> a) -> Vector v n a -> a
foldl1 :: forall a. (a -> a -> a) -> Vector v n a -> a
$ctoList :: forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
Vector v n a -> [a]
toList :: forall a. Vector v n a -> [a]
$cnull :: forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
Vector v n a -> Bool
null :: forall a. Vector v n a -> Bool
$clength :: forall (v :: * -> *) (n :: Nat) a.
Foldable v =>
Vector v n a -> Int
length :: forall a. Vector v n a -> Int
$celem :: forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Eq a) =>
a -> Vector v n a -> Bool
elem :: forall a. Eq a => a -> Vector v n a -> Bool
$cmaximum :: forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Ord a) =>
Vector v n a -> a
maximum :: forall a. Ord a => Vector v n a -> a
$cminimum :: forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Ord a) =>
Vector v n a -> a
minimum :: forall a. Ord a => Vector v n a -> a
$csum :: forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Num a) =>
Vector v n a -> a
sum :: forall a. Num a => Vector v n a -> a
$cproduct :: forall (v :: * -> *) (n :: Nat) a.
(Foldable v, Num a) =>
Vector v n a -> a
product :: forall a. Num a => Vector v n a -> a
Foldable, Functor (Vector v n)
Foldable (Vector v n)
(Functor (Vector v n), Foldable (Vector v n)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Vector v n a -> f (Vector v n b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Vector v n (f a) -> f (Vector v n a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Vector v n a -> m (Vector v n b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Vector v n (m a) -> m (Vector v n a))
-> Traversable (Vector v n)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (v :: * -> *) (n :: Nat).
Traversable v =>
Functor (Vector v n)
forall (v :: * -> *) (n :: Nat).
Traversable v =>
Foldable (Vector v n)
forall (v :: * -> *) (n :: Nat) (m :: * -> *) a.
(Traversable v, Monad m) =>
Vector v n (m a) -> m (Vector v n a)
forall (v :: * -> *) (n :: Nat) (f :: * -> *) a.
(Traversable v, Applicative f) =>
Vector v n (f a) -> f (Vector v n a)
forall (v :: * -> *) (n :: Nat) (m :: * -> *) a b.
(Traversable v, Monad m) =>
(a -> m b) -> Vector v n a -> m (Vector v n b)
forall (v :: * -> *) (n :: Nat) (f :: * -> *) a b.
(Traversable v, Applicative f) =>
(a -> f b) -> Vector v n a -> f (Vector v n b)
forall (m :: * -> *) a.
Monad m =>
Vector v n (m a) -> m (Vector v n a)
forall (f :: * -> *) a.
Applicative f =>
Vector v n (f a) -> f (Vector v n a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Vector v n a -> m (Vector v n b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Vector v n a -> f (Vector v n b)
$ctraverse :: forall (v :: * -> *) (n :: Nat) (f :: * -> *) a b.
(Traversable v, Applicative f) =>
(a -> f b) -> Vector v n a -> f (Vector v n b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Vector v n a -> f (Vector v n b)
$csequenceA :: forall (v :: * -> *) (n :: Nat) (f :: * -> *) a.
(Traversable v, Applicative f) =>
Vector v n (f a) -> f (Vector v n a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Vector v n (f a) -> f (Vector v n a)
$cmapM :: forall (v :: * -> *) (n :: Nat) (m :: * -> *) a b.
(Traversable v, Monad m) =>
(a -> m b) -> Vector v n a -> m (Vector v n b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Vector v n a -> m (Vector v n b)
$csequence :: forall (v :: * -> *) (n :: Nat) (m :: * -> *) a.
(Traversable v, Monad m) =>
Vector v n (m a) -> m (Vector v n a)
sequence :: forall (m :: * -> *) a.
Monad m =>
Vector v n (m a) -> m (Vector v n a)
Traversable, Vector v n a -> ()
(Vector v n a -> ()) -> NFData (Vector v n a)
forall a. (a -> ()) -> NFData a
forall (v :: * -> *) (n :: Nat) a.
NFData (v a) =>
Vector v n a -> ()
$crnf :: forall (v :: * -> *) (n :: Nat) a.
NFData (v a) =>
Vector v n a -> ()
rnf :: Vector v n a -> ()
NFData
           , (forall a. Show a => Show (Vector v n a)) =>
(forall a.
 (Int -> a -> ShowS)
 -> ([a] -> ShowS) -> Int -> Vector v n a -> ShowS)
-> (forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Vector v n a] -> ShowS)
-> Show1 (Vector v n)
forall a. Show a => Show (Vector v n a)
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Vector v n a -> ShowS
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Vector v n a] -> ShowS
forall (f :: * -> *).
(forall a. Show a => Show (f a)) =>
(forall a.
 (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS)
-> (forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
forall (v :: * -> *) (n :: Nat) a.
(Show1 v, Show a) =>
Show (Vector v n a)
forall (v :: * -> *) (n :: Nat) a.
Show1 v =>
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Vector v n a -> ShowS
forall (v :: * -> *) (n :: Nat) a.
Show1 v =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Vector v n a] -> ShowS
$cliftShowsPrec :: forall (v :: * -> *) (n :: Nat) a.
Show1 v =>
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Vector v n a -> ShowS
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Vector v n a -> ShowS
$cliftShowList :: forall (v :: * -> *) (n :: Nat) a.
Show1 v =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Vector v n a] -> ShowS
liftShowList :: forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [Vector v n a] -> ShowS
Show1, (forall a. Eq a => Eq (Vector v n a)) =>
(forall a b.
 (a -> b -> Bool) -> Vector v n a -> Vector v n b -> Bool)
-> Eq1 (Vector v n)
forall a. Eq a => Eq (Vector v n a)
forall a b.
(a -> b -> Bool) -> Vector v n a -> Vector v n b -> Bool
forall (f :: * -> *).
(forall a. Eq a => Eq (f a)) =>
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
forall (v :: * -> *) (n :: Nat) a.
(Eq1 v, Eq a) =>
Eq (Vector v n a)
forall (v :: * -> *) (n :: Nat) a b.
Eq1 v =>
(a -> b -> Bool) -> Vector v n a -> Vector v n b -> Bool
$cliftEq :: forall (v :: * -> *) (n :: Nat) a b.
Eq1 v =>
(a -> b -> Bool) -> Vector v n a -> Vector v n b -> Bool
liftEq :: forall a b.
(a -> b -> Bool) -> Vector v n a -> Vector v n b -> Bool
Eq1, Eq1 (Vector v n)
(Eq1 (Vector v n), forall a. Ord a => Ord (Vector v n a)) =>
(forall a b.
 (a -> b -> Ordering) -> Vector v n a -> Vector v n b -> Ordering)
-> Ord1 (Vector v n)
forall a. Ord a => Ord (Vector v n a)
forall a b.
(a -> b -> Ordering) -> Vector v n a -> Vector v n b -> Ordering
forall (f :: * -> *).
(Eq1 f, forall a. Ord a => Ord (f a)) =>
(forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
forall (v :: * -> *) (n :: Nat). Ord1 v => Eq1 (Vector v n)
forall (v :: * -> *) (n :: Nat) a.
(Ord1 v, Ord a) =>
Ord (Vector v n a)
forall (v :: * -> *) (n :: Nat) a b.
Ord1 v =>
(a -> b -> Ordering) -> Vector v n a -> Vector v n b -> Ordering
$cliftCompare :: forall (v :: * -> *) (n :: Nat) a b.
Ord1 v =>
(a -> b -> Ordering) -> Vector v n a -> Vector v n b -> Ordering
liftCompare :: forall a b.
(a -> b -> Ordering) -> Vector v n a -> Vector v n b -> Ordering
Ord1
           , Typeable (Vector v n a)
Typeable (Vector v n a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Vector v n a -> c (Vector v n a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Vector v n a))
-> (Vector v n a -> Constr)
-> (Vector v n a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Vector v n a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Vector v n a)))
-> ((forall b. Data b => b -> b) -> Vector v n a -> Vector v n a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Vector v n a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Vector v n a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Vector v n a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Vector v n a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a))
-> Data (Vector v n a)
Vector v n a -> Constr
Vector v n a -> DataType
(forall b. Data b => b -> b) -> Vector v n a -> Vector v n a
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Vector v n a -> u
forall u. (forall d. Data d => d -> u) -> Vector v n a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector v n a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector v n a -> c (Vector v n a)
forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Typeable (Vector v n a)
forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Vector v n a -> Constr
forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Vector v n a -> DataType
forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall b. Data b => b -> b) -> Vector v n a -> Vector v n a
forall (v :: * -> *) (n :: Nat) a u.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Int -> (forall d. Data d => d -> u) -> Vector v n a -> u
forall (v :: * -> *) (n :: Nat) a u.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall d. Data d => d -> u) -> Vector v n a -> [u]
forall (v :: * -> *) (n :: Nat) a r r'.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
forall (v :: * -> *) (n :: Nat) a r r'.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
forall (v :: * -> *) (n :: Nat) a (m :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), Monad m) =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
forall (v :: * -> *) (n :: Nat) a (m :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
forall (v :: * -> *) (n :: Nat) a (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector v n a)
forall (v :: * -> *) (n :: Nat) a (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector v n a -> c (Vector v n a)
forall (v :: * -> *) (n :: Nat) a (t :: * -> *) (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Vector v n a))
forall (v :: * -> *) (n :: Nat) a (t :: * -> * -> *) (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Vector v n a))
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Vector v n a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Vector v n a))
$cgfoldl :: forall (v :: * -> *) (n :: Nat) a (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector v n a -> c (Vector v n a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector v n a -> c (Vector v n a)
$cgunfold :: forall (v :: * -> *) (n :: Nat) a (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector v n a)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector v n a)
$ctoConstr :: forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Vector v n a -> Constr
toConstr :: Vector v n a -> Constr
$cdataTypeOf :: forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Vector v n a -> DataType
dataTypeOf :: Vector v n a -> DataType
$cdataCast1 :: forall (v :: * -> *) (n :: Nat) a (t :: * -> *) (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Vector v n a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Vector v n a))
$cdataCast2 :: forall (v :: * -> *) (n :: Nat) a (t :: * -> * -> *) (c :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Vector v n a))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Vector v n a))
$cgmapT :: forall (v :: * -> *) (n :: Nat) a.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall b. Data b => b -> b) -> Vector v n a -> Vector v n a
gmapT :: (forall b. Data b => b -> b) -> Vector v n a -> Vector v n a
$cgmapQl :: forall (v :: * -> *) (n :: Nat) a r r'.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
$cgmapQr :: forall (v :: * -> *) (n :: Nat) a r r'.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Vector v n a -> r
$cgmapQ :: forall (v :: * -> *) (n :: Nat) a u.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
(forall d. Data d => d -> u) -> Vector v n a -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Vector v n a -> [u]
$cgmapQi :: forall (v :: * -> *) (n :: Nat) a u.
(KnownNat n, Typeable v, Typeable a, Data (v a)) =>
Int -> (forall d. Data d => d -> u) -> Vector v n a -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Vector v n a -> u
$cgmapM :: forall (v :: * -> *) (n :: Nat) a (m :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), Monad m) =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
$cgmapMp :: forall (v :: * -> *) (n :: Nat) a (m :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
$cgmapMo :: forall (v :: * -> *) (n :: Nat) a (m :: * -> *).
(KnownNat n, Typeable v, Typeable a, Data (v a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Vector v n a -> m (Vector v n a)
Data, Typeable
           )

instance (Ix a, Ord (v a), VG.Vector v a) => Ix (Vector v n a) where

  -- range is consistent with range :: ((a,..,a), (a,..,a)) -> [(a,..,a)]
  range :: (Vector v n a, Vector v n a) -> [Vector v n a]
range (Vector v a
l, Vector v a
u) = v a -> Vector v n a
forall (v :: * -> *) (n :: Nat) a. v a -> Vector v n a
Vector (v a -> Vector v n a) -> [v a] -> [Vector v n a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector [a] -> [v a]
forall {v :: * -> *} {a}. Vector v a => Vector [a] -> [v a]
enumerate Vector [a]
ranges
   where
    ranges :: Vector [a]
ranges = (a -> a -> [a]) -> Vector a -> Vector a -> Vector [a]
forall a b c. (a -> b -> c) -> Vector a -> Vector b -> Vector c
V.zipWith (((a, a) -> [a]) -> a -> a -> [a]
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (a, a) -> [a]
forall a. Ix a => (a, a) -> [a]
range) Vector a
lc Vector a
uc
    lc :: Vector a
lc     = v a -> Vector a
forall (v :: * -> *) a (w :: * -> *).
(Vector v a, Vector w a) =>
v a -> w a
VG.convert v a
l
    uc :: Vector a
uc     = v a -> Vector a
forall (v :: * -> *) a (w :: * -> *).
(Vector v a, Vector w a) =>
v a -> w a
VG.convert v a
u
    enumerate :: Vector [a] -> [v a]
enumerate Vector [a]
v | Vector [a] -> Bool
forall a. Vector a -> Bool
V.null Vector [a]
v  = [v a
forall (v :: * -> *) a. Vector v a => v a
VG.empty]
                | Bool
otherwise = ([a] -> v a) -> [[a]] -> [v a]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> v a
forall (v :: * -> *) a. Vector v a => [a] -> v a
VG.fromList ([[a]] -> [v a]) -> [[a]] -> [v a]
forall a b. (a -> b) -> a -> b
$ [[a]] -> [[a]]
forall {a}. [[a]] -> [[a]]
enumerate' (Vector [a] -> [[a]]
forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList Vector [a]
v)
    enumerate' :: [[a]] -> [[a]]
enumerate' []         = [[]]
    enumerate' ([a]
xs : [[a]]
xss) = [ a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs' | a
x <- [a]
xs, [a]
xs' <- [[a]] -> [[a]]
enumerate' [[a]]
xss ]

-- index/unsafeIndex is consistent with
-- index :: ((a,..,a), (a,..,a)) -> (a,..,a) -> Int
  unsafeIndex :: (Vector v n a, Vector v n a) -> Vector v n a -> Int
unsafeIndex (Vector v a
l, Vector v a
u) (Vector v a
i) = (Int -> (Int, Int) -> Int) -> Int -> Vector (Int, Int) -> Int
forall a b. (a -> b -> a) -> a -> Vector b -> a
V.foldl' Int -> (Int, Int) -> Int
forall {a}. Num a => a -> (a, a) -> a
f Int
0 Vector (Int, Int)
v
   where
    f :: a -> (a, a) -> a
f a
acc (a
index', a
rangeSize') = a
acc a -> a -> a
forall a. Num a => a -> a -> a
* a
rangeSize' a -> a -> a
forall a. Num a => a -> a -> a
+ a
index'
    v :: Vector (Int, Int)
v            = (a -> a -> a -> (Int, Int))
-> Vector a -> Vector a -> Vector a -> Vector (Int, Int)
forall a b c d.
(a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
V.zipWith3 a -> a -> a -> (Int, Int)
forall {a}. Ix a => a -> a -> a -> (Int, Int)
indexAndRangeSize Vector a
lc Vector a
uc Vector a
ic
    (Vector a
lc, Vector a
uc, Vector a
ic) = v a -> v a -> v a -> (Vector a, Vector a, Vector a)
forall (v1 :: * -> *) a (w1 :: * -> *) (v2 :: * -> *) b
       (w2 :: * -> *) (v3 :: * -> *) c (w3 :: * -> *).
(Vector v1 a, Vector w1 a, Vector v2 b, Vector w2 b, Vector v3 c,
 Vector w3 c) =>
v1 a -> v2 b -> v3 c -> (w1 a, w2 b, w3 c)
convert3 v a
l v a
u v a
i
    indexAndRangeSize :: a -> a -> a -> (Int, Int)
indexAndRangeSize a
l' a
u' a
i' =
      let b' :: (a, a)
b' = (a
l', a
u') in ((a, a) -> a -> Int
forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a, a)
b' a
i', (a, a) -> Int
forall a. Ix a => (a, a) -> Int
unsafeRangeSize (a, a)
b')

-- i is in range (l, u) if, and only if, that is true for all elements,
-- element-by-element
  inRange :: (Vector v n a, Vector v n a) -> Vector v n a -> Bool
inRange (Vector v a
l, Vector v a
u) (Vector v a
i) = Vector Bool -> Bool
V.and
    (Vector Bool -> Bool) -> Vector Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (a -> a -> a -> Bool)
-> Vector a -> Vector a -> Vector a -> Vector Bool
forall a b c d.
(a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
V.zipWith3 (((a, a) -> a -> Bool) -> a -> a -> a -> Bool
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (a, a) -> a -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange) Vector a
lc Vector a
uc Vector a
ic
    where (Vector a
lc, Vector a
uc, Vector a
ic) = v a -> v a -> v a -> (Vector a, Vector a, Vector a)
forall (v1 :: * -> *) a (w1 :: * -> *) (v2 :: * -> *) b
       (w2 :: * -> *) (v3 :: * -> *) c (w3 :: * -> *).
(Vector v1 a, Vector w1 a, Vector v2 b, Vector w2 b, Vector v3 c,
 Vector w3 c) =>
v1 a -> v2 b -> v3 c -> (w1 a, w2 b, w3 c)
convert3 v a
l v a
u v a
i

-- Conversion helper
{-# INLINE convert3 #-}
convert3
  :: ( VG.Vector v1 a
     , VG.Vector w1 a
     , VG.Vector v2 b
     , VG.Vector w2 b
     , VG.Vector v3 c
     , VG.Vector w3 c
     )
  => v1 a
  -> v2 b
  -> v3 c
  -> (w1 a, w2 b, w3 c)
convert3 :: forall (v1 :: * -> *) a (w1 :: * -> *) (v2 :: * -> *) b
       (w2 :: * -> *) (v3 :: * -> *) c (w3 :: * -> *).
(Vector v1 a, Vector w1 a, Vector v2 b, Vector w2 b, Vector v3 c,
 Vector w3 c) =>
v1 a -> v2 b -> v3 c -> (w1 a, w2 b, w3 c)
convert3 v1 a
v1 v2 b
v2 v3 c
v3 = (v1 a -> w1 a
forall (v :: * -> *) a (w :: * -> *).
(Vector v a, Vector w a) =>
v a -> w a
VG.convert v1 a
v1, v2 b -> w2 b
forall (v :: * -> *) a (w :: * -> *).
(Vector v a, Vector w a) =>
v a -> w a
VG.convert v2 b
v2, v3 c -> w3 c
forall (v :: * -> *) a (w :: * -> *).
(Vector v a, Vector w a) =>
v a -> w a
VG.convert v3 c
v3)