{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- | Tensor operations implementation using the ox-arrays package.
-- These definitions, mostly class instances, are needed to make concrete
-- arrays a valid carrier for a tensor class algebra (instance) defined in
-- "HordeAd.Core.OpsConcrete".
module HordeAd.Core.CarriersConcrete
  ( -- * RepConcrete and its operations
    RepConcrete, tftkG, eltDictRep, showDictRep
    -- * Concrete and its operations
  , Concrete(..), rtoVector, stoVector, xtoVector
  ) where

import Prelude hiding (foldl')

import Control.DeepSeq (NFData (..))
import Data.Vector.Storable qualified as VS

import Data.Array.Nested qualified as Nested
import Data.Array.Nested.Mixed qualified as Mixed
import Data.Array.Nested.Mixed.Shape
import Data.Array.Nested.Ranked qualified as Ranked
import Data.Array.Nested.Shaped qualified as Shaped
import Data.Array.Nested.Shaped.Shape
import Data.Array.Strided.Orthotope (liftVEltwise1)

import HordeAd.Core.TensorKind
import HordeAd.Core.Types

-- * Orphan ox-arrays instances

instance (Nested.IntElt r, Nested.PrimElt r, Eq r, Num r)
         => IntegralH (Nested.Ranked n r) where
  -- These can't be partial, because our conditionals are not lazy
  -- and so the counterfactual branches, with zeros, may get executed
  -- even though they are subsequently ignored.
  quotH :: Ranked n r -> Ranked n r -> Ranked n r
quotH Ranked n r
a Ranked n r
b = Ranked n r -> Ranked n r -> Ranked n r
forall a (n :: Nat).
(IntElt a, PrimElt a) =>
Ranked n a -> Ranked n a -> Ranked n a
Nested.rquotArray Ranked n r
a ((Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r
 -> Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r)
-> Ranked n r -> Ranked n r
forall (n :: Nat) a b.
(Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) a
 -> Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) b)
-> Ranked n a -> Ranked n b
Ranked.liftRanked1 Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r
-> Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r
forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero Ranked n r
b)
  remH :: Ranked n r -> Ranked n r -> Ranked n r
remH Ranked n r
a Ranked n r
b = Ranked n r -> Ranked n r -> Ranked n r
forall a (n :: Nat).
(IntElt a, PrimElt a) =>
Ranked n a -> Ranked n a -> Ranked n a
Nested.rremArray Ranked n r
a ((Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r
 -> Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r)
-> Ranked n r -> Ranked n r
forall (n :: Nat) a b.
(Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) a
 -> Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) b)
