{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_HADDOCK hide #-}
-- |
-- Module      : Data.Vector.Unboxed.Base
-- Copyright   : (c) Roman Leshchinskiy 2009-2010
--                   Alexey Kuleshevich 2020-2022
--                   Aleksey Khudyakov 2020-2022
--                   Andrew Lelechenko 2020-2022
-- License     : BSD-style
--
-- Maintainer  : Haskell Libraries Team <libraries@haskell.org>
-- Stability   : experimental
-- Portability : non-portable
--
-- Adaptive unboxed vectors: basic implementation.

module Data.Vector.Unboxed.Base (
  MVector(..), IOVector, STVector, Vector(..), Unbox,
  UnboxViaPrim(..), As(..), IsoUnbox(..)
) where

import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as M

import qualified Data.Vector.Primitive as P

import Control.Applicative (Const(..))

import Control.DeepSeq ( NFData(rnf)
#if MIN_VERSION_deepseq(1,4,3)
                       , NFData1(liftRnf)
#endif
                       )

import Control.Monad.Primitive
import Control.Monad ( liftM )

import Data.Functor.Identity
import Data.Functor.Compose
import Data.Word ( Word8, Word16, Word32, Word64 )
import Data.Int  ( Int8, Int16, Int32, Int64 )
import Data.Complex
import Data.Monoid (Dual(..),Sum(..),Product(..),All(..),Any(..))
import Data.Monoid (Alt(..))
import Data.Semigroup (Min(..),Max(..),First(..),Last(..),WrappedMonoid(..),Arg(..))
import Data.Typeable ( Typeable )
import Data.Data     ( Data(..) )
import GHC.Exts      ( Down(..) )
import GHC.Generics
import Data.Coerce
import Data.Kind     (Type)

-- Data.Vector.Internal.Check is unused
#define NOT_VECTOR_MODULE
#include "vector.h"

data family MVector s a
data family Vector    a

type IOVector = MVector RealWorld
type STVector s = MVector s

type instance G.Mutable Vector = MVector

class (G.Vector Vector a, M.MVector MVector a) => Unbox a

instance NFData (Vector a) where rnf :: Vector a -> ()
rnf !Vector a
_ = ()
instance NFData (MVector s a) where rnf :: MVector s a -> ()
rnf !MVector s a
_ = ()

#if MIN_VERSION_deepseq(1,4,3)
-- | @since 0.12.1.0
instance NFData1 Vector where
  liftRnf :: forall a. (a -> ()) -> Vector a -> ()
liftRnf a -> ()
_ !Vector a
_ = ()
-- | @since 0.12.1.0
instance NFData1 (MVector s) where
  liftRnf :: forall a. (a -> ()) -> MVector s a -> ()
liftRnf a -> ()
_ !MVector s a
_ = ()
#endif

-- -----------------
-- Data and Typeable
-- -----------------
deriving instance Typeable Vector
deriving instance Typeable MVector

instance (Data a, Unbox a) => Data (Vector a) where
  gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector a -> c (Vector a)
gfoldl       = (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Vector a -> c (Vector a)
forall (v :: * -> *) a (c :: * -> *).
(Vector v a, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> v a -> c (v a)
G.gfoldl
  toConstr :: Vector a -> Constr
toConstr Vector a
_   = String -> Constr
G.mkVecConstr String
"Data.Vector.Unboxed.Vector"
  gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector a)
gunfold      = (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Vector a)
forall (v :: * -> *) a (c :: * -> *).
(Vector v a, Data a, HasCallStack) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (v a)
G.gunfold
  dataTypeOf :: Vector a -> DataType
dataTypeOf Vector a
_ = String -> DataType
G.mkVecType String
"Data.Vector.Unboxed.Vector"
  dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Vector a))
dataCast1    = (forall d. Data d => c (t d)) -> Maybe (c (Vector a))
forall (v :: * -> *) a (t :: * -> *) (c :: * -> *).
(Vector v a, Data a, Typeable v, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (v a))
G.dataCast

-- ----
-- Unit
-- ----

newtype instance MVector s () = MV_Unit Int
newtype instance Vector    () = V_Unit Int

instance Unbox ()

instance M.MVector MVector () where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}

  basicLength :: forall s. MVector s () -> Int
basicLength (MV_Unit Int
n) = Int
n

  basicUnsafeSlice :: forall s. Int -> Int -> MVector s () -> MVector s ()
basicUnsafeSlice Int
_ Int
m (MV_Unit Int
_) = Int -> MVector s ()
forall s. Int -> MVector s ()
MV_Unit Int
m

  basicOverlaps :: forall s. MVector s () -> MVector s () -> Bool
basicOverlaps MVector s ()
_ MVector s ()
_ = Bool
False

  basicUnsafeNew :: forall s. Int -> ST s (MVector s ())
basicUnsafeNew Int
n = MVector s () -> ST s (MVector s ())
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> MVector s ()
forall s. Int -> MVector s ()
MV_Unit Int
n)

  -- Nothing to initialize
  basicInitialize :: forall s. MVector s () -> ST s ()
basicInitialize MVector s ()
_ = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeRead :: forall s. MVector s () -> Int -> ST s ()
basicUnsafeRead (MV_Unit Int
_) Int
_ = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeWrite :: forall s. MVector s () -> Int -> () -> ST s ()
basicUnsafeWrite (MV_Unit Int
_) Int
_ () = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicClear :: forall s. MVector s () -> ST s ()
basicClear MVector s ()
_ = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicSet :: forall s. MVector s () -> () -> ST s ()
basicSet (MV_Unit Int
_) () = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeCopy :: forall s. MVector s () -> MVector s () -> ST s ()
basicUnsafeCopy (MV_Unit Int
_) (MV_Unit Int
_) = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  basicUnsafeGrow :: forall s. MVector s () -> Int -> ST s (MVector s ())
basicUnsafeGrow (MV_Unit Int
n) Int
m = MVector s () -> ST s (MVector s ())
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return (MVector s () -> ST s (MVector s ()))
-> MVector s () -> ST s (MVector s ())
forall a b. (a -> b) -> a -> b
$ Int -> MVector s ()
forall s. Int -> MVector s ()
MV_Unit (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
m)

instance G.Vector Vector () where
  {-# INLINE basicUnsafeFreeze #-}
  basicUnsafeFreeze :: forall s. Mutable Vector s () -> ST s (Vector ())
basicUnsafeFreeze (MV_Unit Int
n) = Vector () -> ST s (Vector ())
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector () -> ST s (Vector ())) -> Vector () -> ST s (Vector ())
forall a b. (a -> b) -> a -> b
$ Int -> Vector ()
V_Unit Int
n

  {-# INLINE basicUnsafeThaw #-}
  basicUnsafeThaw :: forall s. Vector () -> ST s (Mutable Vector s ())
basicUnsafeThaw (V_Unit Int
n) = Mutable Vector s () -> ST s (Mutable Vector s ())
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Mutable Vector s () -> ST s (Mutable Vector s ()))
-> Mutable Vector s () -> ST s (Mutable Vector s ())
forall a b. (a -> b) -> a -> b
$ Int -> MVector s ()
forall s. Int -> MVector s ()
MV_Unit Int
n

  {-# INLINE basicLength #-}
  basicLength :: Vector () -> Int
basicLength (V_Unit Int
n) = Int
n

  {-# INLINE basicUnsafeSlice #-}
  basicUnsafeSlice :: Int -> Int -> Vector () -> Vector ()
basicUnsafeSlice Int
_ Int
m (V_Unit Int
_) = Int -> Vector ()
V_Unit Int
m

  {-# INLINE basicUnsafeIndexM #-}
  basicUnsafeIndexM :: Vector () -> Int -> Box ()
basicUnsafeIndexM (V_Unit Int
_) Int
_ = () -> Box ()
forall a. a -> Box a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  {-# INLINE basicUnsafeCopy #-}
  basicUnsafeCopy :: forall s. Mutable Vector s () -> Vector () -> ST s ()
basicUnsafeCopy (MV_Unit Int
_) (V_Unit Int
_) = () -> ST s ()
forall a. a -> ST s a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

  {-# INLINE elemseq #-}
  elemseq :: forall b. Vector () -> () -> b -> b
elemseq Vector ()
_ = () -> b -> b
forall a b. a -> b -> b
seq


-- ---------------
-- Primitive types
-- ---------------

-- | Newtype wrapper which allows to derive unboxed vector in term of
-- primitive vectors using @DerivingVia@ mechanism. This is mostly
-- used as illustration of use of @DerivingVia@ for vector, see examples below.
--
-- First is rather straightforward: we define newtype and use GND to
-- derive 'P.Prim' instance. Newtype instances should be defined
-- manually. Then we use deriving via to define necessary instances.
--
-- >>> :set -XTypeFamilies -XStandaloneDeriving -XDerivingVia -XMultiParamTypeClasses
-- >>> -- Needed to derive Prim
-- >>> :set -XGeneralizedNewtypeDeriving -XDataKinds -XUnboxedTuples -XPolyKinds
-- >>>
-- >>> import qualified Data.Vector.Generic         as VG
-- >>> import qualified Data.Vector.Generic.Mutable as VGM
-- >>> import qualified Data.Vector.Primitive       as VP
-- >>> import qualified Data.Vector.Unboxed         as VU
-- >>>
-- >>> newtype Foo = Foo Int deriving VP.Prim
-- >>>
-- >>> newtype instance VU.MVector s Foo = MV_Int (VP.MVector s Foo)
-- >>> newtype instance VU.Vector    Foo = V_Int  (VP.Vector    Foo)
-- >>> deriving via (VU.UnboxViaPrim Foo) instance VGM.MVector VU.MVector Foo
-- >>> deriving via (VU.UnboxViaPrim Foo) instance VG.Vector   VU.Vector  Foo
-- >>> instance VU.Unbox Foo
--
-- Second example is essentially same but with a twist. Instead of
-- using @Prim@ instance of data type, we use underlying instance of @Int@:
--
-- >>> :set -XTypeFamilies -XStandaloneDeriving -XDerivingVia -XMultiParamTypeClasses
-- >>>
-- >>> import qualified Data.Vector.Generic         as VG
-- >>> import qualified Data.Vector.Generic.Mutable as VGM
-- >>> import qualified Data.Vector.Primitive       as VP
-- >>> import qualified Data.Vector.Unboxed         as VU
-- >>>
-- >>> newtype Foo = Foo Int
-- >>>
-- >>> newtype instance VU.MVector s Foo = MV_Int (VP.MVector s Int)
-- >>> newtype instance VU.Vector    Foo = V_Int  (VP.Vector    Int)
-- >>> deriving via (VU.UnboxViaPrim Int) instance VGM.MVector VU.MVector Foo
-- >>> deriving via (VU.UnboxViaPrim Int) instance VG.Vector   VU.Vector  Foo
-- >>> instance VU.Unbox Foo
--
-- @since 0.13.0.0
newtype UnboxViaPrim a = UnboxViaPrim a

newtype instance MVector s (UnboxViaPrim a) = MV_UnboxViaPrim (P.MVector s a)
newtype instance Vector    (UnboxViaPrim a) = V_UnboxViaPrim (P.Vector a)

instance P.Prim a => M.MVector MVector (UnboxViaPrim a) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: forall s. MVector s (UnboxViaPrim a) -> Int
basicLength          = (MVector s a -> Int) -> MVector s (UnboxViaPrim a) -> Int
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> Int) -> MVector s (UnboxViaPrim a) -> Int)
-> (MVector s a -> Int) -> MVector s (UnboxViaPrim a) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength          @P.MVector @a
  basicUnsafeSlice :: forall s.
Int
-> Int -> MVector s (UnboxViaPrim a) -> MVector s (UnboxViaPrim a)
basicUnsafeSlice     = (Int -> Int -> MVector s a -> MVector s a)
-> Int
-> Int
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> MVector s a -> MVector s a)
 -> Int
 -> Int
 -> MVector s (UnboxViaPrim a)
 -> MVector s (UnboxViaPrim a))
-> (Int -> Int -> MVector s a -> MVector s a)
-> Int
-> Int
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice     @P.MVector @a
  basicOverlaps :: forall s.
MVector s (UnboxViaPrim a) -> MVector s (UnboxViaPrim a) -> Bool
basicOverlaps        = (MVector s a -> MVector s a -> Bool)
-> MVector s (UnboxViaPrim a) -> MVector s (UnboxViaPrim a) -> Bool
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> MVector s a -> Bool)
 -> MVector s (UnboxViaPrim a)
 -> MVector s (UnboxViaPrim a)
 -> Bool)
