Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type family AddSizeF (size :: Size Nat) (size' :: Size Nat) :: Size Nat where ...
- type family AddDimF (dim :: Dim (Name Symbol) (Size Nat)) (dim' :: Dim (Name Symbol) (Size Nat)) :: Dim (Name Symbol) (Size Nat) where ...
- type family BroadcastSizeF (size :: Size Nat) (size' :: Size Nat) :: Maybe (Size Nat) where ...
- type family BroadcastDimF (dim :: Dim (Name Symbol) (Size Nat)) (dim' :: Dim (Name Symbol) (Size Nat)) :: Maybe (Dim (Name Symbol) (Size Nat)) where ...
- type family NumelDimF (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe Nat where ...
- type family BroadcastDimsCheckF (dims :: [Dim (Name Symbol) (Size Nat)]) (dims' :: [Dim (Name Symbol) (Size Nat)]) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ...
- type family BroadcastDimsImplF (reversedDims :: [Dim (Name Symbol) (Size Nat)]) (reversedDims' :: [Dim (Name Symbol) (Size Nat)]) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type BroadcastDimsF dims dims' = BroadcastDimsCheckF dims dims' (BroadcastDimsImplF (Reverse dims) (Reverse dims'))
- type family BroadcastShapesF (shape :: Shape [Dim (Name Symbol) (Size Nat)]) (shape' :: Shape [Dim (Name Symbol) (Size Nat)]) :: Shape [Dim (Name Symbol) (Size Nat)] where ...
- type family NumelDimsF (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe Nat where ...
- type family NumelF (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Maybe Nat where ...
- type family GetDimAndIndexByNameF (index :: Nat) (result :: (Maybe (Dim (Name Symbol) (Size Nat)), Maybe Nat)) (name :: Symbol) (dims :: [Dim (Name Symbol) (Size Nat)]) :: (Maybe (Dim (Name Symbol) (Size Nat)), Maybe Nat) where ...
- type family GetDimByNameF (name :: Symbol) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe (Dim (Name Symbol) (Size Nat)) where ...
- type family GetIndexByNameF (name :: Symbol) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe Nat where ...
- type family GetDimByIndexF (index :: Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe (Dim (Name Symbol) (Size Nat)) where ...
- type family GetDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe (Dim (Name Symbol) (Size Nat)) where ...
- type GetDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) = "Cannot return the first dimension matching" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'.") % ""))))))
- type family GetDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (result :: Maybe (Dim (Name Symbol) (Size Nat))) :: Dim (Name Symbol) (Size Nat) where ...
- type family GetDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Dim (Name Symbol) (Size Nat) where ...
- type family (shape :: Shape [Dim (Name Symbol) (Size Nat)]) ! (_k :: k) :: Dim (Name Symbol) (Size Nat) where ...
- sGetDimFromShape :: forall selectDim shape dim m. (dim ~ GetDimF selectDim shape, MonadThrow m) => SSelectDim selectDim -> SShape shape -> m (SDim dim)
- data GetDimError
- type family ReplaceDimByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family ReplaceDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family ReplaceDimNameByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (name :: Name Symbol) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family ReplaceDimNameImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (name' :: Name Symbol) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family ReplaceDimSizeByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (size' :: Size Nat) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family ReplaceDimSizeImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (size' :: Size Nat) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type ReplaceDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) = "Cannot replace the first dimension matching" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'") % ("" % ("with" % ("" % (((" '" <> dim) <> "'.") % ""))))))))))
- type family ReplaceDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ...
- type family ReplaceDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Shape [Dim (Name Symbol) (Size Nat)] where ...
- type family InsertDimByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family InsertDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type InsertDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) = "Cannot insert the dimension" % ("" % (((" '" <> dim) <> "'") % ("" % ("before the first dimension matching" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'.") % ""))))))))))
- type family InsertDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ...
- type family InsertDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Shape [Dim (Name Symbol) (Size Nat)] where ...
- type family PrependDimF (dim :: Dim (Name Symbol) (Size Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Shape [Dim (Name Symbol) (Size Nat)] where ...
- type family RemoveDimByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type family RemoveDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe [Dim (Name Symbol) (Size Nat)] where ...
- type RemoveDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) = "Cannot remove the dimension by" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'.") % ""))))))
- type family RemoveDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ...
- type family RemoveDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Shape [Dim (Name Symbol) (Size Nat)] where ...
- data UnifyNameError = UnifyNameError {}
- sUnifyName :: forall m name name'. MonadThrow m => SName name -> SName name' -> m (SName (name <+> name'))
- data UnifySizeError = UnifySizeError {}
- sUnifySize :: forall m size size'. MonadThrow m => SSize size -> SSize size' -> m (SSize (size <+> size'))
- sUnifyDim :: forall m dim dim'. MonadThrow m => SDim dim -> SDim dim' -> m (SDim (dim <+> dim'))
Documentation
>>>
import Torch.GraduallyTyped.Prelude.List (SList (..))
>>>
import Torch.GraduallyTyped
type family AddDimF (dim :: Dim (Name Symbol) (Size Nat)) (dim' :: Dim (Name Symbol) (Size Nat)) :: Dim (Name Symbol) (Size Nat) where ... Source #
type family BroadcastSizeF (size :: Size Nat) (size' :: Size Nat) :: Maybe (Size Nat) where ... Source #
BroadcastSizeF 'UncheckedSize _ = 'Just 'UncheckedSize | |
BroadcastSizeF _ 'UncheckedSize = 'Just 'UncheckedSize | |
BroadcastSizeF ('Size size) ('Size size) = 'Just ('Size size) | |
BroadcastSizeF ('Size size) ('Size 1) = 'Just ('Size size) | |
BroadcastSizeF ('Size 1) ('Size size) = 'Just ('Size size) | |
BroadcastSizeF ('Size _) ('Size _) = 'Nothing |
type family BroadcastDimF (dim :: Dim (Name Symbol) (Size Nat)) (dim' :: Dim (Name Symbol) (Size Nat)) :: Maybe (Dim (Name Symbol) (Size Nat)) where ... Source #
BroadcastDimF ('Dim name size) ('Dim name' size') = MapMaybe ('Dim (name <+> name')) (BroadcastSizeF size size') |
type family BroadcastDimsCheckF (dims :: [Dim (Name Symbol) (Size Nat)]) (dims' :: [Dim (Name Symbol) (Size Nat)]) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ... Source #
type family BroadcastDimsImplF (reversedDims :: [Dim (Name Symbol) (Size Nat)]) (reversedDims' :: [Dim (Name Symbol) (Size Nat)]) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
BroadcastDimsImplF '[] reversedDims = 'Just reversedDims | |
BroadcastDimsImplF reversedDims '[] = 'Just reversedDims | |
BroadcastDimsImplF (dim ': reversedDims) (dim' ': reversedDims') = PrependMaybe (BroadcastDimF dim dim') (BroadcastDimsImplF reversedDims reversedDims') |
type BroadcastDimsF dims dims' = BroadcastDimsCheckF dims dims' (BroadcastDimsImplF (Reverse dims) (Reverse dims')) Source #
type family BroadcastShapesF (shape :: Shape [Dim (Name Symbol) (Size Nat)]) (shape' :: Shape [Dim (Name Symbol) (Size Nat)]) :: Shape [Dim (Name Symbol) (Size Nat)] where ... Source #
BroadcastShapesF shape shape = shape | |
BroadcastShapesF ('Shape dims) ('Shape dims') = 'Shape (BroadcastDimsF dims dims') | |
BroadcastShapesF shape shape' = shape <+> shape' |
type family NumelDimsF (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe Nat where ... Source #
NumelDimsF '[] = 'Just 1 | |
NumelDimsF (dim ': dims) = LiftTimesMaybe (NumelDimF dim) (NumelDimsF dims) |
type family NumelF (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Maybe Nat where ... Source #
NumelF 'UncheckedShape = 'Nothing | |
NumelF ('Shape dims) = NumelDimsF dims |
type family GetDimAndIndexByNameF (index :: Nat) (result :: (Maybe (Dim (Name Symbol) (Size Nat)), Maybe Nat)) (name :: Symbol) (dims :: [Dim (Name Symbol) (Size Nat)]) :: (Maybe (Dim (Name Symbol) (Size Nat)), Maybe Nat) where ... Source #
GetDimAndIndexByNameF _ result _ '[] = result | |
GetDimAndIndexByNameF index _ name ('Dim 'UncheckedName _ ': dims) = GetDimAndIndexByNameF (index + 1) '('Just ('Dim 'UncheckedName 'UncheckedSize), 'Nothing) name dims | |
GetDimAndIndexByNameF index _ name ('Dim ('Name name) size ': _) = '('Just ('Dim ('Name name) size), 'Just index) | |
GetDimAndIndexByNameF index result name ('Dim ('Name _) _ ': dims) = GetDimAndIndexByNameF (index + 1) result name dims |
type family GetDimByNameF (name :: Symbol) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe (Dim (Name Symbol) (Size Nat)) where ... Source #
GetDimByNameF name dims = Fst (GetDimAndIndexByNameF 0 '('Nothing, 'Nothing) name dims) |
type family GetIndexByNameF (name :: Symbol) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe Nat where ... Source #
GetIndexByNameF name dims = Snd (GetDimAndIndexByNameF 0 '('Nothing, 'Nothing) name dims) |
type family GetDimByIndexF (index :: Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe (Dim (Name Symbol) (Size Nat)) where ... Source #
GetDimByIndexF 0 (h ': _) = 'Just h | |
GetDimByIndexF index (_ ': t) = GetDimByIndexF (index - 1) t | |
GetDimByIndexF _ _ = 'Nothing |
type family GetDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe (Dim (Name Symbol) (Size Nat)) where ... Source #
GetDimImplF ('ByName name) dims = GetDimByNameF name dims | |
GetDimImplF ('ByIndex index) dims = GetDimByIndexF index dims |
type GetDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) = "Cannot return the first dimension matching" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'.") % "")))))) Source #
type family GetDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (result :: Maybe (Dim (Name Symbol) (Size Nat))) :: Dim (Name Symbol) (Size Nat) where ... Source #
GetDimCheckF by dims 'Nothing = TypeError (GetDimErrorMessage by dims) | |
GetDimCheckF _ _ ('Just dim) = dim |
type family GetDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Dim (Name Symbol) (Size Nat) where ... Source #
GetDimF 'UncheckedSelectDim _ = 'Dim 'UncheckedName 'UncheckedSize | |
GetDimF _ 'UncheckedShape = 'Dim 'UncheckedName 'UncheckedSize | |
GetDimF ('SelectDim by) ('Shape dims) = GetDimCheckF by dims (GetDimImplF by dims) |
type family (shape :: Shape [Dim (Name Symbol) (Size Nat)]) ! (_k :: k) :: Dim (Name Symbol) (Size Nat) where ... Source #
sGetDimFromShape :: forall selectDim shape dim m. (dim ~ GetDimF selectDim shape, MonadThrow m) => SSelectDim selectDim -> SShape shape -> m (SDim dim) Source #
Get dimension by index or by name from a shape.
>>>
shape = SShape $ SName @"batch" :&: SSize @8 :|: SUncheckedName "feature" :&: SSize @2 :|: SNil
>>>
dim = sGetDimFromShape (SSelectDim $ SByName @"batch") shape
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim ('Name "batch") ('Size 8)))>>>
fromSing <$> dim
Dim {dimName = Checked "batch", dimSize = Checked 8}
>>>
dim = sGetDimFromShape (SSelectDim $ SByName @"feature") shape
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim 'UncheckedName 'UncheckedSize))>>>
fromSing <$> dim
Dim {dimName = Unchecked "feature", dimSize = Checked 2}
>>>
dim = sGetDimFromShape (SSelectDim $ SByName @"sequence") shape
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim 'UncheckedName 'UncheckedSize))>>>
fromSing <$> dim
*** Exception: GetDimError {gdeBy = ByName "sequence"}
>>>
dim = sGetDimFromShape (SSelectDim $ SByIndex @0) shape
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim ('Name "batch") ('Size 8)))>>>
fromSing <$> dim
Dim {dimName = Checked "batch", dimSize = Checked 8}
>>>
:type sGetDimFromShape (SSelectDim $ SByIndex @2) shape
sGetDimFromShape (SSelectDim $ SByIndex @2) shape :: MonadThrow m => m (SDim (TypeError ...))
data GetDimError Source #
Instances
Exception GetDimError Source # | |
Defined in Torch.GraduallyTyped.Shape.Class | |
Show GetDimError Source # | |
Defined in Torch.GraduallyTyped.Shape.Class |
type family ReplaceDimByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimByIndexF ('Just 0) (_ ': t) dim = 'Just (dim ': t) | |
ReplaceDimByIndexF ('Just index) (h ': t) dim = PrependMaybe ('Just h) (ReplaceDimByIndexF ('Just (index - 1)) t dim) | |
ReplaceDimByIndexF _ _ _ = 'Nothing |
type family ReplaceDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimImplF ('ByName name) dims dim = ReplaceDimByIndexF (GetIndexByNameF name dims) dims dim | |
ReplaceDimImplF ('ByIndex index) dims dim = ReplaceDimByIndexF ('Just index) dims dim |
type family ReplaceDimNameByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (name :: Name Symbol) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimNameByIndexF ('Just 0) ('Dim _ size ': t) name' = 'Just ('Dim name' size ': t) | |
ReplaceDimNameByIndexF ('Just index) (h ': t) name' = PrependMaybe ('Just h) (ReplaceDimNameByIndexF ('Just (index - 1)) t name') | |
ReplaceDimNameByIndexF _ _ _ = 'Nothing |
type family ReplaceDimNameImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (name' :: Name Symbol) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimNameImplF ('ByName name) dims name' = ReplaceDimNameByIndexF (GetIndexByNameF name dims) dims name' | |
ReplaceDimNameImplF ('ByIndex index) dims name' = ReplaceDimNameByIndexF ('Just index) dims name' |
type family ReplaceDimSizeByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (size' :: Size Nat) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimSizeByIndexF ('Just 0) ('Dim name _ ': t) size' = 'Just ('Dim name size' ': t) | |
ReplaceDimSizeByIndexF ('Just index) (h ': t) size' = PrependMaybe ('Just h) (ReplaceDimSizeByIndexF ('Just (index - 1)) t size') | |
ReplaceDimSizeByIndexF _ _ _ = 'Nothing |
type family ReplaceDimSizeImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (size' :: Size Nat) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimSizeImplF ('ByName name) dims size' = ReplaceDimSizeByIndexF (GetIndexByNameF name dims) dims size' | |
ReplaceDimSizeImplF ('ByIndex index) dims size' = ReplaceDimSizeByIndexF ('Just index) dims size' |
type ReplaceDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) = "Cannot replace the first dimension matching" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'") % ("" % ("with" % ("" % (((" '" <> dim) <> "'.") % "")))))))))) Source #
type family ReplaceDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimCheckF by dims dim 'Nothing = TypeError (ReplaceDimErrorMessage by dims dim) | |
ReplaceDimCheckF _ _ _ ('Just dims) = dims |
type family ReplaceDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Shape [Dim (Name Symbol) (Size Nat)] where ... Source #
ReplaceDimF 'UncheckedSelectDim _ _ = 'UncheckedShape | |
ReplaceDimF _ 'UncheckedShape _ = 'UncheckedShape | |
ReplaceDimF ('SelectDim by) ('Shape dims) dim = 'Shape (ReplaceDimCheckF by dims dim (ReplaceDimImplF by dims dim)) |
type family InsertDimByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
InsertDimByIndexF ('Just 0) dims dim = 'Just (dim ': dims) | |
InsertDimByIndexF ('Just index) (h ': t) dim = PrependMaybe ('Just h) (InsertDimByIndexF ('Just (index - 1)) t dim) | |
InsertDimByIndexF _ _ _ = 'Nothing |
type family InsertDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
InsertDimImplF ('ByName name) dims dim = InsertDimByIndexF (GetIndexByNameF name dims) dims dim | |
InsertDimImplF ('ByIndex index) dims dim = InsertDimByIndexF ('Just index) dims dim |
type InsertDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) = "Cannot insert the dimension" % ("" % (((" '" <> dim) <> "'") % ("" % ("before the first dimension matching" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'.") % "")))))))))) Source #
type family InsertDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ... Source #
InsertDimCheckF by dims dim 'Nothing = TypeError (InsertDimErrorMessage by dims dim) | |
InsertDimCheckF _ _ _ ('Just dims) = dims |
type family InsertDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) (dim :: Dim (Name Symbol) (Size Nat)) :: Shape [Dim (Name Symbol) (Size Nat)] where ... Source #
InsertDimF 'UncheckedSelectDim _ _ = 'UncheckedShape | |
InsertDimF _ 'UncheckedShape _ = 'UncheckedShape | |
InsertDimF ('SelectDim by) ('Shape dims) dim = 'Shape (InsertDimCheckF by dims dim (InsertDimImplF by dims dim)) |
type family PrependDimF (dim :: Dim (Name Symbol) (Size Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Shape [Dim (Name Symbol) (Size Nat)] where ... Source #
PrependDimF dim shape = InsertDimF ('SelectDim ('ByIndex 0)) shape dim |
type family RemoveDimByIndexF (index :: Maybe Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
RemoveDimByIndexF ('Just 0) (dim ': dims) = 'Just dims | |
RemoveDimByIndexF ('Just index) (h ': t) = PrependMaybe ('Just h) (RemoveDimByIndexF ('Just (index - 1)) t) | |
RemoveDimByIndexF _ _ = 'Nothing |
type family RemoveDimImplF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) :: Maybe [Dim (Name Symbol) (Size Nat)] where ... Source #
RemoveDimImplF ('ByName name) dims = RemoveDimByIndexF (GetIndexByNameF name dims) dims | |
RemoveDimImplF ('ByIndex index) dims = RemoveDimByIndexF ('Just index) dims |
type RemoveDimErrorMessage (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) = "Cannot remove the dimension by" % ("" % (((" '" <> by) <> "'") % ("" % ("in the shape" % ("" % (((" '" <> dims) <> "'.") % "")))))) Source #
type family RemoveDimCheckF (by :: By Symbol Nat) (dims :: [Dim (Name Symbol) (Size Nat)]) (result :: Maybe [Dim (Name Symbol) (Size Nat)]) :: [Dim (Name Symbol) (Size Nat)] where ... Source #
RemoveDimCheckF by dims 'Nothing = TypeError (RemoveDimErrorMessage by dims) | |
RemoveDimCheckF _ _ ('Just dims) = dims |
type family RemoveDimF (selectDim :: SelectDim (By Symbol Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) :: Shape [Dim (Name Symbol) (Size Nat)] where ... Source #
RemoveDimF 'UncheckedSelectDim _ = 'UncheckedShape | |
RemoveDimF _ 'UncheckedShape = 'UncheckedShape | |
RemoveDimF ('SelectDim by) ('Shape dims) = 'Shape (RemoveDimCheckF by dims (RemoveDimImplF by dims)) |
data UnifyNameError Source #
Instances
Exception UnifyNameError Source # | |
Defined in Torch.GraduallyTyped.Shape.Class | |
Show UnifyNameError Source # | |
Defined in Torch.GraduallyTyped.Shape.Class |
sUnifyName :: forall m name name'. MonadThrow m => SName name -> SName name' -> m (SName (name <+> name')) Source #
data UnifySizeError Source #
Instances
Exception UnifySizeError Source # | |
Defined in Torch.GraduallyTyped.Shape.Class | |
Show UnifySizeError Source # | |
Defined in Torch.GraduallyTyped.Shape.Class |
sUnifySize :: forall m size size'. MonadThrow m => SSize size -> SSize size' -> m (SSize (size <+> size')) Source #
sUnifyDim :: forall m dim dim'. MonadThrow m => SDim dim -> SDim dim' -> m (SDim (dim <+> dim')) Source #
Unify two dimensions.
>>>
dimA = SName @"*" :&: SSize @0
>>>
dimB = SName @"batch" :&: SSize @0
>>>
dim = sUnifyDim dimA dimB
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim ('Name "batch") ('Size 0)))>>>
fromSing <$> dim
Dim {dimName = Checked "batch", dimSize = Checked 0}
>>>
dimC = SName @"feature" :&: SSize @0
>>>
:type sUnifyDim dimB dimC
sUnifyDim dimB dimC :: MonadThrow m => m (SDim ('Dim (TypeError ...) ('Size 0)))
>>>
dimD = SUncheckedName "batch" :&: SSize @0
>>>
dim = sUnifyDim dimA dimD
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim 'UncheckedName ('Size 0)))>>>
fromSing <$> dim
Dim {dimName = Unchecked "batch", dimSize = Checked 0}
>>>
dimE = SUncheckedName "feature" :&: SSize @0
>>>
dim = sUnifyDim dimB dimE
>>>
:type dim
dim :: MonadThrow m => m (SDim ('Dim 'UncheckedName ('Size 0)))>>>
fromSing <$> dim
*** Exception: UnifyNameError {uneExpect = "batch", uneActual = "feature"}