-> Ranked n a -> Ranked n b
Ranked.liftRanked1 Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r
-> Mixed (Replicate @(Maybe Nat) n ('Nothing @Nat)) r
forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero Ranked n r
b)

instance (Nested.IntElt r, Nested.PrimElt r, Eq r, Num r)
         => IntegralH (Nested.Shaped sh r) where
  quotH :: Shaped sh r -> Shaped sh r -> Shaped sh r
quotH Shaped sh r
a Shaped sh r
b = Shaped sh r -> Shaped sh r -> Shaped sh r
forall a (sh :: [Nat]).
(IntElt a, PrimElt a) =>
Shaped sh a -> Shaped sh a -> Shaped sh a
Nested.squotArray Shaped sh r
a ((Mixed (MapJust @Nat sh) r -> Mixed (MapJust @Nat sh) r)
-> Shaped sh r -> Shaped sh r
forall (sh :: [Nat]) a b.
(Mixed (MapJust @Nat sh) a -> Mixed (MapJust @Nat sh) b)
-> Shaped sh a -> Shaped sh b
Shaped.liftShaped1 Mixed (MapJust @Nat sh) r -> Mixed (MapJust @Nat sh) r
forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero Shaped sh r
b)
  remH :: Shaped sh r -> Shaped sh r -> Shaped sh r
remH Shaped sh r
a Shaped sh r
b = Shaped sh r -> Shaped sh r -> Shaped sh r
forall a (sh :: [Nat]).
(IntElt a, PrimElt a) =>
Shaped sh a -> Shaped sh a -> Shaped sh a
Nested.sremArray Shaped sh r
a ((Mixed (MapJust @Nat sh) r -> Mixed (MapJust @Nat sh) r)
-> Shaped sh r -> Shaped sh r
forall (sh :: [Nat]) a b.
(Mixed (MapJust @Nat sh) a -> Mixed (MapJust @Nat sh) b)
-> Shaped sh a -> Shaped sh b
Shaped.liftShaped1 Mixed (MapJust @Nat sh) r -> Mixed (MapJust @Nat sh) r
forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero Shaped sh r
b)

instance (Nested.IntElt r, Nested.PrimElt r, Eq r, Num r)
         => IntegralH (Nested.Mixed sh r) where
  quotH :: Mixed sh r -> Mixed sh r -> Mixed sh r
quotH Mixed sh r
a Mixed sh r
b = Mixed sh r -> Mixed sh r -> Mixed sh r
forall a (sh :: [Maybe Nat]).
(IntElt a, PrimElt a) =>
Mixed sh a -> Mixed sh a -> Mixed sh a
Nested.mquotArray Mixed sh r
a (Mixed sh r -> Mixed sh r
forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero Mixed sh r
b)
  remH :: Mixed sh r -> Mixed sh r -> Mixed sh r
remH Mixed sh r
a Mixed sh r
b = Mixed sh r -> Mixed sh r -> Mixed sh r
forall a (sh :: [Maybe Nat]).
(IntElt a, PrimElt a) =>
Mixed sh a -> Mixed sh a -> Mixed sh a
Nested.mremArray Mixed sh r
a (Mixed sh r -> Mixed sh r
forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero Mixed sh r
b)

instance GoodScalar r
         => Real (Nested.Ranked n r) where
  toRational :: Ranked n r -> Rational
toRational = [Char] -> Ranked n r -> Rational
forall a. HasCallStack => [Char] -> a
error [Char]
"toRational is not defined for tensors"

instance GoodScalar r
         => Real (Nested.Shaped sh r) where
  toRational :: Shaped sh r -> Rational
toRational = [Char] -> Shaped sh r -> Rational
forall a. HasCallStack => [Char] -> a
error [Char]
"toRational is not defined for tensors"

instance GoodScalar r
         => Real (Nested.Mixed sh r) where
  toRational :: Mixed sh r -> Rational
toRational = [Char] -> Mixed sh r -> Rational
forall a. HasCallStack => [Char] -> a
error [Char]
"toRational is not defined for tensors"

instance (GoodScalar r, Nested.FloatElt r)
         => RealFrac (Nested.Ranked n r) where
  properFraction :: forall b. Integral b => Ranked n r -> (b, Ranked n r)
properFraction = [Char] -> Ranked n r -> (b, Ranked n r)
forall a. HasCallStack => [Char] -> a
error [Char]
"properFraction is not defined for tensors"

instance (GoodScalar r, RealFrac r, Nested.FloatElt r)
         => RealFrac (Nested.Shaped sh r) where
  properFraction :: forall b. Integral b => Shaped sh r -> (b, Shaped sh r)
properFraction = [Char] -> Shaped sh r -> (b, Shaped sh r)
forall a. HasCallStack => [Char] -> a
error [Char]
"properFraction is not defined for tensors"

instance (GoodScalar r, Nested.FloatElt r)
         => RealFrac (Nested.Mixed sh r) where
  properFraction :: forall b. Integral b => Mixed sh r -> (b, Mixed sh r)
properFraction = [Char] -> Mixed sh r -> (b, Mixed sh r)
forall a. HasCallStack => [Char] -> a
error [Char]
"properFraction is not defined for tensors"

instance (Nested.PrimElt r, Nested.FloatElt r)
         => RealFloatH (Nested.Ranked n r) where
  atan2H :: Ranked n r -> Ranked n r -> Ranked n r
atan2H = Ranked n r -> Ranked n r -> Ranked n r
forall a (n :: Nat).
(FloatElt a, PrimElt a) =>
Ranked n a -> Ranked n a -> Ranked n a
Nested.ratan2Array

instance (Nested.PrimElt r, Nested.FloatElt r)
         => RealFloatH (Nested.Shaped sh r) where
  atan2H :: Shaped sh r -> Shaped sh r -> Shaped sh r
atan2H = Shaped sh r -> Shaped sh r -> Shaped sh r
forall a (sh :: [Nat]).
(FloatElt a, PrimElt a) =>
Shaped sh a -> Shaped sh a -> Shaped sh a
Nested.satan2Array

instance (Nested.PrimElt r, Nested.FloatElt r)
         => RealFloatH (Nested.Mixed sh r) where
  atan2H :: Mixed sh r -> Mixed sh r -> Mixed sh r
atan2H = Mixed sh r -> Mixed sh r -> Mixed sh r
forall a (sh :: [Maybe Nat]).
(FloatElt a, PrimElt a) =>
Mixed sh a -> Mixed sh a -> Mixed sh a
Nested.matan2Array

instance (GoodScalar r, Nested.PrimElt r, RealFloat r, Nested.FloatElt r)
         => RealFloat (Nested.Ranked n r) where
  atan2 :: Ranked n r -> Ranked n r -> Ranked n r
atan2 = Ranked n r -> Ranked n r -> Ranked n r
forall a (n :: Nat).
(FloatElt a, PrimElt a) =>
Ranked n a -> Ranked n a -> Ranked n a
Nested.ratan2Array
  floatRadix :: Ranked n r -> Integer
floatRadix = [Char] -> Ranked n r -> Integer
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  floatDigits :: Ranked n r -> Int
floatDigits = [Char] -> Ranked n r -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  floatRange :: Ranked n r -> (Int, Int)
floatRange = [Char] -> Ranked n r -> (Int, Int)
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  decodeFloat :: Ranked n r -> (Integer, Int)
decodeFloat = [Char] -> Ranked n r -> (Integer, Int)
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  encodeFloat :: Integer -> Int -> Ranked n r
encodeFloat = [Char] -> Integer -> Int -> Ranked n r
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isNaN :: Ranked n r -> Bool
isNaN = [Char] -> Ranked n r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isInfinite :: Ranked n r -> Bool
isInfinite = [Char] -> Ranked n r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isDenormalized :: Ranked n r -> Bool
isDenormalized = [Char] -> Ranked n r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isNegativeZero :: Ranked n r -> Bool
isNegativeZero = [Char] -> Ranked n r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isIEEE :: Ranked n r -> Bool
isIEEE = [Char] -> Ranked n r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"

instance (GoodScalar r, Nested.PrimElt r, RealFloat r, Nested.FloatElt r)
         => RealFloat (Nested.Shaped sh r) where
  atan2 :: Shaped sh r -> Shaped sh r -> Shaped sh r
atan2 = Shaped sh r -> Shaped sh r -> Shaped sh r
forall a (sh :: [Nat]).
(FloatElt a, PrimElt a) =>
Shaped sh a -> Shaped sh a -> Shaped sh a
Nested.satan2Array
  floatRadix :: Shaped sh r -> Integer
floatRadix = [Char] -> Shaped sh r -> Integer
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  floatDigits :: Shaped sh r -> Int
floatDigits = [Char] -> Shaped sh r -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  floatRange :: Shaped sh r -> (Int, Int)
floatRange = [Char] -> Shaped sh r -> (Int, Int)
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  decodeFloat :: Shaped sh r -> (Integer, Int)
decodeFloat = [Char] -> Shaped sh r -> (Integer, Int)
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  encodeFloat :: Integer -> Int -> Shaped sh r
encodeFloat = [Char] -> Integer -> Int -> Shaped sh r
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isNaN :: Shaped sh r -> Bool
isNaN = [Char] -> Shaped sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isInfinite :: Shaped sh r -> Bool
isInfinite = [Char] -> Shaped sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isDenormalized :: Shaped sh r -> Bool
isDenormalized = [Char] -> Shaped sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isNegativeZero :: Shaped sh r -> Bool
isNegativeZero = [Char] -> Shaped sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isIEEE :: Shaped sh r -> Bool
isIEEE = [Char] -> Shaped sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"

instance (GoodScalar r, Nested.PrimElt r, RealFloat r, Nested.FloatElt r)
         => RealFloat (Nested.Mixed sh r) where
  atan2 :: Mixed sh r -> Mixed sh r -> Mixed sh r
atan2 = Mixed sh r -> Mixed sh r -> Mixed sh r
forall a (sh :: [Maybe Nat]).
(FloatElt a, PrimElt a) =>
Mixed sh a -> Mixed sh a -> Mixed sh a
Nested.matan2Array
  floatRadix :: Mixed sh r -> Integer
floatRadix = [Char] -> Mixed sh r -> Integer
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  floatDigits :: Mixed sh r -> Int
floatDigits = [Char] -> Mixed sh r -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  floatRange :: Mixed sh r -> (Int, Int)
floatRange = [Char] -> Mixed sh r -> (Int, Int)
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  decodeFloat :: Mixed sh r -> (Integer, Int)
decodeFloat = [Char] -> Mixed sh r -> (Integer, Int)
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  encodeFloat :: Integer -> Int -> Mixed sh r
encodeFloat = [Char] -> Integer -> Int -> Mixed sh r
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isNaN :: Mixed sh r -> Bool
isNaN = [Char] -> Mixed sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isInfinite :: Mixed sh r -> Bool
isInfinite = [Char] -> Mixed sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isDenormalized :: Mixed sh r -> Bool
isDenormalized = [Char] -> Mixed sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isNegativeZero :: Mixed sh r -> Bool
isNegativeZero = [Char] -> Mixed sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"
  isIEEE :: Mixed sh r -> Bool
isIEEE = [Char] -> Mixed sh r -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"operation not defined for tensors"

-- TODO: make more efficient somehow?
mmakeNonZero :: (Nested.PrimElt r, Eq r, Num r)
             => Nested.Mixed sh r -> Nested.Mixed sh r
mmakeNonZero :: forall r (sh :: [Maybe Nat]).
(PrimElt r, Eq r, Num r) =>
Mixed sh r -> Mixed sh r
mmakeNonZero =
  (SNat (Rank @(Maybe Nat) sh)
 -> Array (Rank @(Maybe Nat) sh) r
 -> Array (Rank @(Maybe Nat) sh) r)
-> Mixed sh r -> Mixed sh r
forall a b (sh :: [Maybe Nat]).
(PrimElt a, PrimElt b) =>
(SNat (Rank @(Maybe Nat) sh)
 -> Array (Rank @(Maybe Nat) sh) a
 -> Array (Rank @(Maybe Nat) sh) b)
-> Mixed sh a -> Mixed sh b
Mixed.mliftNumElt1
    (SNat (Rank @(Maybe Nat) sh)
-> (Vector r -> Vector r)
-> Array (Rank @(Maybe Nat) sh) r
-> Array (Rank @(Maybe Nat) sh) r
forall a b (n :: Nat).
(Storable a, Storable b) =>
SNat n -> (Vector a -> Vector b) -> Array n a -> Array n b
`liftVEltwise1` ((r -> r) -> Vector r -> Vector r
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
VS.map (\r
x -> if r
x r -> r -> Bool
forall a. Eq a => a -> a -> Bool
== r
0 then r
1 else r
x)))


-- * RepConcrete and its operations

-- | The type family that represents tensor kinds in concrete arrays.
type family RepConcrete (y :: TK) where
  RepConcrete (TKScalar r) = r
  RepConcrete (TKR2 n x) = Nested.Ranked n (RepConcrete x)
  RepConcrete (TKS2 sh x) = Nested.Shaped sh (RepConcrete x)
  RepConcrete (TKX2 sh x) = Nested.Mixed sh (RepConcrete x)
  RepConcrete (TKProduct x z) = (RepConcrete x, RepConcrete z)

-- | Computing full shape tensor kinds for concrete arrays.
tftkG :: SingletonTK y -> RepConcrete y -> FullShapeTK y
tftkG :: forall (y :: TK). SingletonTK y -> RepConcrete y -> FullShapeTK y
tftkG SingletonTK y
stk RepConcrete y
t =
  let repackShapeTree :: SingletonTK y
                      -> Mixed.ShapeTree (RepConcrete y)
                      -> FullShapeTK y
      repackShapeTree :: forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK y
stk0 ShapeTree (RepConcrete y)
tree = case SingletonTK y
stk0 of
        SingletonTK y
STKScalar -> FullShapeTK y
FullShapeTK (TKScalar r)
forall r. GoodScalar r => FullShapeTK (TKScalar r)
FTKScalar
        STKR SNat n
_ SingletonTK x
stk1 -> let (IShR n
sh, ShapeTree (RepConcrete x)
rest) = ShapeTree (RepConcrete y)
tree
                       in IShR n -> FullShapeTK x -> FullShapeTK (TKR2 n x)
forall (n :: Nat) (x :: TK).
IShR n -> FullShapeTK x -> FullShapeTK (TKR2 n x)
FTKR IShR n
sh (FullShapeTK x -> FullShapeTK (TKR2 n x))
-> FullShapeTK x -> FullShapeTK (TKR2 n x)
forall a b. (a -> b) -> a -> b
$ SingletonTK x -> ShapeTree (RepConcrete x) -> FullShapeTK x
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK x
stk1 ShapeTree (RepConcrete x)
rest
        STKS ShS sh
_ SingletonTK x
stk1 -> let (ShS sh
sh, ShapeTree (RepConcrete x)
rest) = ShapeTree (RepConcrete y)
tree
                       in ShS sh -> FullShapeTK x -> FullShapeTK (TKS2 sh x)
forall (sh :: [Nat]) (x :: TK).
ShS sh -> FullShapeTK x -> FullShapeTK (TKS2 sh x)
FTKS ShS sh
sh (FullShapeTK x -> FullShapeTK (TKS2 sh x))
-> FullShapeTK x -> FullShapeTK (TKS2 sh x)
forall a b. (a -> b) -> a -> b
$ SingletonTK x -> ShapeTree (RepConcrete x) -> FullShapeTK x
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK x
stk1 ShapeTree (RepConcrete x)
rest
        STKX StaticShX sh
_ SingletonTK x
stk1 -> let (IShX sh
sh, ShapeTree (RepConcrete x)
rest) = ShapeTree (RepConcrete y)
tree
                       in IShX sh -> FullShapeTK x -> FullShapeTK (TKX2 sh x)
forall (sh :: [Maybe Nat]) (x :: TK).
IShX sh -> FullShapeTK x -> FullShapeTK (TKX2 sh x)
FTKX IShX sh
sh (FullShapeTK x -> FullShapeTK (TKX2 sh x))
-> FullShapeTK x -> FullShapeTK (TKX2 sh x)
forall a b. (a -> b) -> a -> b
$ SingletonTK x -> ShapeTree (RepConcrete x) -> FullShapeTK x
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK x
stk1 ShapeTree (RepConcrete x)
rest
        STKProduct SingletonTK y1
stk1 SingletonTK z
stk2 ->
                       let (ShapeTree (RepConcrete y1)
tree1, ShapeTree (RepConcrete z)
tree2) = ShapeTree (RepConcrete y)
tree
                       in FullShapeTK y1 -> FullShapeTK z -> FullShapeTK (TKProduct y1 z)
forall (y1 :: TK) (z :: TK).
FullShapeTK y1 -> FullShapeTK z -> FullShapeTK (TKProduct y1 z)
FTKProduct (SingletonTK y1 -> ShapeTree (RepConcrete y1) -> FullShapeTK y1
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK y1
stk1 ShapeTree (RepConcrete y1)
tree1)
                                     (SingletonTK z -> ShapeTree (RepConcrete z) -> FullShapeTK z
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK z
stk2 ShapeTree (RepConcrete z)
tree2)
  in case SingletonTK y
stk of
    SingletonTK y
STKScalar -> FullShapeTK y
FullShapeTK (TKScalar r)
forall r. GoodScalar r => FullShapeTK (TKScalar r)
FTKScalar
    STKR SNat n
_ SingletonTK x
stk1 | Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
stk1 ->
      IShR n -> FullShapeTK x -> FullShapeTK (TKR2 n x)
forall (n :: Nat) (x :: TK).
IShR n -> FullShapeTK x -> FullShapeTK (TKR2 n x)
FTKR (Ranked n (RepConcrete x) -> IShR n
forall a (n :: Nat). Elt a => Ranked n a -> IShR n
Nested.rshape Ranked n (RepConcrete x)
RepConcrete y
t) (FullShapeTK x -> FullShapeTK (TKR2 n x))
-> FullShapeTK x -> FullShapeTK (TKR2 n x)
forall a b. (a -> b) -> a -> b
$ SingletonTK x -> ShapeTree (RepConcrete x) -> FullShapeTK x
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK x
stk1
      (ShapeTree (RepConcrete x) -> FullShapeTK x)
-> ShapeTree (RepConcrete x) -> FullShapeTK x
forall a b. (a -> b) -> a -> b
$ (IShR n, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x)
forall a b. (a, b) -> b
snd ((IShR n, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x))
-> (IShR n, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x)
forall a b. (a -> b) -> a -> b
$ Ranked n (RepConcrete x) -> ShapeTree (Ranked n (RepConcrete x))
forall a. Elt a => a -> ShapeTree a
Mixed.mshapeTree Ranked n (RepConcrete x)
RepConcrete y
t
    STKS ShS sh
sh SingletonTK x
stk1 | Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
stk1 ->
      ShS sh -> FullShapeTK x -> FullShapeTK (TKS2 sh x)
forall (sh :: [Nat]) (x :: TK).
ShS sh -> FullShapeTK x -> FullShapeTK (TKS2 sh x)
FTKS ShS sh
sh (FullShapeTK x -> FullShapeTK (TKS2 sh x))
-> FullShapeTK x -> FullShapeTK (TKS2 sh x)
forall a b. (a -> b) -> a -> b
$ SingletonTK x -> ShapeTree (RepConcrete x) -> FullShapeTK x
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK x
stk1
      (ShapeTree (RepConcrete x) -> FullShapeTK x)
-> ShapeTree (RepConcrete x) -> FullShapeTK x
forall a b. (a -> b) -> a -> b
$ (ShS sh, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x)
forall a b. (a, b) -> b
snd ((ShS sh, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x))
-> (ShS sh, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x)
forall a b. (a -> b) -> a -> b
$ Shaped sh (RepConcrete x) -> ShapeTree (Shaped sh (RepConcrete x))
forall a. Elt a => a -> ShapeTree a
Mixed.mshapeTree Shaped sh (RepConcrete x)
RepConcrete y
t
    STKX StaticShX sh
_ SingletonTK x
stk1 | Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
stk1 ->
      IShX sh -> FullShapeTK x -> FullShapeTK (TKX2 sh x)
forall (sh :: [Maybe Nat]) (x :: TK).
IShX sh -> FullShapeTK x -> FullShapeTK (TKX2 sh x)
FTKX (Mixed sh (RepConcrete x) -> IShX sh
forall (sh :: [Maybe Nat]). Mixed sh (RepConcrete x) -> IShX sh
forall a (sh :: [Maybe Nat]). Elt a => Mixed sh a -> IShX sh
Nested.mshape Mixed sh (RepConcrete x)
RepConcrete y
t) (FullShapeTK x -> FullShapeTK (TKX2 sh x))
-> FullShapeTK x -> FullShapeTK (TKX2 sh x)
forall a b. (a -> b) -> a -> b
$ SingletonTK x -> ShapeTree (RepConcrete x) -> FullShapeTK x
forall (y :: TK).
SingletonTK y -> ShapeTree (RepConcrete y) -> FullShapeTK y
repackShapeTree SingletonTK x
stk1
      (ShapeTree (RepConcrete x) -> FullShapeTK x)
-> ShapeTree (RepConcrete x) -> FullShapeTK x
forall a b. (a -> b) -> a -> b
$ (IShX sh, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x)
forall a b. (a, b) -> b
snd ((IShX sh, ShapeTree (RepConcrete x)) -> ShapeTree (RepConcrete x))
-> (IShX sh, ShapeTree (RepConcrete x))
-> ShapeTree (RepConcrete x)
forall a b. (a -> b) -> a -> b
$ Mixed sh (RepConcrete x) -> ShapeTree (Mixed sh (RepConcrete x))
forall a. Elt a => a -> ShapeTree a
Mixed.mshapeTree Mixed sh (RepConcrete x)
RepConcrete y
t
    STKProduct SingletonTK y1
stk1 SingletonTK z
stk2 ->
      FullShapeTK y1 -> FullShapeTK z -> FullShapeTK (TKProduct y1 z)
forall (y1 :: TK) (z :: TK).
FullShapeTK y1 -> FullShapeTK z -> FullShapeTK (TKProduct y1 z)
FTKProduct (SingletonTK y1 -> RepConcrete y1 -> FullShapeTK y1
forall (y :: TK). SingletonTK y -> RepConcrete y -> FullShapeTK y
tftkG SingletonTK y1
stk1 ((RepConcrete y1, RepConcrete z) -> RepConcrete y1
forall a b. (a, b) -> a
fst (RepConcrete y1, RepConcrete z)
RepConcrete y
t))
                 (SingletonTK z -> RepConcrete z -> FullShapeTK z
forall (y :: TK). SingletonTK y -> RepConcrete y -> FullShapeTK y
tftkG SingletonTK z
stk2 ((RepConcrete y1, RepConcrete z) -> RepConcrete z
forall a b. (a, b) -> b
snd (RepConcrete y1, RepConcrete z)
RepConcrete y
t))

eltDictRep :: SingletonTK y -> Dict Nested.KnownElt (RepConcrete y)
eltDictRep :: forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep = \case
    SingletonTK y
STKScalar -> Dict @Type KnownElt r
Dict @Type KnownElt (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKR SNat n
SNat SingletonTK x
x | Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type KnownElt (Ranked n (RepConcrete x))
Dict @Type KnownElt (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKS ShS sh
sh SingletonTK x
x | Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> ShS sh
-> (KnownShS sh => Dict @Type KnownElt (Shaped sh (RepConcrete x)))
-> Dict @Type KnownElt (Shaped sh (RepConcrete x))
forall (sh :: [Nat]) r. ShS sh -> (KnownShS sh => r) -> r
withKnownShS ShS sh
sh Dict @Type KnownElt (Shaped sh (RepConcrete x))
KnownShS sh => Dict @Type KnownElt (Shaped sh (RepConcrete x))
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKX StaticShX sh
sh SingletonTK x
x | Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> StaticShX sh
-> (KnownShX sh => Dict @Type KnownElt (Mixed sh (RepConcrete x)))
-> Dict @Type KnownElt (Mixed sh (RepConcrete x))
forall (sh :: [Maybe Nat]) r.
StaticShX sh -> (KnownShX sh => r) -> r
withKnownShX StaticShX sh
sh Dict @Type KnownElt (Mixed sh (RepConcrete x))
KnownShX sh => Dict @Type KnownElt (Mixed sh (RepConcrete x))
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKProduct SingletonTK y1
stk1 SingletonTK z
stk2 | Dict @Type KnownElt (RepConcrete y1)
Dict <- SingletonTK y1 -> Dict @Type KnownElt (RepConcrete y1)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK y1
stk1
                         , Dict @Type KnownElt (RepConcrete z)
Dict <- SingletonTK z -> Dict @Type KnownElt (RepConcrete z)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK z
stk2 -> Dict @Type KnownElt (RepConcrete y1, RepConcrete z)
Dict @Type KnownElt (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict

showDictRep :: SingletonTK y -> Dict Show (RepConcrete y)
showDictRep :: forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep = \case
    SingletonTK y
STKScalar -> Dict @Type Show r
Dict @Type Show (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKR SNat n
_ SingletonTK x
x | Dict @Type Show (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type Show (RepConcrete x)
forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep SingletonTK x
x
             , Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type Show (Ranked n (RepConcrete x))
Dict @Type Show (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKS ShS sh
_ SingletonTK x
x | Dict @Type Show (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type Show (RepConcrete x)
forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep SingletonTK x
x
             , Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type Show (Shaped sh (RepConcrete x))
Dict @Type Show (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKX StaticShX sh
_ SingletonTK x
x | Dict @Type Show (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type Show (RepConcrete x)
forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep SingletonTK x
x
             , Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type Show (Mixed sh (RepConcrete x))
Dict @Type Show (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKProduct SingletonTK y1
stk1 SingletonTK z
stk2 | Dict @Type Show (RepConcrete y1)
Dict <- SingletonTK y1 -> Dict @Type Show (RepConcrete y1)
forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep SingletonTK y1
stk1
                         , Dict @Type Show (RepConcrete z)
Dict <- SingletonTK z -> Dict @Type Show (RepConcrete z)
forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep SingletonTK z
stk2 -> Dict @Type Show (RepConcrete y1, RepConcrete z)
Dict @Type Show (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict

nfdataDictRep :: SingletonTK y -> Dict NFData (RepConcrete y)
nfdataDictRep :: forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep = \case
    SingletonTK y
STKScalar -> Dict @Type NFData r
Dict @Type NFData (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKR SNat n
_ SingletonTK x
x | Dict @Type NFData (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type NFData (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep SingletonTK x
x
             , Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type NFData (Ranked n (RepConcrete x))
Dict @Type NFData (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKS ShS sh
_ SingletonTK x
x | Dict @Type NFData (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type NFData (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep SingletonTK x
x
             , Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type NFData (Shaped sh (RepConcrete x))
Dict @Type NFData (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKX StaticShX sh
_ SingletonTK x
x | Dict @Type NFData (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type NFData (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep SingletonTK x
x
             , Dict @Type KnownElt (RepConcrete x)
Dict <- SingletonTK x -> Dict @Type KnownElt (RepConcrete x)
forall (y :: TK).
SingletonTK y -> Dict @Type KnownElt (RepConcrete y)
eltDictRep SingletonTK x
x -> Dict @Type NFData (Mixed sh (RepConcrete x))
Dict @Type NFData (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict
    STKProduct SingletonTK y1
stk1 SingletonTK z
stk2 | Dict @Type NFData (RepConcrete y1)
Dict <- SingletonTK y1 -> Dict @Type NFData (RepConcrete y1)
forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep SingletonTK y1
stk1
                         , Dict @Type NFData (RepConcrete z)
Dict <- SingletonTK z -> Dict @Type NFData (RepConcrete z)
forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep SingletonTK z
stk2 -> Dict @Type NFData (RepConcrete y1, RepConcrete z)
Dict @Type NFData (RepConcrete y)
forall {k} (c :: k -> Constraint) (a :: k). c a => Dict @k c a
Dict


-- * Concrete and its instances

-- | A newtype wrapper over 'RepConcrete'.
-- It's needed because @RepConcrete@ can't be partially applied.
-- This type also lets us work around the woes with defining 'Show'
-- for the @RepConcrete@ type family. It gives us a concrete thing
-- to attach a @Show@ instance to.
type role Concrete nominal
newtype Concrete y = Concrete {forall (y :: TK). Concrete y -> RepConcrete y
unConcrete :: RepConcrete y}

instance KnownSTK y => Show (Concrete y) where
  showsPrec :: Int -> Concrete y -> ShowS
showsPrec Int
d (Concrete RepConcrete y
t) | Dict @Type Show (RepConcrete y)
Dict <- SingletonTK y -> Dict @Type Show (RepConcrete y)
forall (y :: TK). SingletonTK y -> Dict @Type Show (RepConcrete y)
showDictRep (forall (y :: TK). KnownSTK y => SingletonTK y
knownSTK @y) = Int -> RepConcrete y -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d RepConcrete y
t

instance KnownSTK y => NFData (Concrete y) where
  rnf :: Concrete y -> ()
rnf (Concrete RepConcrete y
t) | Dict @Type NFData (RepConcrete y)
Dict <- SingletonTK y -> Dict @Type NFData (RepConcrete y)
forall (y :: TK).
SingletonTK y -> Dict @Type NFData (RepConcrete y)
nfdataDictRep (forall (y :: TK). KnownSTK y => SingletonTK y
knownSTK @y) = RepConcrete y -> ()
forall a. NFData a => a -> ()
rnf RepConcrete y
t

type instance BoolOf Concrete = Bool

type instance HFunOf Concrete x z = RepConcrete x -> RepConcrete z

type instance PrimalOf Concrete = Concrete

type instance DualOf Concrete = DummyDualTarget

type instance ShareOf Concrete = Concrete

instance GoodScalar r => EqH Concrete (TKScalar r) where
  Concrete RepConcrete (TKScalar r)
u ==. :: Concrete (TKScalar r) -> Concrete (TKScalar r) -> BoolOf Concrete
==. Concrete RepConcrete (TKScalar r)
v = r
RepConcrete (TKScalar r)
u r -> r -> Bool
forall a. Eq a => a -> a -> Bool
== r
RepConcrete (TKScalar r)
v

instance GoodScalar r => OrdH Concrete (TKScalar r) where
  Concrete RepConcrete (TKScalar r)
u <=. :: Concrete (TKScalar r) -> Concrete (TKScalar r) -> BoolOf Concrete
<=. Concrete RepConcrete (TKScalar r)
v = r
RepConcrete (TKScalar r)
u r -> r -> Bool
forall a. Ord a => a -> a -> Bool
<= r
RepConcrete (TKScalar r)
v

instance GoodScalar r => EqH Concrete (TKR n r) where
  Concrete RepConcrete (TKR n r)
u ==. :: Concrete (TKR n r) -> Concrete (TKR n r) -> BoolOf Concrete
==. Concrete RepConcrete (TKR n r)
v = Ranked n r
RepConcrete (TKR n r)
u Ranked n r -> Ranked n r -> Bool
forall a. Eq a => a -> a -> Bool
== Ranked n r
RepConcrete (TKR n r)
v

instance GoodScalar r => OrdH Concrete (TKR n r) where
  Concrete RepConcrete (TKR n r)
u <=. :: Concrete (TKR n r) -> Concrete (TKR n r) -> BoolOf Concrete
<=. Concrete RepConcrete (TKR n r)
v = Ranked n r
RepConcrete (TKR n r)
u Ranked n r -> Ranked n r -> Bool
forall a. Ord a => a -> a -> Bool
<= Ranked n r
RepConcrete (TKR n r)
v

instance GoodScalar r => EqH Concrete (TKS sh r) where
  Concrete RepConcrete (TKS sh r)
u ==. :: Concrete (TKS sh r) -> Concrete (TKS sh r) -> BoolOf Concrete
==. Concrete RepConcrete (TKS sh r)
v = Shaped sh r
RepConcrete (TKS sh r)
u Shaped sh r -> Shaped sh r -> Bool
forall a. Eq a => a -> a -> Bool
== Shaped sh r
RepConcrete (TKS sh r)
v

instance GoodScalar r => OrdH Concrete (TKS sh r) where
  Concrete RepConcrete (TKS sh r)
u <=. :: Concrete (TKS sh r) -> Concrete (TKS sh r) -> BoolOf Concrete
<=. Concrete RepConcrete (TKS sh r)
v = Shaped sh r
RepConcrete (TKS sh r)
u Shaped sh r -> Shaped sh r -> Bool
forall a. Ord a => a -> a -> Bool
<= Shaped sh r
RepConcrete (TKS sh r)
v

instance GoodScalar r => EqH Concrete (TKX sh r) where
  Concrete RepConcrete (TKX sh r)
u ==. :: Concrete (TKX sh r) -> Concrete (TKX sh r) -> BoolOf Concrete
==. Concrete RepConcrete (TKX sh r)
v = Mixed sh r
RepConcrete (TKX sh r)
u Mixed sh r -> Mixed sh r -> Bool
forall a. Eq a => a -> a -> Bool
== Mixed sh r
RepConcrete (TKX sh r)
v

instance GoodScalar r => OrdH Concrete (TKX sh r) where
  Concrete RepConcrete (TKX sh r)
u <=. :: Concrete (TKX sh r) -> Concrete (TKX sh r) -> BoolOf Concrete
<=. Concrete RepConcrete (TKX sh r)
v = Mixed sh r
RepConcrete (TKX sh r)
u Mixed sh r -> Mixed sh r -> Bool
forall a. Ord a => a -> a -> Bool
<= Mixed sh r
RepConcrete (TKX sh r)
v

deriving instance Eq (RepConcrete y) => Eq (Concrete y)
deriving instance Ord (RepConcrete y) => Ord (Concrete y)
deriving instance Num (RepConcrete y) => Num (Concrete y)
deriving instance IntegralH (RepConcrete y) => IntegralH (Concrete y)
deriving instance Real (RepConcrete y) => Real (Concrete y)
deriving instance Fractional (RepConcrete y) => Fractional (Concrete y)
deriving instance Floating (RepConcrete y) => Floating (Concrete y)
deriving instance RealFrac (RepConcrete y) => RealFrac (Concrete y)
deriving instance RealFloatH (RepConcrete y) => RealFloatH (Concrete y)
deriving instance RealFloat (RepConcrete y) => RealFloat (Concrete y)

rtoVector :: GoodScalar r => Concrete (TKR n r) -> VS.Vector r
rtoVector :: forall r (n :: Nat). GoodScalar r => Concrete (TKR n r) -> Vector r
rtoVector = Ranked n r -> Vector r
forall a (n :: Nat). PrimElt a => Ranked n a -> Vector a
Nested.rtoVector (Ranked n r -> Vector r)
-> (Concrete (TKR n r) -> Ranked n r)
-> Concrete (TKR n r)
-> Vector r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Concrete (TKR n r) -> Ranked n r
Concrete (TKR n r) -> RepConcrete (TKR n r)
forall (y :: TK). Concrete y -> RepConcrete y
unConcrete

stoVector :: GoodScalar r => Concrete (TKS sh r) -> VS.Vector r
stoVector :: forall r (sh :: [Nat]).
GoodScalar r =>
Concrete (TKS sh r) -> Vector r
stoVector = Shaped sh r -> Vector r
forall a (sh :: [Nat]). PrimElt a => Shaped sh a -> Vector a
Nested.stoVector (Shaped sh r -> Vector r)
-> (Concrete (TKS sh r) -> Shaped sh r)
-> Concrete (TKS sh r)
-> Vector r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Concrete (TKS sh r) -> Shaped sh r
Concrete (TKS sh r) -> RepConcrete (TKS sh r)
forall (y :: TK). Concrete y -> RepConcrete y
unConcrete

xtoVector :: GoodScalar r => Concrete (TKX sh r) -> VS.Vector r
xtoVector :: forall r (sh :: [Maybe Nat]).
GoodScalar r =>
Concrete (TKX sh r) -> Vector r
xtoVector = Mixed sh r -> Vector r
forall a (sh :: [Maybe Nat]). PrimElt a => Mixed sh a -> Vector a
Nested.mtoVector (Mixed sh r -> Vector r)
-> (Concrete (TKX sh r) -> Mixed sh r)
-> Concrete (TKX sh r)
-> Vector r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Concrete (TKX sh r) -> Mixed sh r
Concrete (TKX sh r) -> RepConcrete (TKX sh r)
forall (y :: TK). Concrete y -> RepConcrete y
unConcrete