-> (MVector s a -> MVector s a -> Bool)
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
-> Bool
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps        @P.MVector @a
  basicUnsafeNew :: forall s. Int -> ST s (MVector s (UnboxViaPrim a))
basicUnsafeNew       = (Int -> ST s (MVector s a))
-> Int -> ST s (MVector s (UnboxViaPrim a))
forall a b. Coercible a b => a -> b
coerce ((Int -> ST s (MVector s a))
 -> Int -> ST s (MVector s (UnboxViaPrim a)))
-> (Int -> ST s (MVector s a))
-> Int
-> ST s (MVector s (UnboxViaPrim a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew       @P.MVector @a
  basicInitialize :: forall s. MVector s (UnboxViaPrim a) -> ST s ()
basicInitialize      = (MVector s a -> ST s ()) -> MVector s (UnboxViaPrim a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> ST s ()) -> MVector s (UnboxViaPrim a) -> ST s ())
-> (MVector s a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize      @P.MVector @a
  basicUnsafeReplicate :: forall s.
Int -> UnboxViaPrim a -> ST s (MVector s (UnboxViaPrim a))
basicUnsafeReplicate = (Int -> a -> ST s (MVector s a))
-> Int -> UnboxViaPrim a -> ST s (MVector s (UnboxViaPrim a))
forall a b. Coercible a b => a -> b
coerce ((Int -> a -> ST s (MVector s a))
 -> Int -> UnboxViaPrim a -> ST s (MVector s (UnboxViaPrim a)))
-> (Int -> a -> ST s (MVector s a))
-> Int
-> UnboxViaPrim a
-> ST s (MVector s (UnboxViaPrim a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
M.basicUnsafeReplicate @P.MVector @a
  basicUnsafeRead :: forall s.
MVector s (UnboxViaPrim a) -> Int -> ST s (UnboxViaPrim a)
basicUnsafeRead      = (MVector s a -> Int -> ST s a)
-> MVector s (UnboxViaPrim a) -> Int -> ST s (UnboxViaPrim a)
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> Int -> ST s a)
 -> MVector s (UnboxViaPrim a) -> Int -> ST s (UnboxViaPrim a))
-> (MVector s a -> Int -> ST s a)
-> MVector s (UnboxViaPrim a)
-> Int
-> ST s (UnboxViaPrim a)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead      @P.MVector @a
  basicUnsafeWrite :: forall s.
MVector s (UnboxViaPrim a) -> Int -> UnboxViaPrim a -> ST s ()
basicUnsafeWrite     = (MVector s a -> Int -> a -> ST s ())
-> MVector s (UnboxViaPrim a) -> Int -> UnboxViaPrim a -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> Int -> a -> ST s ())
 -> MVector s (UnboxViaPrim a) -> Int -> UnboxViaPrim a -> ST s ())
-> (MVector s a -> Int -> a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> Int
-> UnboxViaPrim a
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite     @P.MVector @a
  basicClear :: forall s. MVector s (UnboxViaPrim a) -> ST s ()
basicClear           = (MVector s a -> ST s ()) -> MVector s (UnboxViaPrim a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> ST s ()) -> MVector s (UnboxViaPrim a) -> ST s ())
-> (MVector s a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicClear           @P.MVector @a
  basicSet :: forall s. MVector s (UnboxViaPrim a) -> UnboxViaPrim a -> ST s ()
basicSet             = (MVector s a -> a -> ST s ())
-> MVector s (UnboxViaPrim a) -> UnboxViaPrim a -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> a -> ST s ())
 -> MVector s (UnboxViaPrim a) -> UnboxViaPrim a -> ST s ())
-> (MVector s a -> a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> UnboxViaPrim a
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
M.basicSet             @P.MVector @a
  basicUnsafeCopy :: forall s.
MVector s (UnboxViaPrim a) -> MVector s (UnboxViaPrim a) -> ST s ()
basicUnsafeCopy      = (MVector s a -> MVector s a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
-> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> MVector s a -> ST s ())
 -> MVector s (UnboxViaPrim a)
 -> MVector s (UnboxViaPrim a)
 -> ST s ())
-> (MVector s a -> MVector s a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeCopy      @P.MVector @a
  basicUnsafeMove :: forall s.
MVector s (UnboxViaPrim a) -> MVector s (UnboxViaPrim a) -> ST s ()
basicUnsafeMove      = (MVector s a -> MVector s a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
-> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> MVector s a -> ST s ())
 -> MVector s (UnboxViaPrim a)
 -> MVector s (UnboxViaPrim a)
 -> ST s ())
-> (MVector s a -> MVector s a -> ST s ())
-> MVector s (UnboxViaPrim a)
-> MVector s (UnboxViaPrim a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeMove      @P.MVector @a
  basicUnsafeGrow :: forall s.
MVector s (UnboxViaPrim a)
-> Int -> ST s (MVector s (UnboxViaPrim a))
basicUnsafeGrow      = (MVector s a -> Int -> ST s (MVector s a))
-> MVector s (UnboxViaPrim a)
-> Int
-> ST s (MVector s (UnboxViaPrim a))
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> Int -> ST s (MVector s a))
 -> MVector s (UnboxViaPrim a)
 -> Int
 -> ST s (MVector s (UnboxViaPrim a)))
-> (MVector s a -> Int -> ST s (MVector s a))
-> MVector s (UnboxViaPrim a)
-> Int
-> ST s (MVector s (UnboxViaPrim a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
M.basicUnsafeGrow      @P.MVector @a

instance P.Prim a => G.Vector Vector (UnboxViaPrim a) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeFreeze :: forall s.
Mutable Vector s (UnboxViaPrim a) -> ST s (Vector (UnboxViaPrim a))
basicUnsafeFreeze = (MVector s a -> ST s (Vector a))
-> Mutable Vector s (UnboxViaPrim a)
-> ST s (Vector (UnboxViaPrim a))
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> ST s (Vector a))
 -> Mutable Vector s (UnboxViaPrim a)
 -> ST s (Vector (UnboxViaPrim a)))
-> (MVector s a -> ST s (Vector a))
-> Mutable Vector s (UnboxViaPrim a)
-> ST s (Vector (UnboxViaPrim a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
G.basicUnsafeFreeze @P.Vector @a
  basicUnsafeThaw :: forall s.
Vector (UnboxViaPrim a) -> ST s (Mutable Vector s (UnboxViaPrim a))
basicUnsafeThaw   = (Vector a -> ST s (MVector s a))
-> Vector (UnboxViaPrim a)
-> ST s (Mutable Vector s (UnboxViaPrim a))
forall a b. Coercible a b => a -> b
coerce ((Vector a -> ST s (MVector s a))
 -> Vector (UnboxViaPrim a)
 -> ST s (Mutable Vector s (UnboxViaPrim a)))
-> (Vector a -> ST s (MVector s a))
-> Vector (UnboxViaPrim a)
-> ST s (Mutable Vector s (UnboxViaPrim a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw   @P.Vector @a
  basicLength :: Vector (UnboxViaPrim a) -> Int
basicLength       = (Vector a -> Int) -> Vector (UnboxViaPrim a) -> Int
forall a b. Coercible a b => a -> b
coerce ((Vector a -> Int) -> Vector (UnboxViaPrim a) -> Int)
-> (Vector a -> Int) -> Vector (UnboxViaPrim a) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength       @P.Vector @a
  basicUnsafeSlice :: Int -> Int -> Vector (UnboxViaPrim a) -> Vector (UnboxViaPrim a)
basicUnsafeSlice  = (Int -> Int -> Vector a -> Vector a)
-> Int -> Int -> Vector (UnboxViaPrim a) -> Vector (UnboxViaPrim a)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> Vector a -> Vector a)
 -> Int
 -> Int
 -> Vector (UnboxViaPrim a)
 -> Vector (UnboxViaPrim a))
-> (Int -> Int -> Vector a -> Vector a)
-> Int
-> Int
-> Vector (UnboxViaPrim a)
-> Vector (UnboxViaPrim a)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice  @P.Vector @a
  basicUnsafeIndexM :: Vector (UnboxViaPrim a) -> Int -> Box (UnboxViaPrim a)
basicUnsafeIndexM = (Vector a -> Int -> Box a)
-> Vector (UnboxViaPrim a) -> Int -> Box (UnboxViaPrim a)
forall a b. Coercible a b => a -> b
coerce ((Vector a -> Int -> Box a)
 -> Vector (UnboxViaPrim a) -> Int -> Box (UnboxViaPrim a))
-> (Vector a -> Int -> Box a)
-> Vector (UnboxViaPrim a)
-> Int
-> Box (UnboxViaPrim a)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM @P.Vector @a
  basicUnsafeCopy :: forall s.
Mutable Vector s (UnboxViaPrim a)
-> Vector (UnboxViaPrim a) -> ST s ()
basicUnsafeCopy   = (MVector s a -> Vector a -> ST s ())
-> Mutable Vector s (UnboxViaPrim a)
-> Vector (UnboxViaPrim a)
-> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s a -> Vector a -> ST s ())
 -> Mutable Vector s (UnboxViaPrim a)
 -> Vector (UnboxViaPrim a)
 -> ST s ())
