{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module      : Data.Massiv.Core.Index.Tuple
-- Copyright   : (c) Alexey Kuleshevich 2018-2022
-- License     : BSD3
-- Maintainer  : Alexey Kuleshevich <alexey@kuleshevi.ch>
-- Stability   : experimental
-- Portability : non-portable
module Data.Massiv.Core.Index.Tuple (
  -- * Tuple based indices

  -- ** 1-dimensional
  Ix1T,

  -- ** 2-dimensional
  Ix2T,
  toIx2,
  fromIx2,

  -- ** 3-dimensional
  Ix3T,
  toIx3,
  fromIx3,

  -- ** 4-dimensional
  Ix4T,
  toIx4,
  fromIx4,

  -- ** 5-dimensional
  Ix5T,
  toIx5,
  fromIx5,
) where

import Control.Monad.Catch (MonadThrow (..))
import Data.Massiv.Core.Index.Internal (
  Index (..),
  IndexException (..),
  Lower,
  Sz (..),
 )
import Data.Massiv.Core.Index.Ix

-- | Another 1-dimensional index type synonym for `Int`, same as `Ix1` and is here just for
-- consistency.
type Ix1T = Int

-- | 2-dimensional index as tuple of `Int`s.
type Ix2T = (Int, Int)

-- | 3-dimensional index as 3-tuple of `Int`s.
type Ix3T = (Int, Int, Int)

-- | 4-dimensional index as 4-tuple of `Int`s.
type Ix4T = (Int, Int, Int, Int)

-- | 5-dimensional index as 5-tuple of `Int`s.
type Ix5T = (Int, Int, Int, Int, Int)

type instance Lower Ix2T = Ix1T
type instance Lower Ix3T = Ix2T
type instance Lower Ix4T = Ix3T
type instance Lower Ix5T = Ix4T

-- | Convert an `Int` tuple to `Ix2`
--
-- ==== __Example__
--
-- >>> toIx2 (2, 3)
-- 2 :. 3
--
-- @since 0.1.0
toIx2 :: Ix2T -> Ix2
toIx2 :: Ix2T -> Ix2
toIx2 (Ix1T
i, Ix1T
j) = Ix1T
i Ix1T -> Ix1T -> Ix2
:. Ix1T
j
{-# INLINE toIx2 #-}

-- | Convert an `Ix2` to `Int` tuple
--
-- ==== __Example__
--
-- >>> fromIx2 (2 :. 3)
-- (2,3)
--
-- @since 0.1.0
fromIx2 :: Ix2 -> Ix2T
fromIx2 :: Ix2 -> Ix2T
fromIx2 (Ix1T
i :. Ix1T
j) = (Ix1T
i, Ix1T
j)
{-# INLINE fromIx2 #-}

-- | Convert a `Int` 3-tuple to `Ix3`
--
-- ==== __Example__
--
-- >>> toIx3 (1, 2, 3)
-- 1 :> 2 :. 3
--
-- @since 0.1.0
toIx3 :: Ix3T -> Ix3
toIx3 :: Ix3T -> Ix3
toIx3 (Ix1T
i, Ix1T
j, Ix1T
k) = Ix1T
i forall (n :: Nat). Ix1T -> Ix (n - 1) -> IxN n
:> Ix1T
j Ix1T -> Ix1T -> Ix2
:. Ix1T
k
{-# INLINE toIx3 #-}

-- | Convert an `Ix3` to `Int` 3-tuple
--
-- ==== __Example__
--
-- >>> fromIx3 (1 :>  2 :. 3)
-- (1,2,3)
--
-- @since 0.1.0
fromIx3 :: Ix3 -> Ix3T
fromIx3 :: Ix3 -> Ix3T
fromIx3 (Ix1T
i :> Ix1T
j :. Ix1T
k) = (Ix1T
i, Ix1T
j, Ix1T
k)
{-# INLINE fromIx3 #-}

-- | Convert a `Int` 4-tuple to `Ix4`
--
-- ==== __Example__
--
-- >>> toIx4 (1, 2, 3, 4)
-- 1 :> 2 :> 3 :. 4
--
-- @since 0.1.0
toIx4 :: Ix4T -> Ix4
toIx4 :: Ix4T -> Ix4
toIx4 (Ix1T
i, Ix1T
j, Ix1T
k, Ix1T
l) = Ix1T
i forall (n :: Nat). Ix1T -> Ix (n - 1) -> IxN n
:> Ix1T
j forall (n :: Nat). Ix1T -> Ix (n - 1) -> IxN n
:> Ix1T
k Ix1T -> Ix1T -> Ix2
:. Ix1T
l
{-# INLINE toIx4 #-}

-- | Convert an `Ix4` to `Int` 4-tuple
--
-- ==== __Example__
--
-- >>> fromIx4 (1 :> 2 :> 3 :. 4)
-- (1,2,3,4)
--
-- @since 0.1.0
fromIx4 :: Ix4 -> Ix4T
fromIx4 :: Ix4 -> Ix4T
fromIx4 (Ix1T
i :> Ix1T
j :> Ix1T
k :. Ix1T
l) = (Ix1T
i, Ix1T
j, Ix1T
k, Ix1T
l)
{-# INLINE fromIx4 #-}

-- | Convert a `Int` 5-tuple to `Ix5`
--
-- ==== __Example__
--
-- >>> toIx5 (1, 2, 3, 4, 5)
-- 1 :> 2 :> 3 :> 4 :. 5
--
-- @since 0.1.0
toIx5 :: Ix5T -> Ix5
toIx5 :: Ix5T -> Ix5
toIx5 (Ix1T
i, Ix1T
j, Ix1T
k, Ix1T
l, Ix1T
m) = Ix1T
i forall (n :: Nat). Ix1T -> Ix (n - 1) -> IxN n
:> Ix1T
j forall (n :: Nat). Ix1T -> Ix (n - 1) -> IxN n
:> Ix1T
k forall (n :: Nat). Ix1T -> Ix (n - 1) -> IxN n
:> Ix1T
l Ix1T -> Ix1T -> Ix2
:. Ix1T
m
{-# INLINE toIx5 #-}

-- | Convert an `Ix5` to `Int` 5-tuple
--
-- ==== __Example__
--
-- >>> fromIx5 (1 :> 2 :> 3 :> 4 :. 5)
-- (1,2,3,4,5)
--
-- @since 0.1.0
fromIx5 :: Ix5 -> Ix5T
fromIx5 :: Ix5 -> Ix5T
fromIx5 (Ix1T
i :> Ix1T
j :> Ix1T
k :> Ix1T
l :. Ix1T
m) = (Ix1T
i, Ix1T
j, Ix1T
k, Ix1T
l, Ix1T
m)
{-# INLINE fromIx5 #-}

-- |
-- @since 0.1.0
instance Index Ix2T where
  type Dimensions Ix2T = 2
  dimensions :: forall (proxy :: * -> *). proxy Ix2T -> Dim
dimensions proxy Ix2T
_ = Dim
2
  {-# INLINE [1] dimensions #-}
  totalElem :: Sz Ix2T -> Ix1T
totalElem (SafeSz (Ix1T
k2, Ix1T
k1)) = Ix1T
k2 forall a. Num a => a -> a -> a
* Ix1T
k1
  {-# INLINE [1] totalElem #-}
  toLinearIndex :: Sz Ix2T -> Ix2T -> Ix1T
toLinearIndex (SafeSz (Ix1T
_, Ix1T
k1)) (Ix1T
i2, Ix1T
i1) = Ix1T
k1 forall a. Num a => a -> a -> a
* Ix1T
i2 forall a. Num a => a -> a -> a
+ Ix1T
i1
  {-# INLINE [1] toLinearIndex #-}
  fromLinearIndex :: Sz Ix2T -> Ix1T -> Ix2T
fromLinearIndex (SafeSz (Ix1T
_, Ix1T
k1)) !Ix1T
i = Ix1T
i forall a. Integral a => a -> a -> (a, a)
`quotRem` Ix1T
k1
  {-# INLINE [1] fromLinearIndex #-}
  consDim :: Ix1T -> Lower Ix2T -> Ix2T
consDim = (,)
  {-# INLINE [1] consDim #-}
  unconsDim :: Ix2T -> (Ix1T, Lower Ix2T)
unconsDim = forall a. a -> a
id
  {-# INLINE [1] unconsDim #-}
  snocDim :: Lower Ix2T -> Ix1T -> Ix2T
snocDim = (,)
  {-# INLINE [1] snocDim #-}
  unsnocDim :: Ix2T -> (Lower Ix2T, Ix1T)
unsnocDim = forall a. a -> a
id
  {-# INLINE [1] unsnocDim #-}
  getDimM :: forall (m :: * -> *). MonadThrow m => Ix2T -> Dim -> m Ix1T
getDimM (Ix1T
i2, Ix1T
_) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i2
  getDimM (Ix1T
_, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i1
  getDimM Ix2T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix2T
ix Dim
d
  {-# INLINE [1] getDimM #-}
  setDimM :: forall (m :: * -> *). MonadThrow m => Ix2T -> Dim -> Ix1T -> m Ix2T
setDimM (Ix1T
_, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i2, Ix1T
_) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, Ix1T
i1)
  setDimM Ix2T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix2T
ix Dim
d
  {-# INLINE [1] setDimM #-}
  modifyDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix2T -> Dim -> (Ix1T -> Ix1T) -> m (Ix1T, Ix2T)
modifyDimM (Ix1T
i2, Ix1T
i1) Dim
2 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T -> Ix1T
f Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i2, Ix1T
i1) Dim
1 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i2, Ix1T -> Ix1T
f Ix1T
i1))
  modifyDimM Ix2T
ix Dim
d Ix1T -> Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix2T
ix Dim
d
  {-# INLINE [1] modifyDimM #-}
  pullOutDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix2T -> Dim -> m (Ix1T, Lower Ix2T)
pullOutDimM (Ix1T
i2, Ix1T
i1) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, Ix1T
i1)
  pullOutDimM (Ix1T
i2, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, Ix1T
i2)
  pullOutDimM Ix2T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix2T
ix Dim
d
  {-# INLINE [1] pullOutDimM #-}
  insertDimM :: forall (m :: * -> *).
MonadThrow m =>
Lower Ix2T -> Dim -> Ix1T -> m Ix2T
insertDimM Lower Ix2T
i1 Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, Lower Ix2T
i1)
  insertDimM Lower Ix2T
i2 Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Lower Ix2T
i2, Ix1T
i1)
  insertDimM Lower Ix2T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Lower Ix2T
ix Dim
d
  {-# INLINE [1] insertDimM #-}
  pureIndex :: Ix1T -> Ix2T
pureIndex Ix1T
i = (Ix1T
i, Ix1T
i)
  {-# INLINE [1] pureIndex #-}
  liftIndex2 :: (Ix1T -> Ix1T -> Ix1T) -> Ix2T -> Ix2T -> Ix2T
liftIndex2 Ix1T -> Ix1T -> Ix1T
f (Ix1T
i2, Ix1T
i1) (Ix1T
i2', Ix1T
i1') = (Ix1T -> Ix1T -> Ix1T
f Ix1T
i2 Ix1T
i2', Ix1T -> Ix1T -> Ix1T
f Ix1T
i1 Ix1T
i1')
  {-# INLINE [1] liftIndex2 #-}

-- |
-- @since 0.1.0
instance Index Ix3T where
  type Dimensions Ix3T = 3
  dimensions :: forall (proxy :: * -> *). proxy Ix3T -> Dim
dimensions proxy Ix3T
_ = Dim
3
  {-# INLINE [1] dimensions #-}
  totalElem :: Sz Ix3T -> Ix1T
totalElem (SafeSz (Ix1T
k3, Ix1T
k2, Ix1T
k1)) = Ix1T
k3 forall a. Num a => a -> a -> a
* Ix1T
k2 forall a. Num a => a -> a -> a
* Ix1T
k1
  {-# INLINE [1] totalElem #-}
  consDim :: Ix1T -> Lower Ix3T -> Ix3T
consDim Ix1T
i3 (Ix1T
i2, Ix1T
i1) = (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  {-# INLINE [1] consDim #-}
  unconsDim :: Ix3T -> (Ix1T, Lower Ix3T)
unconsDim (Ix1T
i3, Ix1T
i2, Ix1T
i1) = (Ix1T
i3, (Ix1T
i2, Ix1T
i1))
  {-# INLINE [1] unconsDim #-}
  snocDim :: Lower Ix3T -> Ix1T -> Ix3T
snocDim (Ix1T
i3, Ix1T
i2) Ix1T
i1 = (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  {-# INLINE [1] snocDim #-}
  unsnocDim :: Ix3T -> (Lower Ix3T, Ix1T)
unsnocDim (Ix1T
i3, Ix1T
i2, Ix1T
i1) = ((Ix1T
i3, Ix1T
i2), Ix1T
i1)
  {-# INLINE [1] unsnocDim #-}
  getDimM :: forall (m :: * -> *). MonadThrow m => Ix3T -> Dim -> m Ix1T
getDimM (Ix1T
i3, Ix1T
_, Ix1T
_) Dim
3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i3
  getDimM (Ix1T
_, Ix1T
i2, Ix1T
_) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i2
  getDimM (Ix1T
_, Ix1T
_, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i1
  getDimM Ix3T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix3T
ix Dim
d
  {-# INLINE [1] getDimM #-}
  setDimM :: forall (m :: * -> *). MonadThrow m => Ix3T -> Dim -> Ix1T -> m Ix3T
setDimM (Ix1T
_, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T
i3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i3, Ix1T
_, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i3, Ix1T
i2, Ix1T
_) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM Ix3T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix3T
ix Dim
d
  {-# INLINE [1] setDimM #-}
  modifyDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix3T -> Dim -> (Ix1T -> Ix1T) -> m (Ix1T, Ix3T)
modifyDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, (Ix1T -> Ix1T
f Ix1T
i3, Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
2 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T
i3, Ix1T -> Ix1T
f Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
1 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i3, Ix1T
i2, Ix1T -> Ix1T
f Ix1T
i1))
  modifyDimM Ix3T
ix Dim
d Ix1T -> Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix3T
ix Dim
d
  {-# INLINE [1] modifyDimM #-}
  pullOutDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix3T -> Dim -> m (Ix1T, Lower Ix3T)
pullOutDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, (Ix1T
i2, Ix1T
i1))
  pullOutDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T
i3, Ix1T
i1))
  pullOutDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i3, Ix1T
i2))
  pullOutDimM Ix3T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix3T
ix Dim
d
  {-# INLINE [1] pullOutDimM #-}
  insertDimM :: forall (m :: * -> *).
MonadThrow m =>
Lower Ix3T -> Dim -> Ix1T -> m Ix3T
insertDimM (Ix1T
i2, Ix1T
i1) Dim
3 Ix1T
i3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i3, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i3, Ix1T
i2) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM Lower Ix3T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Lower Ix3T
ix Dim
d
  pureIndex :: Ix1T -> Ix3T
pureIndex Ix1T
i = (Ix1T
i, Ix1T
i, Ix1T
i)
  {-# INLINE [1] pureIndex #-}
  liftIndex2 :: (Ix1T -> Ix1T -> Ix1T) -> Ix3T -> Ix3T -> Ix3T
liftIndex2 Ix1T -> Ix1T -> Ix1T
f (Ix1T
i3, Ix1T
i2, Ix1T
i1) (Ix1T
i3', Ix1T
i2', Ix1T
i1') = (Ix1T -> Ix1T -> Ix1T
f Ix1T
i3 Ix1T
i3', Ix1T -> Ix1T -> Ix1T
f Ix1T
i2 Ix1T
i2', Ix1T -> Ix1T -> Ix1T
f Ix1T
i1 Ix1T
i1')
  {-# INLINE [1] liftIndex2 #-}

instance Index Ix4T where
  type Dimensions Ix4T = 4
  dimensions :: forall (proxy :: * -> *). proxy Ix4T -> Dim
dimensions proxy Ix4T
_ = Dim
4
  {-# INLINE [1] dimensions #-}
  totalElem :: Sz Ix4T -> Ix1T
totalElem (SafeSz (Ix1T
k4, Ix1T
k3, Ix1T
k2, Ix1T
k1)) = Ix1T
k4 forall a. Num a => a -> a -> a
* Ix1T
k3 forall a. Num a => a -> a -> a
* Ix1T
k2 forall a. Num a => a -> a -> a
* Ix1T
k1
  {-# INLINE [1] totalElem #-}
  consDim :: Ix1T -> Lower Ix4T -> Ix4T
consDim Ix1T
i4 (Ix1T
i3, Ix1T
i2, Ix1T
i1) = (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  {-# INLINE [1] consDim #-}
  unconsDim :: Ix4T -> (Ix1T, Lower Ix4T)
unconsDim (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) = (Ix1T
i4, (Ix1T
i3, Ix1T
i2, Ix1T
i1))
  {-# INLINE [1] unconsDim #-}
  snocDim :: Lower Ix4T -> Ix1T -> Ix4T
snocDim (Ix1T
i4, Ix1T
i3, Ix1T
i2) Ix1T
i1 = (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  {-# INLINE [1] snocDim #-}
  unsnocDim :: Ix4T -> (Lower Ix4T, Ix1T)
unsnocDim (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) = ((Ix1T
i4, Ix1T
i3, Ix1T
i2), Ix1T
i1)
  {-# INLINE [1] unsnocDim #-}
  getDimM :: forall (m :: * -> *). MonadThrow m => Ix4T -> Dim -> m Ix1T
getDimM (Ix1T
i4, Ix1T
_, Ix1T
_, Ix1T
_) Dim
4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i4
  getDimM (Ix1T
_, Ix1T
i3, Ix1T
_, Ix1T
_) Dim
3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i3
  getDimM (Ix1T
_, Ix1T
_, Ix1T
i2, Ix1T
_) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i2
  getDimM (Ix1T
_, Ix1T
_, Ix1T
_, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i1
  getDimM Ix4T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix4T
ix Dim
d
  {-# INLINE [1] getDimM #-}
  setDimM :: forall (m :: * -> *). MonadThrow m => Ix4T -> Dim -> Ix1T -> m Ix4T
setDimM (Ix1T
_, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 Ix1T
i4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i4, Ix1T
_, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T
i3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i4, Ix1T
i3, Ix1T
_, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
_) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM Ix4T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix4T
ix Dim
d
  {-# INLINE [1] setDimM #-}
  modifyDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix4T -> Dim -> (Ix1T -> Ix1T) -> m (Ix1T, Ix4T)
modifyDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, (Ix1T -> Ix1T
f Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, (Ix1T
i4, Ix1T -> Ix1T
f Ix1T
i3, Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
2 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T
i4, Ix1T
i3, Ix1T -> Ix1T
f Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
1 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T -> Ix1T
f Ix1T
i1))
  modifyDimM Ix4T
ix Dim
d Ix1T -> Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix4T
ix Dim
d
  {-# INLINE [1] modifyDimM #-}
  pullOutDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix4T -> Dim -> m (Ix1T, Lower Ix4T)
pullOutDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, (Ix1T
i3, Ix1T
i2, Ix1T
i1))
  pullOutDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, (Ix1T
i4, Ix1T
i2, Ix1T
i1))
  pullOutDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T
i4, Ix1T
i3, Ix1T
i1))
  pullOutDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i4, Ix1T
i3, Ix1T
i2))
  pullOutDimM Ix4T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix4T
ix Dim
d
  {-# INLINE [1] pullOutDimM #-}
  insertDimM :: forall (m :: * -> *).
MonadThrow m =>
Lower Ix4T -> Dim -> Ix1T -> m Ix4T
insertDimM (Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 Ix1T
i4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i4, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T
i3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i4, Ix1T
i3, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM Lower Ix4T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Lower Ix4T
ix Dim
d
  {-# INLINE [1] insertDimM #-}
  pureIndex :: Ix1T -> Ix4T
pureIndex Ix1T
i = (Ix1T
i, Ix1T
i, Ix1T
i, Ix1T
i)
  {-# INLINE [1] pureIndex #-}
  liftIndex2 :: (Ix1T -> Ix1T -> Ix1T) -> Ix4T -> Ix4T -> Ix4T
liftIndex2 Ix1T -> Ix1T -> Ix1T
f (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) (Ix1T
i4', Ix1T
i3', Ix1T
i2', Ix1T
i1') = (Ix1T -> Ix1T -> Ix1T
f Ix1T
i4 Ix1T
i4', Ix1T -> Ix1T -> Ix1T
f Ix1T
i3 Ix1T
i3', Ix1T -> Ix1T -> Ix1T
f Ix1T
i2 Ix1T
i2', Ix1T -> Ix1T -> Ix1T
f Ix1T
i1 Ix1T
i1')
  {-# INLINE [1] liftIndex2 #-}

instance Index Ix5T where
  type Dimensions Ix5T = 5
  dimensions :: forall (proxy :: * -> *). proxy Ix5T -> Dim
dimensions proxy Ix5T
_ = Dim
5
  {-# INLINE [1] dimensions #-}
  totalElem :: Sz Ix5T -> Ix1T
totalElem (SafeSz (Ix1T
n5, Ix1T
n4, Ix1T
n3, Ix1T
n2, Ix1T
n1)) = Ix1T
n5 forall a. Num a => a -> a -> a
* Ix1T
n4 forall a. Num a => a -> a -> a
* Ix1T
n3 forall a. Num a => a -> a -> a
* Ix1T
n2 forall a. Num a => a -> a -> a
* Ix1T
n1
  {-# INLINE [1] totalElem #-}
  consDim :: Ix1T -> Lower Ix5T -> Ix5T
consDim Ix1T
i5 (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) = (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  {-# INLINE [1] consDim #-}
  unconsDim :: Ix5T -> (Ix1T, Lower Ix5T)
unconsDim (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) = (Ix1T
i5, (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1))
  {-# INLINE [1] unconsDim #-}
  snocDim :: Lower Ix5T -> Ix1T -> Ix5T
snocDim (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2) Ix1T
i1 = (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  {-# INLINE [1] snocDim #-}
  unsnocDim :: Ix5T -> (Lower Ix5T, Ix1T)
unsnocDim (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) = ((Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2), Ix1T
i1)
  {-# INLINE [1] unsnocDim #-}
  getDimM :: forall (m :: * -> *). MonadThrow m => Ix5T -> Dim -> m Ix1T
getDimM (Ix1T
i5, Ix1T
_, Ix1T
_, Ix1T
_, Ix1T
_) Dim
5 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i5
  getDimM (Ix1T
_, Ix1T
i4, Ix1T
_, Ix1T
_, Ix1T
_) Dim
4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i4
  getDimM (Ix1T
_, Ix1T
_, Ix1T
i3, Ix1T
_, Ix1T
_) Dim
3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i3
  getDimM (Ix1T
_, Ix1T
_, Ix1T
_, Ix1T
i2, Ix1T
_) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i2
  getDimM (Ix1T
_, Ix1T
_, Ix1T
_, Ix1T
_, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix1T
i1
  getDimM Ix5T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix5T
ix Dim
d
  {-# INLINE [1] getDimM #-}
  setDimM :: forall (m :: * -> *). MonadThrow m => Ix5T -> Dim -> Ix1T -> m Ix5T
setDimM (Ix1T
_, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
5 Ix1T
i5 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i5, Ix1T
_, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 Ix1T
i4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i5, Ix1T
i4, Ix1T
_, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T
i3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
_, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
_) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  setDimM Ix5T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix5T
ix Dim
d
  {-# INLINE [1] setDimM #-}
  modifyDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix5T -> Dim -> (Ix1T -> Ix1T) -> m (Ix1T, Ix5T)
modifyDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
5 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, (Ix1T -> Ix1T
f Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, (Ix1T
i5, Ix1T -> Ix1T
f Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, (Ix1T
i5, Ix1T
i4, Ix1T -> Ix1T
f Ix1T
i3, Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
2 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T -> Ix1T
f Ix1T
i2, Ix1T
i1))
  modifyDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
1 Ix1T -> Ix1T
f = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T -> Ix1T
f Ix1T
i1))
  modifyDimM Ix5T
ix Dim
d Ix1T -> Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix5T
ix Dim
d
  {-# INLINE [1] modifyDimM #-}
  pullOutDimM :: forall (m :: * -> *).
MonadThrow m =>
Ix5T -> Dim -> m (Ix1T, Lower Ix5T)
pullOutDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
5 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1))
  pullOutDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i4, (Ix1T
i5, Ix1T
i3, Ix1T
i2, Ix1T
i1))
  pullOutDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i3, (Ix1T
i5, Ix1T
i4, Ix1T
i2, Ix1T
i1))
  pullOutDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i2, (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i1))
  pullOutDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i1, (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2))
  pullOutDimM Ix5T
ix Dim
d = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Ix5T
ix Dim
d
  {-# INLINE [1] pullOutDimM #-}
  insertDimM :: forall (m :: * -> *).
MonadThrow m =>
Lower Ix5T -> Dim -> Ix1T -> m Ix5T
insertDimM (Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
5 Ix1T
i5 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i5, Ix1T
i3, Ix1T
i2, Ix1T
i1) Dim
4 Ix1T
i4 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i5, Ix1T
i4, Ix1T
i2, Ix1T
i1) Dim
3 Ix1T
i3 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i1) Dim
2 Ix1T
i2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2) Dim
1 Ix1T
i1 = forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1)
  insertDimM Lower Ix5T
ix Dim
d Ix1T
_ = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Lower Ix5T
ix Dim
d
  {-# INLINE [1] insertDimM #-}
  pureIndex :: Ix1T -> Ix5T
pureIndex Ix1T
i = (Ix1T
i, Ix1T
i, Ix1T
i, Ix1T
i, Ix1T
i)
  {-# INLINE [1] pureIndex #-}
  liftIndex2 :: (Ix1T -> Ix1T -> Ix1T) -> Ix5T -> Ix5T -> Ix5T
liftIndex2 Ix1T -> Ix1T -> Ix1T
f (Ix1T
i5, Ix1T
i4, Ix1T
i3, Ix1T
i2, Ix1T
i1) (Ix1T
i5', Ix1T
i4', Ix1T
i3', Ix1T
i2', Ix1T
i1') =
    (Ix1T -> Ix1T -> Ix1T
f Ix1T
i5 Ix1T
i5', Ix1T -> Ix1T -> Ix1T
f Ix1T
i4 Ix1T
i4', Ix1T -> Ix1T -> Ix1T
f Ix1T
i3 Ix1T
i3', Ix1T -> Ix1T -> Ix1T
f Ix1T
i2 Ix1T
i2', Ix1T -> Ix1T -> Ix1T
f Ix1T
i1 Ix1T
i1')
  {-# INLINE [1] liftIndex2 #-}