-> (MVector s a -> Vector a -> ST s ())
-> Mutable Vector s (UnboxViaPrim a)
-> Vector (UnboxViaPrim a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
G.basicUnsafeCopy   @P.Vector @a
  elemseq :: forall b. Vector (UnboxViaPrim a) -> UnboxViaPrim a -> b -> b
elemseq Vector (UnboxViaPrim a)
_ = UnboxViaPrim a -> b -> b
forall a b. a -> b -> b
seq

-- | Isomorphism between type @a@ and its representation in unboxed
-- vector @b@. Default instance coerces between generic
-- representations of @a@ and @b@ which means they have same shape and
-- corresponding fields could be coerced to each other. Note that this
-- means it's possible to have fields that have different types:
--
-- >>> :set -XMultiParamTypeClasses -XDeriveGeneric -XFlexibleInstances
-- >>> import GHC.Generics (Generic)
-- >>> import Data.Monoid
-- >>> import qualified Data.Vector.Unboxed as VU
-- >>> :{
-- data Foo a = Foo Int a
--   deriving (Show,Generic)
-- instance VU.IsoUnbox (Foo a) (Int, a)
-- instance VU.IsoUnbox (Foo a) (Sum Int, Product a)
-- :}
--
-- @since 0.13.0.0
class IsoUnbox a b where
  -- | Convert value into it representation in unboxed vector.
  toURepr   :: a -> b
  default toURepr :: (Generic a, Generic b, Coercible (Rep a ()) (Rep b ())) => a -> b
  toURepr = Rep b () -> b
forall a x. Generic a => Rep a x -> a
forall x. Rep b x -> b
to (Rep b () -> b) -> (a -> Rep b ()) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep b () -> Rep b ()
forall (f :: * -> *). f () -> f ()
idU (Rep b () -> Rep b ()) -> (a -> Rep b ()) -> a -> Rep b ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep a () -> Rep b ()
forall a b. Coercible a b => a -> b
coerce (Rep a () -> Rep b ()) -> (a -> Rep a ()) -> a -> Rep b ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep a () -> Rep a ()
forall (f :: * -> *). f () -> f ()
idU (Rep a () -> Rep a ()) -> (a -> Rep a ()) -> a -> Rep a ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a ()
forall x. a -> Rep a x
forall a x. Generic a => a -> Rep a x
from
  -- | Convert value representation in unboxed vector back to value.
  fromURepr :: b -> a
  default fromURepr :: (Generic a, Generic b, Coercible (Rep b ()) (Rep a ())) => b -> a
  fromURepr = Rep a () -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
to (Rep a () -> a) -> (b -> Rep a ()) -> b -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep a () -> Rep a ()
forall (f :: * -> *). f () -> f ()
idU (Rep a () -> Rep a ()) -> (b -> Rep a ()) -> b -> Rep a ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep b () -> Rep a ()
forall a b. Coercible a b => a -> b
coerce (Rep b () -> Rep a ()) -> (b -> Rep b ()) -> b -> Rep a ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep b () -> Rep b ()
forall (f :: * -> *). f () -> f ()
idU (Rep b () -> Rep b ()) -> (b -> Rep b ()) -> b -> Rep b ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Rep b ()
forall x. b -> Rep b x
forall a x. Generic a => a -> Rep a x
from

idU :: f () -> f ()
idU :: forall (f :: * -> *). f () -> f ()
idU = f () -> f ()
forall a. a -> a
id


-- | Newtype which allows to derive unbox instances for type @a@ which
-- uses @b@ as underlying representation (usually tuple). Type @a@ and
-- its representation @b@ are connected by type class
-- 'IsoUnbox'. Here's example which uses explicit 'IsoUnbox' instance:
--
--
-- >>> :set -XTypeFamilies -XStandaloneDeriving -XDerivingVia
-- >>> :set -XMultiParamTypeClasses -XTypeOperators -XFlexibleInstances
-- >>> import qualified Data.Vector.Unboxed         as VU
-- >>> import qualified Data.Vector.Unboxed.Mutable as MVU
-- >>> import qualified Data.Vector.Generic         as VG
-- >>> import qualified Data.Vector.Generic.Mutable as VGM
-- >>> :{
-- data Foo a = Foo Int a
--   deriving Show
-- instance VU.IsoUnbox (Foo a) (Int,a) where
--   toURepr (Foo i a) = (i,a)
--   fromURepr (i,a) = Foo i a
--   {-# INLINE toURepr #-}
--   {-# INLINE fromURepr #-}
-- newtype instance VU.MVector s (Foo a) = MV_Foo (VU.MVector s (Int, a))
-- newtype instance VU.Vector    (Foo a) = V_Foo  (VU.Vector    (Int, a))
-- deriving via (Foo a `VU.As` (Int, a)) instance VU.Unbox a => VGM.MVector MVU.MVector (Foo a)
-- deriving via (Foo a `VU.As` (Int, a)) instance VU.Unbox a => VG.Vector   VU.Vector   (Foo a)
-- instance VU.Unbox a => VU.Unbox (Foo a)
-- :}
--
--
-- It's also possible to use generic-based instance for 'IsoUnbox'
-- which should work for all product types.
--
-- >>> :set -XMultiParamTypeClasses -XTypeOperators -XFlexibleInstances -XDeriveGeneric
-- >>> :set -XDerivingVia
-- >>> import qualified Data.Vector.Unboxed         as VU
-- >>> import qualified Data.Vector.Generic         as VG
-- >>> import qualified Data.Vector.Generic.Mutable as VGM
-- >>> :{
-- data Bar a = Bar Int a
--   deriving (Show,Generic)
-- instance VU.IsoUnbox (Bar a) (Int,a) where
-- newtype instance VU.MVector s (Bar a) = MV_Bar (VU.MVector s (Int, a))
-- newtype instance VU.Vector    (Bar a) = V_Bar  (VU.Vector    (Int, a))
-- deriving via (Bar a `VU.As` (Int, a)) instance VU.Unbox a => VGM.MVector VU.MVector (Bar a)
-- deriving via (Bar a `VU.As` (Int, a)) instance VU.Unbox a => VG.Vector  VU.Vector  (Bar a)
-- instance VU.Unbox a => VU.Unbox (Bar a)
-- :}
--
-- @since 0.13.0.0
newtype As (a :: Type) (b :: Type) = As a

newtype instance MVector s (As a b) = MV_UnboxAs (MVector s b)
newtype instance Vector    (As a b) = V_UnboxAs  (Vector b)

instance (IsoUnbox a b, Unbox b) => M.MVector MVector (As a b) where
  -- Methods that just use underlying vector
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeMove #-}
  {-# INLINE basicUnsafeGrow #-}
  {-# INLINE basicClear #-}
  basicLength :: forall s. MVector s (As a b) -> Int
basicLength      = (MVector s b -> Int) -> MVector s (As a b) -> Int
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> Int) -> MVector s (As a b) -> Int)
-> (MVector s b -> Int) -> MVector s (As a b) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength      @MVector @b
  basicUnsafeSlice :: forall s. Int -> Int -> MVector s (As a b) -> MVector s (As a b)
basicUnsafeSlice = (Int -> Int -> MVector s b -> MVector s b)
-> Int -> Int -> MVector s (As a b) -> MVector s (As a b)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> MVector s b -> MVector s b)
 -> Int -> Int -> MVector s (As a b) -> MVector s (As a b))
-> (Int -> Int -> MVector s b -> MVector s b)
-> Int
-> Int
-> MVector s (As a b)
-> MVector s (As a b)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice @MVector @b
  basicOverlaps :: forall s. MVector s (As a b) -> MVector s (As a b) -> Bool
basicOverlaps    = (MVector s b -> MVector s b -> Bool)
-> MVector s (As a b) -> MVector s (As a b) -> Bool
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> MVector s b -> Bool)
 -> MVector s (As a b) -> MVector s (As a b) -> Bool)
-> (MVector s b -> MVector s b -> Bool)
-> MVector s (As a b)
-> MVector s (As a b)
-> Bool
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps    @MVector @b
  basicUnsafeNew :: forall s. Int -> ST s (MVector s (As a b))
basicUnsafeNew   = (Int -> ST s (MVector s b)) -> Int -> ST s (MVector s (As a b))
forall a b. Coercible a b => a -> b
coerce ((Int -> ST s (MVector s b)) -> Int -> ST s (MVector s (As a b)))
-> (Int -> ST s (MVector s b)) -> Int -> ST s (MVector s (As a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew   @MVector @b
  basicInitialize :: forall s. MVector s (As a b) -> ST s ()
basicInitialize  = (MVector s b -> ST s ()) -> MVector s (As a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> ST s ()) -> MVector s (As a b) -> ST s ())
-> (MVector s b -> ST s ()) -> MVector s (As a b) -> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize  @MVector @b
  basicUnsafeCopy :: forall s. MVector s (As a b) -> MVector s (As a b) -> ST s ()
basicUnsafeCopy  = (MVector s b -> MVector s b -> ST s ())
-> MVector s (As a b) -> MVector s (As a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> MVector s b -> ST s ())
 -> MVector s (As a b) -> MVector s (As a b) -> ST s ())
-> (MVector s b -> MVector s b -> ST s ())
-> MVector s (As a b)
-> MVector s (As a b)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeCopy  @MVector @b
  basicUnsafeMove :: forall s. MVector s (As a b) -> MVector s (As a b) -> ST s ()
basicUnsafeMove  = (MVector s b -> MVector s b -> ST s ())
-> MVector s (As a b) -> MVector s (As a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> MVector s b -> ST s ())
 -> MVector s (As a b) -> MVector s (As a b) -> ST s ())
-> (MVector s b -> MVector s b -> ST s ())
-> MVector s (As a b)
-> MVector s (As a b)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeMove  @MVector @b
  basicUnsafeGrow :: forall s. MVector s (As a b) -> Int -> ST s (MVector s (As a b))
basicUnsafeGrow  = (MVector s b -> Int -> ST s (MVector s b))
-> MVector s (As a b) -> Int -> ST s (MVector s (As a b))
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> Int -> ST s (MVector s b))
 -> MVector s (As a b) -> Int -> ST s (MVector s (As a b)))
-> (MVector s b -> Int -> ST s (MVector s b))
-> MVector s (As a b)
-> Int
-> ST s (MVector s (As a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
M.basicUnsafeGrow  @MVector @b
  basicClear :: forall s. MVector s (As a b) -> ST s ()
basicClear       = (MVector s b -> ST s ()) -> MVector s (As a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> ST s ()) -> MVector s (As a b) -> ST s ())
-> (MVector s b -> ST s ()) -> MVector s (As a b) -> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicClear       @MVector @b
  -- Conversion to/from underlying representation
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicSet #-}
  basicUnsafeReplicate :: forall s. Int -> As a b -> ST s (MVector s (As a b))
basicUnsafeReplicate Int
n (As a
x) = MVector s b -> MVector s (As a b)
forall s a b. MVector s b -> MVector s (As a b)
MV_UnboxAs (MVector s b -> MVector s (As a b))
-> ST s (MVector s b) -> ST s (MVector s (As a b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> b -> ST s (MVector s b)
forall s. Int -> b -> ST s (MVector s b)
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
M.basicUnsafeReplicate Int
n (a -> b
forall a b. IsoUnbox a b => a -> b
toURepr a
x)
  basicUnsafeRead :: forall s. MVector s (As a b) -> Int -> ST s (As a b)
basicUnsafeRead (MV_UnboxAs MVector s b
v) Int
i = a -> As a b
forall a b. a -> As a b
As (a -> As a b) -> (b -> a) -> b -> As a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
forall a b. IsoUnbox a b => b -> a
fromURepr (b -> As a b) -> ST s b -> ST s (As a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector s b -> Int -> ST s b
forall s. MVector s b -> Int -> ST s b
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s b
v Int
i
  basicUnsafeWrite :: forall s. MVector s (As a b) -> Int -> As a b -> ST s ()
basicUnsafeWrite (MV_UnboxAs MVector s b
v) Int
i (As a
x) = MVector s b -> Int -> b -> ST s ()
forall s. MVector s b -> Int -> b -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s b
v Int
i (a -> b
forall a b. IsoUnbox a b => a -> b
toURepr a
x)
  basicSet :: forall s. MVector s (As a b) -> As a b -> ST s ()
basicSet (MV_UnboxAs MVector s b
v) (As a
x) = MVector s b -> b -> ST s ()
forall s. MVector s b -> b -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
M.basicSet MVector s b
v (a -> b
forall a b. IsoUnbox a b => a -> b
toURepr a
x)

instance (IsoUnbox a b, Unbox b) => G.Vector Vector (As a b) where
  -- Method that just use underlying vector
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE elemseq #-}
  basicUnsafeFreeze :: forall s. Mutable Vector s (As a b) -> ST s (Vector (As a b))
basicUnsafeFreeze = (MVector s b -> ST s (Vector b))
-> Mutable Vector s (As a b) -> ST s (Vector (As a b))
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> ST s (Vector b))
 -> Mutable Vector s (As a b) -> ST s (Vector (As a b)))
-> (MVector s b -> ST s (Vector b))
-> Mutable Vector s (As a b)
-> ST s (Vector (As a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
G.basicUnsafeFreeze @Vector @b
  basicUnsafeThaw :: forall s. Vector (As a b) -> ST s (Mutable Vector s (As a b))
basicUnsafeThaw   = (Vector b -> ST s (MVector s b))
-> Vector (As a b) -> ST s (Mutable Vector s (As a b))
forall a b. Coercible a b => a -> b
coerce ((Vector b -> ST s (MVector s b))
 -> Vector (As a b) -> ST s (Mutable Vector s (As a b)))
-> (Vector b -> ST s (MVector s b))
-> Vector (As a b)
-> ST s (Mutable Vector s (As a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw   @Vector @b
  basicLength :: Vector (As a b) -> Int
basicLength       = (Vector b -> Int) -> Vector (As a b) -> Int
forall a b. Coercible a b => a -> b
coerce ((Vector b -> Int) -> Vector (As a b) -> Int)
-> (Vector b -> Int) -> Vector (As a b) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength       @Vector @b
  basicUnsafeSlice :: Int -> Int -> Vector (As a b) -> Vector (As a b)
basicUnsafeSlice  = (Int -> Int -> Vector b -> Vector b)
-> Int -> Int -> Vector (As a b) -> Vector (As a b)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> Vector b -> Vector b)
 -> Int -> Int -> Vector (As a b) -> Vector (As a b))
-> (Int -> Int -> Vector b -> Vector b)
-> Int
-> Int
-> Vector (As a b)
-> Vector (As a b)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice  @Vector @b
  basicUnsafeCopy :: forall s. Mutable Vector s (As a b) -> Vector (As a b) -> ST s ()
basicUnsafeCopy   = (MVector s b -> Vector b -> ST s ())
-> Mutable Vector s (As a b) -> Vector (As a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s b -> Vector b -> ST s ())
 -> Mutable Vector s (As a b) -> Vector (As a b) -> ST s ())
-> (MVector s b -> Vector b -> ST s ())
-> Mutable Vector s (As a b)
-> Vector (As a b)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
G.basicUnsafeCopy   @Vector @b
  elemseq :: forall b. Vector (As a b) -> As a b -> b -> b
elemseq Vector (As a b)
_         = As a b -> b -> b
forall a b. a -> b -> b
seq
  -- Conversion to/from underlying representation
  {-# INLINE basicUnsafeIndexM #-}
  basicUnsafeIndexM :: Vector (As a b) -> Int -> Box (As a b)
basicUnsafeIndexM (V_UnboxAs Vector b
v) Int
i = a -> As a b
forall a b. a -> As a b
As (a -> As a b) -> (b -> a) -> b -> As a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
forall a b. IsoUnbox a b => b -> a
fromURepr (b -> As a b) -> Box b -> Box (As a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector b -> Int -> Box b
forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector b
v Int
i


#define primMVector(ty,con)                                             \
instance M.MVector MVector ty where {                                   \
  {-# INLINE basicLength #-}                                            \
; {-# INLINE basicUnsafeSlice #-}                                       \
; {-# INLINE basicOverlaps #-}                                          \
; {-# INLINE basicUnsafeNew #-}                                         \
; {-# INLINE basicInitialize #-}                                        \
; {-# INLINE basicUnsafeReplicate #-}                                   \
; {-# INLINE basicUnsafeRead #-}                                        \
; {-# INLINE basicUnsafeWrite #-}                                       \
; {-# INLINE basicClear #-}                                             \
; {-# INLINE basicSet #-}                                               \
; {-# INLINE basicUnsafeCopy #-}                                        \
; {-# INLINE basicUnsafeGrow #-}                                        \
; basicLength (con v) = M.basicLength v                                 \
; basicUnsafeSlice i n (con v) = con $ M.basicUnsafeSlice i n v         \
; basicOverlaps (con v1) (con v2) = M.basicOverlaps v1 v2               \
; basicUnsafeNew n = con `liftM` M.basicUnsafeNew n                     \
; basicInitialize (con v) = M.basicInitialize v                         \
; basicUnsafeReplicate n x = con `liftM` M.basicUnsafeReplicate n x     \
; basicUnsafeRead (con v) i = M.basicUnsafeRead v i                     \
; basicUnsafeWrite (con v) i x = M.basicUnsafeWrite v i x               \
; basicClear (con v) = M.basicClear v                                   \
; basicSet (con v) x = M.basicSet v x                                   \
; basicUnsafeCopy (con v1) (con v2) = M.basicUnsafeCopy v1 v2           \
; basicUnsafeMove (con v1) (con v2) = M.basicUnsafeMove v1 v2           \
; basicUnsafeGrow (con v) n = con `liftM` M.basicUnsafeGrow v n }

#define primVector(ty,con,mcon)                                         \
instance G.Vector Vector ty where {                                     \
  {-# INLINE basicUnsafeFreeze #-}                                      \
; {-# INLINE basicUnsafeThaw #-}                                        \
; {-# INLINE basicLength #-}                                            \
; {-# INLINE basicUnsafeSlice #-}                                       \
; {-# INLINE basicUnsafeIndexM #-}                                      \
; {-# INLINE elemseq #-}                                                \
; basicUnsafeFreeze (mcon v) = con `liftM` G.basicUnsafeFreeze v        \
; basicUnsafeThaw (con v) = mcon `liftM` G.basicUnsafeThaw v            \
; basicLength (con v) = G.basicLength v                                 \
; basicUnsafeSlice i n (con v) = con $ G.basicUnsafeSlice i n v         \
; basicUnsafeIndexM (con v) i = G.basicUnsafeIndexM v i                 \
; basicUnsafeCopy (mcon mv) (con v) = G.basicUnsafeCopy mv v            \
; elemseq _ = seq }

newtype instance MVector s Int = MV_Int (P.MVector s Int)
newtype instance Vector    Int = V_Int  (P.Vector    Int)
instance Unbox Int
primMVector(Int, MV_Int)
primVector(Int, V_Int, MV_Int)

newtype instance MVector s Int8 = MV_Int8 (P.MVector s Int8)
newtype instance Vector    Int8 = V_Int8  (P.Vector    Int8)
instance Unbox Int8
primMVector(Int8, MV_Int8)
primVector(Int8, V_Int8, MV_Int8)

newtype instance MVector s Int16 = MV_Int16 (P.MVector s Int16)
newtype instance Vector    Int16 = V_Int16  (P.Vector    Int16)
instance Unbox Int16
primMVector(Int16, MV_Int16)
primVector(Int16, V_Int16, MV_Int16)

newtype instance MVector s Int32 = MV_Int32 (P.MVector s Int32)
newtype instance Vector    Int32 = V_Int32  (P.Vector    Int32)
instance Unbox Int32
primMVector(Int32, MV_Int32)
primVector(Int32, V_Int32, MV_Int32)

newtype instance MVector s Int64 = MV_Int64 (P.MVector s Int64)
newtype instance Vector    Int64 = V_Int64  (P.Vector    Int64)
instance Unbox Int64
primMVector(Int64, MV_Int64)
primVector(Int64, V_Int64, MV_Int64)


newtype instance MVector s Word = MV_Word (P.MVector s Word)
newtype instance Vector    Word = V_Word  (P.Vector    Word)
instance Unbox Word
primMVector(Word, MV_Word)
primVector(Word, V_Word, MV_Word)

newtype instance MVector s Word8 = MV_Word8 (P.MVector s Word8)
newtype instance Vector    Word8 = V_Word8  (P.Vector    Word8)
instance Unbox Word8
primMVector(Word8, MV_Word8)
primVector(Word8, V_Word8, MV_Word8)

newtype instance MVector s Word16 = MV_Word16 (P.MVector s Word16)
newtype instance Vector    Word16 = V_Word16  (P.Vector    Word16)
instance Unbox Word16
primMVector(Word16, MV_Word16)
primVector(Word16, V_Word16, MV_Word16)

newtype instance MVector s Word32 = MV_Word32 (P.MVector s Word32)
newtype instance Vector    Word32 = V_Word32  (P.Vector    Word32)
instance Unbox Word32
primMVector(Word32, MV_Word32)
primVector(Word32, V_Word32, MV_Word32)

newtype instance MVector s Word64 = MV_Word64 (P.MVector s Word64)
newtype instance Vector    Word64 = V_Word64  (P.Vector    Word64)
instance Unbox Word64
primMVector(Word64, MV_Word64)
primVector(Word64, V_Word64, MV_Word64)


newtype instance MVector s Float = MV_Float (P.MVector s Float)
newtype instance Vector    Float = V_Float  (P.Vector    Float)
instance Unbox Float
primMVector(Float, MV_Float)
primVector(Float, V_Float, MV_Float)

newtype instance MVector s Double = MV_Double (P.MVector s Double)
newtype instance Vector    Double = V_Double  (P.Vector    Double)
instance Unbox Double
primMVector(Double, MV_Double)
primVector(Double, V_Double, MV_Double)


newtype instance MVector s Char = MV_Char (P.MVector s Char)
newtype instance Vector    Char = V_Char  (P.Vector    Char)
instance Unbox Char
primMVector(Char, MV_Char)
primVector(Char, V_Char, MV_Char)

-- ----
-- Bool
-- ----

fromBool :: Bool -> Word8
{-# INLINE fromBool #-}
fromBool :: Bool -> Word8
fromBool Bool
True = Word8
1
fromBool Bool
False = Word8
0

toBool :: Word8 -> Bool
{-# INLINE toBool #-}
toBool :: Word8 -> Bool
toBool Word8
0 = Bool
False
toBool Word8
_ = Bool
True

newtype instance MVector s Bool = MV_Bool (P.MVector s Word8)
newtype instance Vector    Bool = V_Bool  (P.Vector    Word8)

instance Unbox Bool

instance M.MVector MVector Bool where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicSet #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: forall s. MVector s Bool -> Int
basicLength (MV_Bool MVector s Word8
v) = MVector s Word8 -> Int
forall s. MVector s Word8 -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength MVector s Word8
v
  basicUnsafeSlice :: forall s. Int -> Int -> MVector s Bool -> MVector s Bool
basicUnsafeSlice Int
i Int
n (MV_Bool MVector s Word8
v) = MVector s Word8 -> MVector s Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector s Word8 -> MVector s Bool)
-> MVector s Word8 -> MVector s Bool
forall a b. (a -> b) -> a -> b
$ Int -> Int -> MVector s Word8 -> MVector s Word8
forall s. Int -> Int -> MVector s Word8 -> MVector s Word8
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice Int
i Int
n MVector s Word8
v
  basicOverlaps :: forall s. MVector s Bool -> MVector s Bool -> Bool
basicOverlaps (MV_Bool MVector s Word8
v1) (MV_Bool MVector s Word8
v2) = MVector s Word8 -> MVector s Word8 -> Bool
forall s. MVector s Word8 -> MVector s Word8 -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps MVector s Word8
v1 MVector s Word8
v2
  basicUnsafeNew :: forall s. Int -> ST s (MVector s Bool)
basicUnsafeNew Int
n = MVector s Word8 -> MVector s Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector s Word8 -> MVector s Bool)
-> ST s (MVector s Word8) -> ST s (MVector s Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> ST s (MVector s Word8)
forall s. Int -> ST s (MVector s Word8)
forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew Int
n
  basicInitialize :: forall s. MVector s Bool -> ST s ()
basicInitialize (MV_Bool MVector s Word8
v) = MVector s Word8 -> ST s ()
forall s. MVector s Word8 -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize MVector s Word8
v
  basicUnsafeReplicate :: forall s. Int -> Bool -> ST s (MVector s Bool)
basicUnsafeReplicate Int
n Bool
x = MVector s Word8 -> MVector s Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector s Word8 -> MVector s Bool)
-> ST s (MVector s Word8) -> ST s (MVector s Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Int -> Word8 -> ST s (MVector s Word8)
forall s. Int -> Word8 -> ST s (MVector s Word8)
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
M.basicUnsafeReplicate Int
n (Bool -> Word8
fromBool Bool
x)
  basicUnsafeRead :: forall s. MVector s Bool -> Int -> ST s Bool
basicUnsafeRead (MV_Bool MVector s Word8
v) Int
i = Word8 -> Bool
toBool (Word8 -> Bool) -> ST s Word8 -> ST s Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector s Word8 -> Int -> ST s Word8
forall s. MVector s Word8 -> Int -> ST s Word8
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s Word8
v Int
i
  basicUnsafeWrite :: forall s. MVector s Bool -> Int -> Bool -> ST s ()
basicUnsafeWrite (MV_Bool MVector s Word8
v) Int
i Bool
x = MVector s Word8 -> Int -> Word8 -> ST s ()
forall s. MVector s Word8 -> Int -> Word8 -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s Word8
v Int
i (Bool -> Word8
fromBool Bool
x)
  basicClear :: forall s. MVector s Bool -> ST s ()
basicClear (MV_Bool MVector s Word8
v) = MVector s Word8 -> ST s ()
forall s. MVector s Word8 -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicClear MVector s Word8
v
  basicSet :: forall s. MVector s Bool -> Bool -> ST s ()
basicSet (MV_Bool MVector s Word8
v) Bool
x = MVector s Word8 -> Word8 -> ST s ()
forall s. MVector s Word8 -> Word8 -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
M.basicSet MVector s Word8
v (Bool -> Word8
fromBool Bool
x)
  basicUnsafeCopy :: forall s. MVector s Bool -> MVector s Bool -> ST s ()
basicUnsafeCopy (MV_Bool MVector s Word8
v1) (MV_Bool MVector s Word8
v2) = MVector s Word8 -> MVector s Word8 -> ST s ()
forall s. MVector s Word8 -> MVector s Word8 -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeCopy MVector s Word8
v1 MVector s Word8
v2
  basicUnsafeMove :: forall s. MVector s Bool -> MVector s Bool -> ST s ()
basicUnsafeMove (MV_Bool MVector s Word8
v1) (MV_Bool MVector s Word8
v2) = MVector s Word8 -> MVector s Word8 -> ST s ()
forall s. MVector s Word8 -> MVector s Word8 -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeMove MVector s Word8
v1 MVector s Word8
v2
  basicUnsafeGrow :: forall s. MVector s Bool -> Int -> ST s (MVector s Bool)
basicUnsafeGrow (MV_Bool MVector s Word8
v) Int
n = MVector s Word8 -> MVector s Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector s Word8 -> MVector s Bool)
-> ST s (MVector s Word8) -> ST s (MVector s Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` MVector s Word8 -> Int -> ST s (MVector s Word8)
forall s. MVector s Word8 -> Int -> ST s (MVector s Word8)
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
M.basicUnsafeGrow MVector s Word8
v Int
n

instance G.Vector Vector Bool where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeFreeze :: forall s. Mutable Vector s Bool -> ST s (Vector Bool)
basicUnsafeFreeze (MV_Bool MVector s Word8
v) = Vector Word8 -> Vector Bool
V_Bool (Vector Word8 -> Vector Bool)
-> ST s (Vector Word8) -> ST s (Vector Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Mutable Vector s Word8 -> ST s (Vector Word8)
forall s. Mutable Vector s Word8 -> ST s (Vector Word8)
forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
G.basicUnsafeFreeze Mutable Vector s Word8
MVector s Word8
v
  basicUnsafeThaw :: forall s. Vector Bool -> ST s (Mutable Vector s Bool)
basicUnsafeThaw (V_Bool Vector Word8
v) = MVector s Word8 -> MVector s Bool
forall s. MVector s Word8 -> MVector s Bool
MV_Bool (MVector s Word8 -> MVector s Bool)
-> ST s (MVector s Word8) -> ST s (MVector s Bool)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector Word8 -> ST s (Mutable Vector s Word8)
forall s. Vector Word8 -> ST s (Mutable Vector s Word8)
forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw Vector Word8
v
  basicLength :: Vector Bool -> Int
basicLength (V_Bool Vector Word8
v) = Vector Word8 -> Int
forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength Vector Word8
v
  basicUnsafeSlice :: Int -> Int -> Vector Bool -> Vector Bool
basicUnsafeSlice Int
i Int
n (V_Bool Vector Word8
v) = Vector Word8 -> Vector Bool
V_Bool (Vector Word8 -> Vector Bool) -> Vector Word8 -> Vector Bool
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Vector Word8 -> Vector Word8
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice Int
i Int
n Vector Word8
v
  basicUnsafeIndexM :: Vector Bool -> Int -> Box Bool
basicUnsafeIndexM (V_Bool Vector Word8
v) Int
i = Word8 -> Bool
toBool (Word8 -> Bool) -> Box Word8 -> Box Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector Word8 -> Int -> Box Word8
forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector Word8
v Int
i
  basicUnsafeCopy :: forall s. Mutable Vector s Bool -> Vector Bool -> ST s ()
basicUnsafeCopy (MV_Bool MVector s Word8
mv) (V_Bool Vector Word8
v) = Mutable Vector s Word8 -> Vector Word8 -> ST s ()
forall s. Mutable Vector s Word8 -> Vector Word8 -> ST s ()
forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
G.basicUnsafeCopy Mutable Vector s Word8
MVector s Word8
mv Vector Word8
v
  elemseq :: forall b. Vector Bool -> Bool -> b -> b
elemseq Vector Bool
_ = Bool -> b -> b
forall a b. a -> b -> b
seq

-- -------
-- Complex
-- -------

newtype instance MVector s (Complex a) = MV_Complex (MVector s (a,a))
newtype instance Vector    (Complex a) = V_Complex  (Vector    (a,a))

instance (Unbox a) => Unbox (Complex a)

instance (Unbox a) => M.MVector MVector (Complex a) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeMove #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: forall s. MVector s (Complex a) -> Int
basicLength      = (MVector s (a, a) -> Int) -> MVector s (Complex a) -> Int
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> Int) -> MVector s (Complex a) -> Int)
-> (MVector s (a, a) -> Int) -> MVector s (Complex a) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength      @MVector @(a,a)
  basicUnsafeSlice :: forall s.
Int -> Int -> MVector s (Complex a) -> MVector s (Complex a)
basicUnsafeSlice = (Int -> Int -> MVector s (a, a) -> MVector s (a, a))
-> Int -> Int -> MVector s (Complex a) -> MVector s (Complex a)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> MVector s (a, a) -> MVector s (a, a))
 -> Int -> Int -> MVector s (Complex a) -> MVector s (Complex a))
-> (Int -> Int -> MVector s (a, a) -> MVector s (a, a))
-> Int
-> Int
-> MVector s (Complex a)
-> MVector s (Complex a)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice @MVector @(a,a)
  basicOverlaps :: forall s. MVector s (Complex a) -> MVector s (Complex a) -> Bool
basicOverlaps    = (MVector s (a, a) -> MVector s (a, a) -> Bool)
-> MVector s (Complex a) -> MVector s (Complex a) -> Bool
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> MVector s (a, a) -> Bool)
 -> MVector s (Complex a) -> MVector s (Complex a) -> Bool)
-> (MVector s (a, a) -> MVector s (a, a) -> Bool)
-> MVector s (Complex a)
-> MVector s (Complex a)
-> Bool
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps    @MVector @(a,a)
  basicUnsafeNew :: forall s. Int -> ST s (MVector s (Complex a))
basicUnsafeNew   = (Int -> ST s (MVector s (a, a)))
-> Int -> ST s (MVector s (Complex a))
forall a b. Coercible a b => a -> b
coerce ((Int -> ST s (MVector s (a, a)))
 -> Int -> ST s (MVector s (Complex a)))
-> (Int -> ST s (MVector s (a, a)))
-> Int
-> ST s (MVector s (Complex a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew   @MVector @(a,a)
  basicInitialize :: forall s. MVector s (Complex a) -> ST s ()
basicInitialize  = (MVector s (a, a) -> ST s ()) -> MVector s (Complex a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> ST s ()) -> MVector s (Complex a) -> ST s ())
-> (MVector s (a, a) -> ST s ())
-> MVector s (Complex a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize  @MVector @(a,a)
  basicUnsafeCopy :: forall s. MVector s (Complex a) -> MVector s (Complex a) -> ST s ()
basicUnsafeCopy  = (MVector s (a, a) -> MVector s (a, a) -> ST s ())
-> MVector s (Complex a) -> MVector s (Complex a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> MVector s (a, a) -> ST s ())
 -> MVector s (Complex a) -> MVector s (Complex a) -> ST s ())
-> (MVector s (a, a) -> MVector s (a, a) -> ST s ())
-> MVector s (Complex a)
-> MVector s (Complex a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeCopy  @MVector @(a,a)
  basicUnsafeMove :: forall s. MVector s (Complex a) -> MVector s (Complex a) -> ST s ()
basicUnsafeMove  = (MVector s (a, a) -> MVector s (a, a) -> ST s ())
-> MVector s (Complex a) -> MVector s (Complex a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> MVector s (a, a) -> ST s ())
 -> MVector s (Complex a) -> MVector s (Complex a) -> ST s ())
-> (MVector s (a, a) -> MVector s (a, a) -> ST s ())
-> MVector s (Complex a)
-> MVector s (Complex a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeMove  @MVector @(a,a)
  basicUnsafeGrow :: forall s.
MVector s (Complex a) -> Int -> ST s (MVector s (Complex a))
basicUnsafeGrow  = (MVector s (a, a) -> Int -> ST s (MVector s (a, a)))
-> MVector s (Complex a) -> Int -> ST s (MVector s (Complex a))
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> Int -> ST s (MVector s (a, a)))
 -> MVector s (Complex a) -> Int -> ST s (MVector s (Complex a)))
-> (MVector s (a, a) -> Int -> ST s (MVector s (a, a)))
-> MVector s (Complex a)
-> Int
-> ST s (MVector s (Complex a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
M.basicUnsafeGrow  @MVector @(a,a)
  basicClear :: forall s. MVector s (Complex a) -> ST s ()
basicClear       = (MVector s (a, a) -> ST s ()) -> MVector s (Complex a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> ST s ()) -> MVector s (Complex a) -> ST s ())
-> (MVector s (a, a) -> ST s ())
-> MVector s (Complex a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicClear       @MVector @(a,a)
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicSet #-}
  basicUnsafeReplicate :: forall s. Int -> Complex a -> ST s (MVector s (Complex a))
basicUnsafeReplicate Int
n (a
x :+ a
y) = MVector s (a, a) -> MVector s (Complex a)
forall s a. MVector s (a, a) -> MVector s (Complex a)
MV_Complex (MVector s (a, a) -> MVector s (Complex a))
-> ST s (MVector s (a, a)) -> ST s (MVector s (Complex a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> (a, a) -> ST s (MVector s (a, a))
forall s. Int -> (a, a) -> ST s (MVector s (a, a))
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
M.basicUnsafeReplicate Int
n (a
x,a
y)
  basicUnsafeRead :: forall s. MVector s (Complex a) -> Int -> ST s (Complex a)
basicUnsafeRead (MV_Complex MVector s (a, a)
v) Int
i = (a -> a -> Complex a) -> (a, a) -> Complex a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Complex a
forall a. a -> a -> Complex a
(:+) ((a, a) -> Complex a) -> ST s (a, a) -> ST s (Complex a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector s (a, a) -> Int -> ST s (a, a)
forall s. MVector s (a, a) -> Int -> ST s (a, a)
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s (a, a)
v Int
i
  basicUnsafeWrite :: forall s. MVector s (Complex a) -> Int -> Complex a -> ST s ()
basicUnsafeWrite (MV_Complex MVector s (a, a)
v) Int
i (a
x :+ a
y) = MVector s (a, a) -> Int -> (a, a) -> ST s ()
forall s. MVector s (a, a) -> Int -> (a, a) -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s (a, a)
v Int
i (a
x,a
y)
  basicSet :: forall s. MVector s (Complex a) -> Complex a -> ST s ()
basicSet (MV_Complex MVector s (a, a)
v) (a
x :+ a
y) = MVector s (a, a) -> (a, a) -> ST s ()
forall s. MVector s (a, a) -> (a, a) -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
M.basicSet MVector s (a, a)
v (a
x,a
y)

instance (Unbox a) => G.Vector Vector (Complex a) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeCopy #-}
  basicUnsafeFreeze :: forall s. Mutable Vector s (Complex a) -> ST s (Vector (Complex a))
basicUnsafeFreeze = (MVector s (a, a) -> ST s (Vector (a, a)))
-> Mutable Vector s (Complex a) -> ST s (Vector (Complex a))
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> ST s (Vector (a, a)))
 -> Mutable Vector s (Complex a) -> ST s (Vector (Complex a)))
-> (MVector s (a, a) -> ST s (Vector (a, a)))
-> Mutable Vector s (Complex a)
-> ST s (Vector (Complex a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
G.basicUnsafeFreeze @Vector @(a,a)
  basicUnsafeThaw :: forall s. Vector (Complex a) -> ST s (Mutable Vector s (Complex a))
basicUnsafeThaw   = (Vector (a, a) -> ST s (MVector s (a, a)))
-> Vector (Complex a) -> ST s (Mutable Vector s (Complex a))
forall a b. Coercible a b => a -> b
coerce ((Vector (a, a) -> ST s (MVector s (a, a)))
 -> Vector (Complex a) -> ST s (Mutable Vector s (Complex a)))
-> (Vector (a, a) -> ST s (MVector s (a, a)))
-> Vector (Complex a)
-> ST s (Mutable Vector s (Complex a))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw   @Vector @(a,a)
  basicLength :: Vector (Complex a) -> Int
basicLength       = (Vector (a, a) -> Int) -> Vector (Complex a) -> Int
forall a b. Coercible a b => a -> b
coerce ((Vector (a, a) -> Int) -> Vector (Complex a) -> Int)
-> (Vector (a, a) -> Int) -> Vector (Complex a) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength       @Vector @(a,a)
  basicUnsafeSlice :: Int -> Int -> Vector (Complex a) -> Vector (Complex a)
basicUnsafeSlice  = (Int -> Int -> Vector (a, a) -> Vector (a, a))
-> Int -> Int -> Vector (Complex a) -> Vector (Complex a)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> Vector (a, a) -> Vector (a, a))
 -> Int -> Int -> Vector (Complex a) -> Vector (Complex a))
-> (Int -> Int -> Vector (a, a) -> Vector (a, a))
-> Int
-> Int
-> Vector (Complex a)
-> Vector (Complex a)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice  @Vector @(a,a)
  basicUnsafeCopy :: forall s.
Mutable Vector s (Complex a) -> Vector (Complex a) -> ST s ()
basicUnsafeCopy   = (MVector s (a, a) -> Vector (a, a) -> ST s ())
-> Mutable Vector s (Complex a) -> Vector (Complex a) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, a) -> Vector (a, a) -> ST s ())
 -> Mutable Vector s (Complex a) -> Vector (Complex a) -> ST s ())
-> (MVector s (a, a) -> Vector (a, a) -> ST s ())
-> Mutable Vector s (Complex a)
-> Vector (Complex a)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
G.basicUnsafeCopy   @Vector @(a,a)
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeIndexM :: Vector (Complex a) -> Int -> Box (Complex a)
basicUnsafeIndexM (V_Complex Vector (a, a)
v) Int
i
                = (a -> a -> Complex a) -> (a, a) -> Complex a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Complex a
forall a. a -> a -> Complex a
(:+) ((a, a) -> Complex a) -> Box (a, a) -> Box (Complex a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector (a, a) -> Int -> Box (a, a)
forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector (a, a)
v Int
i
  elemseq :: forall b. Vector (Complex a) -> Complex a -> b -> b
elemseq Vector (Complex a)
_ (a
x :+ a
y) b
z = Vector a -> a -> b -> b
forall b. Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (Vector a
forall a. HasCallStack => a
undefined :: Vector a) a
x
                       (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Vector a -> a -> b -> b
forall b. Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (Vector a
forall a. HasCallStack => a
undefined :: Vector a) a
y b
z

-- -------
-- Identity
-- -------
#define newtypeMVector(inst_ctxt,inst_head,tyC,con) \
instance inst_ctxt => M.MVector MVector (inst_head) where { \
; {-# INLINE basicLength          #-}                                         \
; {-# INLINE basicUnsafeSlice     #-}                                         \
; {-# INLINE basicOverlaps        #-}                                         \
; {-# INLINE basicUnsafeNew       #-}                                         \
; {-# INLINE basicInitialize      #-}                                         \
; {-# INLINE basicUnsafeReplicate #-}                                         \
; {-# INLINE basicUnsafeRead      #-}                                         \
; {-# INLINE basicUnsafeWrite     #-}                                         \
; {-# INLINE basicClear           #-}                                         \
; {-# INLINE basicSet             #-}                                         \
; {-# INLINE basicUnsafeCopy      #-}                                         \
; {-# INLINE basicUnsafeGrow      #-}                                         \
; basicLength (con v)                = M.basicLength v                        \
; basicUnsafeSlice i n (con v)       = con $ M.basicUnsafeSlice i n v         \
; basicOverlaps (con v1) (con v2)    = M.basicOverlaps v1 v2                  \
; basicUnsafeNew n                   = con `liftM` M.basicUnsafeNew n         \
; basicInitialize (con v)            = M.basicInitialize v                    \
; basicUnsafeReplicate n (tyC x)     = con `liftM` M.basicUnsafeReplicate n x \
; basicUnsafeRead (con v) i          = tyC `liftM` M.basicUnsafeRead v i      \
; basicUnsafeWrite (con v) i (tyC x) = M.basicUnsafeWrite v i x               \
; basicClear (con v)                 = M.basicClear v                         \
; basicSet (con v) (tyC x)           = M.basicSet v x                         \
; basicUnsafeCopy (con v1) (con v2)  = M.basicUnsafeCopy v1 v2                \
; basicUnsafeMove (con v1) (con v2)  = M.basicUnsafeMove v1 v2                \
; basicUnsafeGrow (con v) n          = con `liftM` M.basicUnsafeGrow v n      \
}
#define newtypeVector(inst_ctxt,inst_head,tyC,con,mcon) \
instance inst_ctxt => G.Vector Vector (inst_head) where { \
; {-# INLINE basicUnsafeFreeze  #-}                                       \
; {-# INLINE basicUnsafeThaw    #-}                                       \
; {-# INLINE basicLength        #-}                                       \
; {-# INLINE basicUnsafeSlice   #-}                                       \
; {-# INLINE basicUnsafeIndexM  #-}                                       \
; {-# INLINE elemseq            #-}                                       \
; basicUnsafeFreeze (mcon v)        = con `liftM` G.basicUnsafeFreeze v   \
; basicUnsafeThaw (con v)           = mcon `liftM` G.basicUnsafeThaw v    \
; basicLength (con v)               = G.basicLength v                     \
; basicUnsafeSlice i n (con v)      = con $ G.basicUnsafeSlice i n v      \
; basicUnsafeIndexM (con v) i       = tyC `liftM` G.basicUnsafeIndexM v i \
; basicUnsafeCopy (mcon mv) (con v) = G.basicUnsafeCopy mv v              \
; elemseq _ (tyC a)                 = G.elemseq (undefined :: Vector x) a \
}
#define deriveNewtypeInstances(inst_ctxt,inst_head,rep,tyC,con,mcon) \
newtype instance MVector s (inst_head) = mcon (MVector s (rep)) ;\
newtype instance Vector    (inst_head) = con  (Vector (rep))    ;\
instance inst_ctxt => Unbox (inst_head)                         ;\
newtypeMVector(inst_ctxt, inst_head, tyC, mcon)                 ;\
newtypeVector(inst_ctxt,  inst_head, tyC, con, mcon)

deriveNewtypeInstances(Unbox a, Identity a, a, Identity, V_Identity, MV_Identity)
deriveNewtypeInstances(Unbox a, Down a,    a, Down,    V_Down,    MV_Down)
deriveNewtypeInstances(Unbox a, Dual a,    a, Dual,    V_Dual,    MV_Dual)
deriveNewtypeInstances(Unbox a, Sum a,     a, Sum,     V_Sum,     MV_Sum)
deriveNewtypeInstances(Unbox a, Product a, a, Product, V_Product, MV_Product)


-- --------------
-- Data.Semigroup
-- --------------

deriveNewtypeInstances(Unbox a, Min a,   a, Min,   V_Min,   MV_Min)
deriveNewtypeInstances(Unbox a, Max a,   a, Max,   V_Max,   MV_Max)
deriveNewtypeInstances(Unbox a, First a, a, First, V_First, MV_First)
deriveNewtypeInstances(Unbox a, Last a,  a, Last,  V_Last,  MV_Last)
deriveNewtypeInstances(Unbox a, WrappedMonoid a, a, WrapMonoid, V_WrappedMonoid, MV_WrappedMonoid)

-- ------------------
-- Data.Semigroup.Arg
-- ------------------

newtype instance MVector s (Arg a b) = MV_Arg (MVector s (a,b))
newtype instance Vector    (Arg a b) = V_Arg  (Vector    (a,b))

instance (Unbox a, Unbox b) => Unbox (Arg a b)

instance (Unbox a, Unbox b) => M.MVector MVector (Arg a b) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicInitialize #-}
  {-# INLINE basicClear #-}
  {-# INLINE basicUnsafeCopy #-}
  {-# INLINE basicUnsafeMove #-}
  {-# INLINE basicUnsafeGrow #-}
  basicLength :: forall s. MVector s (Arg a b) -> Int
basicLength      = (MVector s (a, b) -> Int) -> MVector s (Arg a b) -> Int
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> Int) -> MVector s (Arg a b) -> Int)
-> (MVector s (a, b) -> Int) -> MVector s (Arg a b) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
M.basicLength      @MVector @(a,b)
  basicUnsafeSlice :: forall s. Int -> Int -> MVector s (Arg a b) -> MVector s (Arg a b)
basicUnsafeSlice = (Int -> Int -> MVector s (a, b) -> MVector s (a, b))
-> Int -> Int -> MVector s (Arg a b) -> MVector s (Arg a b)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> MVector s (a, b) -> MVector s (a, b))
 -> Int -> Int -> MVector s (Arg a b) -> MVector s (Arg a b))
-> (Int -> Int -> MVector s (a, b) -> MVector s (a, b))
-> Int
-> Int
-> MVector s (Arg a b)
-> MVector s (Arg a b)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice @MVector @(a,b)
  basicOverlaps :: forall s. MVector s (Arg a b) -> MVector s (Arg a b) -> Bool
basicOverlaps    = (MVector s (a, b) -> MVector s (a, b) -> Bool)
-> MVector s (Arg a b) -> MVector s (Arg a b) -> Bool
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> MVector s (a, b) -> Bool)
 -> MVector s (Arg a b) -> MVector s (Arg a b) -> Bool)
-> (MVector s (a, b) -> MVector s (a, b) -> Bool)
-> MVector s (Arg a b)
-> MVector s (Arg a b)
-> Bool
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps    @MVector @(a,b)
  basicUnsafeNew :: forall s. Int -> ST s (MVector s (Arg a b))
basicUnsafeNew   = (Int -> ST s (MVector s (a, b)))
-> Int -> ST s (MVector s (Arg a b))
forall a b. Coercible a b => a -> b
coerce ((Int -> ST s (MVector s (a, b)))
 -> Int -> ST s (MVector s (Arg a b)))
-> (Int -> ST s (MVector s (a, b)))
-> Int
-> ST s (MVector s (Arg a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew   @MVector @(a,b)
  basicInitialize :: forall s. MVector s (Arg a b) -> ST s ()
basicInitialize  = (MVector s (a, b) -> ST s ()) -> MVector s (Arg a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> ST s ()) -> MVector s (Arg a b) -> ST s ())
-> (MVector s (a, b) -> ST s ()) -> MVector s (Arg a b) -> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize  @MVector @(a,b)
  basicUnsafeCopy :: forall s. MVector s (Arg a b) -> MVector s (Arg a b) -> ST s ()
basicUnsafeCopy  = (MVector s (a, b) -> MVector s (a, b) -> ST s ())
-> MVector s (Arg a b) -> MVector s (Arg a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> MVector s (a, b) -> ST s ())
 -> MVector s (Arg a b) -> MVector s (Arg a b) -> ST s ())
-> (MVector s (a, b) -> MVector s (a, b) -> ST s ())
-> MVector s (Arg a b)
-> MVector s (Arg a b)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeCopy  @MVector @(a,b)
  basicUnsafeMove :: forall s. MVector s (Arg a b) -> MVector s (Arg a b) -> ST s ()
basicUnsafeMove  = (MVector s (a, b) -> MVector s (a, b) -> ST s ())
-> MVector s (Arg a b) -> MVector s (Arg a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> MVector s (a, b) -> ST s ())
 -> MVector s (Arg a b) -> MVector s (Arg a b) -> ST s ())
-> (MVector s (a, b) -> MVector s (a, b) -> ST s ())
-> MVector s (Arg a b)
-> MVector s (Arg a b)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
M.basicUnsafeMove  @MVector @(a,b)
  basicUnsafeGrow :: forall s. MVector s (Arg a b) -> Int -> ST s (MVector s (Arg a b))
basicUnsafeGrow  = (MVector s (a, b) -> Int -> ST s (MVector s (a, b)))
-> MVector s (Arg a b) -> Int -> ST s (MVector s (Arg a b))
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> Int -> ST s (MVector s (a, b)))
 -> MVector s (Arg a b) -> Int -> ST s (MVector s (Arg a b)))
-> (MVector s (a, b) -> Int -> ST s (MVector s (a, b)))
-> MVector s (Arg a b)
-> Int
-> ST s (MVector s (Arg a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
M.basicUnsafeGrow  @MVector @(a,b)
  basicClear :: forall s. MVector s (Arg a b) -> ST s ()
basicClear       = (MVector s (a, b) -> ST s ()) -> MVector s (Arg a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> ST s ()) -> MVector s (Arg a b) -> ST s ())
-> (MVector s (a, b) -> ST s ()) -> MVector s (Arg a b) -> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicClear       @MVector @(a,b)
  {-# INLINE basicUnsafeReplicate #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  {-# INLINE basicSet #-}
  basicUnsafeReplicate :: forall s. Int -> Arg a b -> ST s (MVector s (Arg a b))
basicUnsafeReplicate Int
n (Arg a
x b
y)        = MVector s (a, b) -> MVector s (Arg a b)
forall s a b. MVector s (a, b) -> MVector s (Arg a b)
MV_Arg (MVector s (a, b) -> MVector s (Arg a b))
-> ST s (MVector s (a, b)) -> ST s (MVector s (Arg a b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> (a, b) -> ST s (MVector s (a, b))
forall s. Int -> (a, b) -> ST s (MVector s (a, b))
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
M.basicUnsafeReplicate Int
n (a
x,b
y)
  basicUnsafeRead :: forall s. MVector s (Arg a b) -> Int -> ST s (Arg a b)
basicUnsafeRead (MV_Arg MVector s (a, b)
v) Int
i            = (a -> b -> Arg a b) -> (a, b) -> Arg a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Arg a b
forall a b. a -> b -> Arg a b
Arg ((a, b) -> Arg a b) -> ST s (a, b) -> ST s (Arg a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector s (a, b) -> Int -> ST s (a, b)
forall s. MVector s (a, b) -> Int -> ST s (a, b)
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s (a, b)
v Int
i
  basicUnsafeWrite :: forall s. MVector s (Arg a b) -> Int -> Arg a b -> ST s ()
basicUnsafeWrite (MV_Arg MVector s (a, b)
v) Int
i (Arg a
x b
y) = MVector s (a, b) -> Int -> (a, b) -> ST s ()
forall s. MVector s (a, b) -> Int -> (a, b) -> ST s ()
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s (a, b)
v Int
i (a
x,b
y)
  basicSet :: forall s. MVector s (Arg a b) -> Arg a b -> ST s ()
basicSet (MV_Arg MVector s (a, b)
v) (Arg a
x b
y)           = MVector s (a, b) -> (a, b) -> ST s ()
forall s. MVector s (a, b) -> (a, b) -> ST s ()
forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
M.basicSet MVector s (a, b)
v (a
x,b
y)


instance (Unbox a, Unbox b) => G.Vector Vector (Arg a b) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw #-}
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicUnsafeCopy #-}
  basicUnsafeFreeze :: forall s. Mutable Vector s (Arg a b) -> ST s (Vector (Arg a b))
basicUnsafeFreeze = (MVector s (a, b) -> ST s (Vector (a, b)))
-> Mutable Vector s (Arg a b) -> ST s (Vector (Arg a b))
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> ST s (Vector (a, b)))
 -> Mutable Vector s (Arg a b) -> ST s (Vector (Arg a b)))
-> (MVector s (a, b) -> ST s (Vector (a, b)))
-> Mutable Vector s (Arg a b)
-> ST s (Vector (Arg a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
G.basicUnsafeFreeze @Vector @(a,b)
  basicUnsafeThaw :: forall s. Vector (Arg a b) -> ST s (Mutable Vector s (Arg a b))
basicUnsafeThaw   = (Vector (a, b) -> ST s (MVector s (a, b)))
-> Vector (Arg a b) -> ST s (Mutable Vector s (Arg a b))
forall a b. Coercible a b => a -> b
coerce ((Vector (a, b) -> ST s (MVector s (a, b)))
 -> Vector (Arg a b) -> ST s (Mutable Vector s (Arg a b)))
-> (Vector (a, b) -> ST s (MVector s (a, b)))
-> Vector (Arg a b)
-> ST s (Mutable Vector s (Arg a b))
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw   @Vector @(a,b)
  basicLength :: Vector (Arg a b) -> Int
basicLength       = (Vector (a, b) -> Int) -> Vector (Arg a b) -> Int
forall a b. Coercible a b => a -> b
coerce ((Vector (a, b) -> Int) -> Vector (Arg a b) -> Int)
-> (Vector (a, b) -> Int) -> Vector (Arg a b) -> Int
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => v a -> Int
G.basicLength       @Vector @(a,b)
  basicUnsafeSlice :: Int -> Int -> Vector (Arg a b) -> Vector (Arg a b)
basicUnsafeSlice  = (Int -> Int -> Vector (a, b) -> Vector (a, b))
-> Int -> Int -> Vector (Arg a b) -> Vector (Arg a b)
forall a b. Coercible a b => a -> b
coerce ((Int -> Int -> Vector (a, b) -> Vector (a, b))
 -> Int -> Int -> Vector (Arg a b) -> Vector (Arg a b))
-> (Int -> Int -> Vector (a, b) -> Vector (a, b))
-> Int
-> Int
-> Vector (Arg a b)
-> Vector (Arg a b)
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice  @Vector @(a,b)
  basicUnsafeCopy :: forall s. Mutable Vector s (Arg a b) -> Vector (Arg a b) -> ST s ()
basicUnsafeCopy   = (MVector s (a, b) -> Vector (a, b) -> ST s ())
-> Mutable Vector s (Arg a b) -> Vector (Arg a b) -> ST s ()
forall a b. Coercible a b => a -> b
coerce ((MVector s (a, b) -> Vector (a, b) -> ST s ())
 -> Mutable Vector s (Arg a b) -> Vector (Arg a b) -> ST s ())
-> (MVector s (a, b) -> Vector (a, b) -> ST s ())
-> Mutable Vector s (Arg a b)
-> Vector (Arg a b)
-> ST s ()
forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
G.basicUnsafeCopy   @Vector @(a,b)
  {-# INLINE basicUnsafeIndexM #-}
  {-# INLINE elemseq #-}
  basicUnsafeIndexM :: Vector (Arg a b) -> Int -> Box (Arg a b)
basicUnsafeIndexM (V_Arg Vector (a, b)
v) Int
i  = (a -> b -> Arg a b) -> (a, b) -> Arg a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Arg a b
forall a b. a -> b -> Arg a b
Arg ((a, b) -> Arg a b) -> Box (a, b) -> Box (Arg a b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Vector (a, b) -> Int -> Box (a, b)
forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector (a, b)
v Int
i
  elemseq :: forall b. Vector (Arg a b) -> Arg a b -> b -> b
elemseq Vector (Arg a b)
_ (Arg a
x b
y) b
z          = Vector a -> a -> b -> b
forall b. Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (Vector a
forall a. HasCallStack => a
undefined :: Vector a) a
x
                                 (b -> b) -> b -> b
forall a b. (a -> b) -> a -> b
$ Vector b -> b -> b -> b
forall b. Vector b -> b -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
G.elemseq (Vector b
forall a. HasCallStack => a
undefined :: Vector b) b
y b
z

deriveNewtypeInstances((), Any, Bool, Any, V_Any, MV_Any)
deriveNewtypeInstances((), All, Bool, All, V_All, MV_All)

-- -------
-- Const
-- -------

deriveNewtypeInstances(Unbox a, Const a b, a, Const, V_Const, MV_Const)

-- ---
-- Alt
-- ---

deriveNewtypeInstances(Unbox (f a), Alt f a, f a, Alt, V_Alt, MV_Alt)

-- -------
-- Compose
-- -------

deriveNewtypeInstances(Unbox (f (g a)), Compose f g a, f (g a), Compose, V_Compose, MV_Compose)

-- ------
-- Tuples
-- ------

#define DEFINE_INSTANCES
#include "unbox-tuple-instances"