hasktorch-gradually-typed-0.2.0.0: experimental project for hasktorch
Safe HaskellSafe-Inferred
LanguageHaskell2010

Torch.GraduallyTyped.Tensor.Type

Synopsis

Documentation

>>> import Torch.GraduallyTyped.Prelude.List (SList (..))
>>> import Torch.GraduallyTyped

newtype Tensor (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where Source #

A gradually typed tensor.

                         ┌─► Compute device, e.g. `'Device CPU
                         │
                         │               ┌─► List of dimensions, e.g. `'Shape '[ 'Dim 'UncheckedName ('Size 8), 'Dim 'UncheckedName ('Size 1) ]`
                         │               │
Tensor gradient layout device dataType shape
          │       │              │
          │       │              └─► Data type, e.g. `'DataType DType
          │       │
          │       └─► Memory layout, e.g. `'Layout Dense
          │
          └─► Whether or not the tensor requires a gradient, e.g. `'Gradient WithGradient for one that does

Constructors

UnsafeTensor :: forall gradient layout device dataType shape. ForeignPtr Tensor -> Tensor gradient layout device dataType shape

Unsafe constructor for tensors. Do not call this constructor directly, use smart constructors like ones or randn instead.

Instances

Instances details
Castable (CatListF selectDim (Tensor gradient layout device dataType shape)) (ForeignPtr Tensor) => HasCat selectDim Type [] (Tensor gradient layout device dataType shape :: TYPE LiftedRep) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.IndexingSlicingJoining

Associated Types

type CatF selectDim (Tensor gradient layout device dataType shape) [] Source #

Methods

sCat :: MonadThrow m => SSelectDim selectDim -> [Tensor gradient layout device dataType shape] -> m (CatF selectDim (Tensor gradient layout device dataType shape) []) Source #

cat :: (SingI selectDim, MonadThrow m) => [Tensor gradient layout device dataType shape] -> m (CatF selectDim (Tensor gradient layout device dataType shape) []) Source #

(Catch (predShape <+> targetShape), output ~ Tensor (predGradient <|> targetGradient) (predLayout <+> targetLayout) (predDevice <+> targetDevice) (predDataType <+> targetDataType) ('Shape ('[] :: [Dim (Name Symbol) (Size Nat)]))) => HasForward MSELoss (Tensor predGradient predLayout predDevice predDataType predShape, Tensor targetGradient targetLayout targetDevice targetDataType targetShape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Loss

Methods

forward :: MonadThrow m => MSELoss -> (Tensor predGradient predLayout predDevice predDataType predShape, Tensor targetGradient targetLayout targetDevice targetDataType targetShape) -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

MkTransformerPaddingMaskC layout device dataType shape output => HasForward MkTransformerPaddingMask (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.Type

Methods

forward :: MonadThrow m => MkTransformerPaddingMask -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

HasForward Gelu (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Activation

Methods

forward :: MonadThrow m => Gelu -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (Tensor requiresGradient layout device dataType shape, Generator generator) Source #

HasForward GeluNew (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Activation

Methods

forward :: MonadThrow m => GeluNew -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (Tensor requiresGradient layout device dataType shape, Generator generator) Source #

HasForward Relu (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Activation

Methods

forward :: MonadThrow m => Relu -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (Tensor requiresGradient layout device dataType shape, Generator generator) Source #

HasForward Tanh (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Activation

Methods

forward :: MonadThrow m => Tanh -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (Tensor requiresGradient layout device dataType shape, Generator generator) Source #

MkPosC device shape seqDim seqName seqSize output => HasForward MkAbsPos (Tensor gradient layout device dataType shape) generatorDevice (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") seqSize])) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.Type

Methods

forward :: MonadThrow m => MkAbsPos -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") seqSize]), Generator generatorDevice) Source #

HasInitialize (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

initialize :: MonadThrow m => ModelSpec (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) -> Generator generatorDevice -> m (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)), Generator generatorDevice) Source #

HasInitialize (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) generatorDevice (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

initialize :: MonadThrow m => ModelSpec (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) -> Generator generatorDevice -> m (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape), Generator generatorDevice) Source #

Castable [Tensor gradient layout device dataType shape] (ForeignPtr TensorList) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

cast :: [Tensor gradient layout device dataType shape] -> (ForeignPtr TensorList -> IO r) -> IO r Source #

uncast :: ForeignPtr TensorList -> ([Tensor gradient layout device dataType shape] -> IO r) -> IO r Source #

MkTransformerCrossAttentionMaskC dataType decoderInputShape decoderInputSeqDim inputPaddingMaskGradient inputPaddingMaskLayout inputPaddingMaskDevice inputPaddingMaksDataType inputPaddingMaskShape seqDim output => HasForward (MkTransformerCrossAttentionMask dataType) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor inputPaddingMaskGradient inputPaddingMaskLayout inputPaddingMaskDevice inputPaddingMaksDataType inputPaddingMaskShape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.Type

Methods

forward :: MonadThrow m => MkTransformerCrossAttentionMask dataType -> (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor inputPaddingMaskGradient inputPaddingMaskLayout inputPaddingMaskDevice inputPaddingMaksDataType inputPaddingMaskShape) -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(shape' ~ SoftmaxF selectDim shape, Catch shape', output ~ Tensor requiresGradient layout device dataType shape') => HasForward (LogSoftmax selectDim) (Tensor requiresGradient layout device dataType shape) generator output generator Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Activation

Methods

forward :: MonadThrow m => LogSoftmax selectDim -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (output, Generator generator) Source #

(shape' ~ SoftmaxF selectDim shape, Catch shape', output ~ Tensor requiresGradient layout device dataType shape') => HasForward (Softmax selectDim) (Tensor requiresGradient layout device dataType shape) generator output generator Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Activation

Methods

forward :: MonadThrow m => Softmax selectDim -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (output, Generator generator) Source #

(shape' ~ BroadcastShapesF shape biasShape, Catch shape', output ~ Tensor (gradient <|> biasGradient) (layout <+> biasLayout) (device <+> biasDevice) (dataType <+> biasDataType) shape') => HasForward (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(shape' ~ BroadcastShapesF shape biasShape, Catch shape', output ~ Tensor (gradient <|> biasGradient) (layout <+> biasLayout) (device <+> biasDevice) (dataType <+> biasDataType) shape') => HasForward (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape) -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

MkTransformerAttentionMaskC dataType inputGradient inputLayout inputDevice inputDataType inputShape seqDim output => HasForward (MkTransformerAttentionMask dataType) (Tensor inputGradient inputLayout inputDevice inputDataType inputShape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.Type

Methods

forward :: MonadThrow m => MkTransformerAttentionMask dataType -> Tensor inputGradient inputLayout inputDevice inputDataType inputShape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

MkTransformerDecoderAttentionMaskC dataType decoderInputLayout decoderInputDevice decoderInputShape seqDim output => HasForward (MkTransformerDecoderAttentionMask dataType) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape) generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.Type

Methods

forward :: MonadThrow m => MkTransformerDecoderAttentionMask dataType -> Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

HasForward (GBias ()) (Tensor gradient layout device dataType shape) generatorDevice (Tensor gradient layout device dataType shape) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GBias () -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (Tensor gradient layout device dataType shape, Generator generatorDevice) Source #

MkRelPosC device shape seqDim seqName seqSize output => HasForward (MkRelPos relPosEncBucketDim) (Tensor gradient layout device dataType shape) generatorDevice (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") ('Size 1), 'Dim ('Name "*") seqSize, 'Dim ('Name "*") seqSize])) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.Type

Methods

forward :: MonadThrow m => MkRelPos relPosEncBucketDim -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") ('Size 1), 'Dim ('Name "*") seqSize, 'Dim ('Name "*") seqSize]), Generator generatorDevice) Source #

(output ~ GLinear (Tensor gradient ('Layout 'Dense) (device <+> generatorDevice) dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) (device <+> generatorDevice) dataType ('Shape '[outputDim])), generatorOutputDevice ~ (device <+> generatorDevice), SGetGeneratorDevice generatorDevice, SGetGeneratorDevice generatorOutputDevice) => HasInitialize (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim]))) generatorDevice output generatorOutputDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Linear

Methods

initialize :: MonadThrow m => ModelSpec (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim]))) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(output ~ GLinear (Tensor gradient ('Layout 'Dense) (device <+> generatorDevice) dataType ('Shape '[outputDim, inputDim])) (), generatorOutputDevice ~ (device <+> generatorDevice), SGetGeneratorDevice generatorDevice) => HasInitialize (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) ()) generatorDevice output generatorOutputDevice Source #

TODO: Add ForNonLinearity as parameter.

Instance details

Defined in Torch.GraduallyTyped.NN.Linear

Methods

initialize :: MonadThrow m => ModelSpec (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) ()) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

Castable (HList tensors) [ForeignPtr Tensor] => Castable (HList (Tensor gradient layout device dataType shape ': tensors)) [ForeignPtr Tensor] Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

cast :: HList (Tensor gradient layout device dataType shape ': tensors) -> ([ForeignPtr Tensor0] -> IO r) -> IO r Source #

uncast :: [ForeignPtr Tensor0] -> (HList (Tensor gradient layout device dataType shape ': tensors) -> IO r) -> IO r Source #

output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LinearWithBiasF ('Shape '[outputDim, inputDim]) ('Shape '[outputDim]) shape') => HasForward (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim]))) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Linear

Methods

forward :: MonadThrow m => GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim])) -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LinearWithoutBiasF ('Shape '[outputDim, inputDim]) shape') => HasForward (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) ()) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Linear

Methods

forward :: MonadThrow m => GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) () -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(HasForward dense (Tensor gradient layout device dataType shape) generatorDevice tensor0 generatorDevice0, HasForward activation tensor0 generatorDevice0 output generatorOutputDevice) => HasForward (GPooler dense activation) (Tensor gradient layout device dataType shape) generatorDevice output generatorOutputDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GPooler

Methods

forward :: MonadThrow m => GPooler dense activation -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward layer0 (Tensor gradient layout device dataType shape) generatorDevice (Tensor gradient' layout' device' dataType' shape') generatorDevice', HasForward activation (Tensor gradient' layout' device' dataType' shape') generatorDevice' (Tensor gradient' layout' device' dataType' shape') generatorDevice', HasForward layer1 (Tensor gradient layout device dataType shape) generatorDevice' (Tensor gradient' layout' device' dataType' shape') generatorDevice'', output ~ Tensor gradient' layout' device' dataType' shape', generatorOutputDevice ~ generatorDevice'') => HasForward (GGate layer0 activation layer1) (Tensor gradient layout device dataType shape) generatorDevice output generatorOutputDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GFeedForwardNetwork

Methods

forward :: MonadThrow m => GGate layer0 activation layer1 -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward initialLayerNorm (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice tensor0 generatorDevice0, HasForward multiHeadAttention (tensor0, tensor0, tensor0, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice0 tensor1 generatorDevice1, HasForward dropout tensor1 generatorDevice1 (Tensor gradient2 layout2 device2 dataType2 shape2) generatorDevice2, HasForward finalLayerNorm (Tensor (queryGradient <|> gradient2) (queryLayout <+> layout2) (queryDevice <+> device2) (queryDataType <+> dataType2) (BroadcastShapesF queryShape shape2)) generatorDevice2 output generatorOutputDevice, Catch (BroadcastShapesF queryShape shape2)) => HasForward (GSelfAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GSelfAttention.

┌───────────────┐     ┌───────┐
│ attentionBias │     │ query │
└───────┬───────┘     └───┬───┘
        │                 │
        │           ┌─────┴─────┐
        │           │           │
        │           ▼           │
        │  (saInitialLayerNorm) │
        │           │           │
        │      ┌────┼────┐      │
        │      │    │    │      │
        │      ▼    ▼    ▼      │
        └─►saMultiHeadAttention │
                    │           │
                    ▼           │
                saDropout       │
                    │           │
                    └───►add◄───┘
                          │
                          ▼
                  (saFinalLayerNorm)
                          │
                          ▼
                      ┌───────┐
                      │ query │
                      └───────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GSelfAttention

Methods

forward :: MonadThrow m => GSelfAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm -> (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward initialLayerNorm (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice tensor0 generatorDevice0, HasForward multiHeadAttention (tensor0, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice0 tensor1 generatorDevice1, HasForward dropout tensor1 generatorDevice1 (Tensor gradient2 layout2 device2 dataType2 shape2) generatorDevice2, HasForward finalLayerNorm (Tensor (queryGradient <|> gradient2) (queryLayout <+> layout2) (queryDevice <+> device2) (queryDataType <+> dataType2) (BroadcastShapesF queryShape shape2)) generatorDevice2 output generatorOutputDevice, Catch (BroadcastShapesF queryShape shape2)) => HasForward (GCrossAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GCrossAttention.

       ┌───────┐    ┌─────┐    ┌───────────────┐
       │ query │    │ key │    │ attentionBias │
       └───┬───┘    └──┬──┘    └───────┬───────┘
           │           │               │
┌──────────┤           │               │
│          │           │               │
│          ▼           │               │
│ (caInitialLayerNorm) │               │
│          │           │               │
│          │       ┌───┴───┐           │
│          │       │       │           │
│          ▼       ▼       ▼           │
│        caMultiheadAttention◄─────────┘
│                  │
│                  ▼
│              caDropout
│                  │
└──────►add◄───────┘
         │
         ▼
 (caFinalLayerNorm)
         │
         ▼
     ┌───────┐
     │ query │
     └───────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GCrossAttention

Methods

forward :: MonadThrow m => GCrossAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm -> (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

Num (Tensor gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

(+) :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

(-) :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

(*) :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

negate :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

abs :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

signum :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

fromInteger :: Integer -> Tensor gradient layout device dataType shape Source #

Show (Tensor gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

showsPrec :: Int -> Tensor gradient layout device dataType shape -> ShowS Source #

show :: Tensor gradient layout device dataType shape -> String Source #

showList :: [Tensor gradient layout device dataType shape] -> ShowS Source #

HasGrad (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Autograd

Associated Types

type Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source #

type Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source #

Methods

grad :: Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) -> Tensor ('Gradient 'WithGradient) layout device dataType shape -> Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source #

HasStateDict (Tensor gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Class

Methods

fromStateDict :: (MonadIO m, MonadThrow m, MonadState StateDict m) => ModelSpec (Tensor gradient layout device dataType shape) -> StateDictKey -> m (Tensor gradient layout device dataType shape) Source #

toStateDict :: (MonadThrow m, MonadState StateDict m) => StateDictKey -> Tensor gradient layout device dataType shape -> m () Source #

Castable (Tensor gradient layout device dataType shape) (ForeignPtr Tensor) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

cast :: Tensor gradient layout device dataType shape -> (ForeignPtr Tensor0 -> IO r) -> IO r Source #

uncast :: ForeignPtr Tensor0 -> (Tensor gradient layout device dataType shape -> IO r) -> IO r Source #

(SGetShape normalizedShape, output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LayerNormWithBiasF normalizedShape normalizedShape shape')) => HasForward (LayerNorm 'WithBias gradient device dataType normalizedShape) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Normalization

Methods

forward :: MonadThrow m => LayerNorm 'WithBias gradient device dataType normalizedShape -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(SGetShape normalizedShape, SGetShape shape', output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LayerNormWithoutBiasF normalizedShape shape')) => HasForward (LayerNorm 'WithoutBias gradient device dataType normalizedShape) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Normalization

Methods

forward :: MonadThrow m => LayerNorm 'WithoutBias gradient device dataType normalizedShape -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(HasForward dense (Tensor gradient layout device dataType shape) generatorDevice tensor0 generatorDevice0, HasForward activation tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward layerNorm tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward decoder tensor2 generatorDevice2 (Tensor gradient3 layout3 device3 dataType3 shape3) generatorDevice3, HasForward bias (Tensor gradient3 layout3 device3 dataType3 shape3) generatorDevice3 output generatorOutputDevice) => HasForward (GLMHead inputEmbedDim dense activation layerNorm decoder bias) (Tensor gradient layout device dataType shape) generatorDevice output generatorOutputDevice Source #

HasForward instance for LMHead.

    ┌───────┐
    │ input │
    └───┬───┘
        │
        ▼
  (lmHeadDense)
        ▼
(lmHeadActivation)
        ▼
(lmHeadLayerNorm)
        ▼
  lmHeadDecoder
        ▼
    (scaling)
        ▼
   (lmHeadBias)
        │
        ▼
┌───────────────┐
│ decoderOutput │
└───────────────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GLMHead inputEmbedDim dense activation layerNorm decoder bias -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerInput input decoderInput) generatorDevice (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask) generatorOutputDevice, decoderInput ~ Tensor targetGradient targetLayout targetDevice targetDataType (IndexDims ('Indices '['SliceAll :: IndexType (Index Natural), 'SliceUpTo ('NegativeIndex 1)]) targetShape), decoderOutput ~ Tensor doGradient doLayout doDevice doDataType doShape, logProbsShape ~ SoftmaxF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) doShape, Catch logProbsShape, unsqueezedTargetShape ~ UnsqueezeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) targetShape, Catch unsqueezedTargetShape, gatheredLogProbsShape ~ GatherDimF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) unsqueezedTargetShape logProbsShape, Catch gatheredLogProbsShape, Catch (targetDataType <+> 'DataType 'Int64), logLikelihoodShape ~ SqueezeDimF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) gatheredLogProbsShape, Catch logLikelihoodShape, MeanAllCheckF logLikelihoodShape, loss ~ Tensor (targetGradient <|> doGradient) (targetLayout <+> doLayout) (targetDevice <+> doDevice) doDataType ('Shape ('[] :: [Dim (Name Symbol) (Size Nat)])), generatorOutputDevice ~ generatorDevice) => HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerTrainingInput input (Tensor targetGradient targetLayout targetDevice targetDataType targetShape)) generatorDevice (SimplifiedEncoderDecoderTransformerTrainingOutput loss) generatorOutputDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder

Methods

forward :: MonadThrow m => GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask -> SimplifiedEncoderDecoderTransformerTrainingInput input (Tensor targetGradient targetLayout targetDevice targetDataType targetShape) -> Generator generatorDevice -> m (SimplifiedEncoderDecoderTransformerTrainingOutput loss, Generator generatorOutputDevice) Source #

(HasForward initialLayerNorm (Tensor inputGradient inputLayout inputDevice inputDataType inputShape) generatorDevice tensor0 generatorDevice0, HasForward initialDropout tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward relPosEnc (Tensor relPosGradient relPosLayout relPosDevice relPosDataType relPosShape) generatorDevice1 (Tensor relPosEncGradient relPosEncLayout relPosEncDevice relPosEncDataType relPosEncShape) generatorDevice2, HasForward stack (tensor1, Tensor (relPosEncGradient <|> attentionMaskGradient) (relPosEncLayout <+> attentionMaskLayout) (relPosEncDevice <+> attentionMaskDevice) (relPosEncDataType <+> attentionMaskDataType) (BroadcastShapesF doubleTransposedRelPosEncShape unsqueezedAttentionMaskShape)) generatorDevice2 tensor3 generatorDevice3, transposedRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) ('SelectDim ('ByIndex 3 :: By Symbol Natural)) relPosEncShape, Catch transposedRelPosEncShape, doubleTransposedRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) transposedRelPosEncShape, Catch doubleTransposedRelPosEncShape, unsqueezedAttentionMaskShape ~ UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) attentionMaskShape, Catch unsqueezedAttentionMaskShape, Catch (BroadcastShapesF doubleTransposedRelPosEncShape unsqueezedAttentionMaskShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor relPosGradient relPosLayout relPosDevice relPosDataType relPosShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GTransformer in an encoder configuration with relative positional encoding rather than absolute positional encoding.

     ┌───────┐  ┌────────┐  ┌───────────────┐
     │ input │  │ relPos │  │ attentionMask │
     └───┬───┘  └───┬────┘  └───────┬───────┘
         │          │               │
         │          ▼               │
         │     tRelPosEnc           │
         │          ▼               │
         │      transpose           │
         │          ▼               ▼
         │      transpose       unsqueeze
         ▼          │               │
(tInitialLayerNorm) │               │
         ▼          └─────►add◄─────┘
 (tInitialDropout)          │
         ▼                  │
      tStack◄───────────────┘
         ▼
 (tFinalLayerNorm)
         ▼
  (tFinalDropout)
         │
         ▼
    ┌────────┐
    │ output │
    └────────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer

Methods

forward :: MonadThrow m => GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor relPosGradient relPosLayout relPosDevice relPosDataType relPosShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward posEnc (Tensor posGradient posLayout posDevice posDataType posShape) generatorDevice (Tensor posEncGradient posEncLayout posEncDevice posEncDataType posEncShape) generatorDevice0, HasForward initialLayerNorm (Tensor (inputGradient <|> posEncGradient) (inputLayout <+> posEncLayout) (inputDevice <+> posEncDevice) (inputDataType <+> posEncDataType) (BroadcastShapesF inputShape posEncShape)) generatorDevice0 tensor1 generatorDevice1, Catch (BroadcastShapesF inputShape posEncShape), HasForward initialDropout tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward stack (tensor2, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) attentionMaskShape)) generatorDevice2 tensor3 generatorDevice3, Catch (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) attentionMaskShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor posGradient posLayout posDevice posDataType posShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GTransformer in an encoder configuration with absolute positional encoding rather than relative positional encoding.

┌───────┐  ┌─────┐  ┌───────────────┐
│ input │  │ pos │  │ attentionMask │
└───┬───┘  └─────┘  └───────┬───────┘
    │         │             │
    │         ▼             │
    │      tPosEnc          │
    │         │             │
    └──►add◄──┘             │
         │                  │
         ▼                  │
(tInitialLayerNorm)         │
         ▼                  ▼
 (tInitialDropout)     unsqueeze
         ▼                  │
      tStack◄───────────────┘
         ▼
 (tFinalLayerNorm)
         ▼
  (tFinalDropout)
         │
         ▼
    ┌────────┐
    │ output │
    └────────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer

Methods

forward :: MonadThrow m => GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor posGradient posLayout posDevice posDataType posShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(SGetLayout layout, KnownNat paddingIdx, Catch (dataType' <+> 'DataType 'Int64), output ~ Tensor (gradient <|> gradient') (layout <+> layout') (device <+> device') dataType (EmbeddingF ('Shape '[embedNumDim, embedDim]) shape')) => HasForward (Embedding gradient layout device dataType embedNumDim embedDim ('Just paddingIdx)) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Sparse

Methods

forward :: MonadThrow m => Embedding gradient layout device dataType embedNumDim embedDim ('Just paddingIdx) -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(SGetLayout layout, Catch (dataType' <+> 'DataType 'Int64), output ~ Tensor (gradient <|> gradient') (layout <+> layout') (device <+> device') dataType (EmbeddingF ('Shape '[embedNumDim, embedDim]) shape')) => HasForward (Embedding gradient layout device dataType embedNumDim embedDim ('Nothing :: Maybe Nat)) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Sparse

Methods

forward :: MonadThrow m => Embedding gradient layout device dataType embedNumDim embedDim 'Nothing -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

(HasForward inputLayerNorm (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice tensor0 generatorDevice0, HasForward inputTransformation tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward activation tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward activationDropout tensor2 generatorDevice2 tensor3 generatorDevice3, HasForward outputProjection tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward outputDropout tensor4 generatorDevice4 (Tensor queryGradient5 queryLayout5 queryDevice5 queryDataType5 queryShape5) generatorDevice5, HasForward outputLayerNorm (Tensor (queryGradient <|> queryGradient5) (queryLayout <+> queryLayout5) (queryDevice <+> queryDevice5) (queryDataType <+> queryDataType5) (BroadcastShapesF queryShape queryShape5)) generatorDevice5 output generatorOutputDevice, Catch (BroadcastShapesF queryShape queryShape5)) => HasForward (GTransformerFeedForwardNetwork inputLayerNorm inputTransformation activation activationDropout outputProjection outputDropout outputLayerNorm) (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GTransformerFeedForwardNetwork.

      ┌───────┐
      │ query ├────────┐
      └───┬───┘        │
          │            │
          ▼            │
 (ffnInputLayerNorm)   │
          ▼            │
ffnInputTransformation │
          ▼            │
    ffnActivation      │
          ▼            │
(ffnActivationDropout) │
          ▼            │
  ffnOutputProjecton   │
          ▼            │
   ffnOutputDropout    │
          │            │
          ▼            │
         add◄──────────┘
          │
          ▼
 (ffnOutputLayerNorm)
          │
          ▼
      ┌───────┐
      │ query │
      └───────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GFeedForwardNetwork

Methods

forward :: MonadThrow m => GTransformerFeedForwardNetwork inputLayerNorm inputTransformation activation activationDropout outputProjection outputDropout outputLayerNorm -> Tensor queryGradient queryLayout queryDevice queryDataType queryShape -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward initialLayerNorm (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape) generatorDevice tensor0 generatorDevice0, HasForward initialDropout tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward relPosEnc (Tensor decoderRelPosGradient decoderRelPosLayout decoderRelPosDevice decoderRelPosDataType decoderRelPosShape) generatorDevice1 (Tensor decoderRelPosEncGradient decoderRelPosEncLayout decoderRelPosEncDevice decoderRelPosEncDataType decoderRelPosEncShape) generatorDevice2, HasForward stack (tensor1, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor (decoderRelPosEncGradient <|> decoderAttentionMaskGradient) (decoderRelPosEncLayout <+> decoderAttentionMaskLayout) (decoderRelPosEncDevice <+> decoderAttentionMaskDevice) (decoderRelPosEncDataType <+> decoderAttentionMaskDataType) (BroadcastShapesF doubleTransposedDecoderRelPosEncShape unsqueezedDecoderAttentionMaskShape), Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType unsqueezedCrossAttentionMaskShape) generatorDevice2 tensor3 generatorDevice3, transposedDecoderRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) ('SelectDim ('ByIndex 3 :: By Symbol Natural)) decoderRelPosEncShape, Catch transposedDecoderRelPosEncShape, doubleTransposedDecoderRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) transposedDecoderRelPosEncShape, Catch doubleTransposedDecoderRelPosEncShape, unsqueezedDecoderAttentionMaskShape ~ UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) decoderAttentionMaskShape, Catch unsqueezedDecoderAttentionMaskShape, unsqueezedCrossAttentionMaskShape ~ UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) crossAttentionMaskShape, Catch unsqueezedCrossAttentionMaskShape, Catch (BroadcastShapesF doubleTransposedDecoderRelPosEncShape unsqueezedDecoderAttentionMaskShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderRelPosGradient decoderRelPosLayout decoderRelPosDevice decoderRelPosDataType decoderRelPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GTransformer in a decoder configuration with relative positional encoding rather than absolute positional encoding.

  ┌──────────────┐  ┌───────────────┐  ┌───────────────┐  ┌──────────────────────┐  ┌────────────────────┐
  │ decoderInput │  │ encoderOutput │  │ decoderRelPos │  │ decoderAttentionMask │  │ crossAttentionMask │
  └──────┬───────┘  └───────┬───────┘  └───────┬───────┘  └──────────┬───────────┘  └─────────┬──────────┘
         │                  │                  │                     │                        │
         │                  │                  ▼                     │                        │
         │                  │             tdRelPosEnc                │                        │
         │                  │                  ▼                     │                        │
         │                  │              transpose                 │                        │
         │                  │                  ▼                     ▼                        ▼
         │                  │              transpose             unsqueeze                unsqueeze
         ▼                  │                  │                     │                        │
(tInitialLayerNorm)         │                  │                     │                        │
         ▼                  │                  └────────►add◄────────┘                        │
 (tInitialDropout)          │                             │                                   │
         ▼                  │                             │                                   │
      tStack◄───────────────┘◄────────────────────────────┘◄──────────────────────────────────┘
         ▼
 (tFinalLayerNorm)
         ▼
  (tFinalDropout)
         │
         ▼
    ┌────────┐
    │ output │
    └────────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer

Methods

forward :: MonadThrow m => GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderRelPosGradient decoderRelPosLayout decoderRelPosDevice decoderRelPosDataType decoderRelPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward posEnc (Tensor decoderPosGradient decoderPosLayout decoderPosDevice decoderPosDataType decoderPosShape) generatorDevice (Tensor decoderPosEncGradient decoderPosEncLayout decoderPosEncDevice decoderPosEncDataType decoderPosEncShape) generatorDevice0, HasForward initialLayerNorm (Tensor (decoderInputGradient <|> decoderPosEncGradient) (decoderInputLayout <+> decoderPosEncLayout) (decoderInputDevice <+> decoderPosEncDevice) (decoderInputDataType <+> decoderPosEncDataType) (BroadcastShapesF decoderInputShape decoderPosEncShape)) generatorDevice0 tensor1 generatorDevice1, HasForward initialDropout tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward stack (tensor2, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) decoderAttentionMaskShape), Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) crossAttentionMaskShape)) generatorDevice2 tensor3 generatorDevice3, Catch (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) decoderAttentionMaskShape), Catch (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) crossAttentionMaskShape), Catch (BroadcastShapesF decoderInputShape decoderPosEncShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderPosGradient decoderPosLayout decoderPosDevice decoderPosDataType decoderPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GTransformer in a decoder configuration with absolute positional encoding rather than relative positional encoding.

┌──────────────┐  ┌────────────┐  ┌───────────────┐  ┌──────────────────────┐  ┌────────────────────┐
│ decoderInput │  │ decoderPos │  │ encoderOutput │  │ decoderAttentionMask │  │ crossAttentionMask │
└──────┬───────┘  └──────┬─────┘  └───────┬───────┘  └──────────┬───────────┘  └──────────┬─────────┘
       │                 │                │                     │                         │
       │                 ▼                │                     │                         │
       │             tdPosEnc             │                     │                         │
       │                 │                │                     │                         │
       └──────►add◄──────┘                │                     │                         │
                │                         │                     │                         │
                ▼                         │                     │                         │
       (tInitialLayerNorm)                │                     │                         │
                ▼                         │                     ▼                         ▼
        (tInitialDropout)                 │                 unsqueeze                 unsqueeze
                ▼                         │                     │                         │
             tStack◄──────────────────────┘◄────────────────────┘◄────────────────────────┘
                ▼
        (tFinalLayerNorm)
                ▼
         (tFinalDropout)
                │
                ▼
           ┌────────┐
           │ output │
           └────────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer

Methods

forward :: MonadThrow m => GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderPosGradient decoderPosLayout decoderPosDevice decoderPosDataType decoderPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

(HasForward qInProj (Tensor queryRequiresGradient queryLayout queryDevice queryDataType queryShape) generatorDevice (Tensor qRequiresGradient qLayout qDevice qDataType qShape0) qGeneratorOutputDevice, reshapedQShape0 ~ ReshapeF qShape0 ('Shape '[batchDim, querySeqDim, headDim, headEmbedDim]), Catch reshapedQShape0, qShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) reshapedQShape0, Catch qShape, HasForward kInProj (Tensor keyRequiresGradient keyLayout keyDevice keyDataType keyShape) qGeneratorOutputDevice (Tensor qRequiresGradient kLayout kDevice kDataType kShape0) kGeneratorOutputDevice, reshapedKShape0 ~ ReshapeF kShape0 ('Shape '[batchDim, keySeqDim, headDim, headEmbedDim]), Catch reshapedKShape0, transposedReshapedKShape0 ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) reshapedKShape0, Catch transposedReshapedKShape0, doubleTransposedReshapedKShape0 ~ TransposeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) ('SelectDim ('ByIndex 3 :: By Symbol Natural)) transposedReshapedKShape0, Catch doubleTransposedReshapedKShape0, multipliedQDoubleTransposedReshapedKShape0 ~ MatmulF qShape doubleTransposedReshapedKShape0, Catch multipliedQDoubleTransposedReshapedKShape0, weightsShape0 ~ SoftmaxF ('SelectDim ('ByIndex 3 :: By Symbol Natural)) (BroadcastShapesF multipliedQDoubleTransposedReshapedKShape0 attentionBiasShape), Catch (BroadcastShapesF multipliedQDoubleTransposedReshapedKShape0 attentionBiasShape), Catch weightsShape0, HasForward dropout (Tensor (qRequiresGradient <|> attentionBiasRequiresGradient) (qLayout <+> (kLayout <+> attentionBiasLayout)) (qDevice <+> (kDevice <+> attentionBiasDevice)) (qDataType <+> (kDataType <+> attentionBiasDataType)) weightsShape0) kGeneratorOutputDevice (Tensor weightsRequiresGradient weightsLayout weightsDevice weightsDataType weightsShape) weightsGeneratorOutputDevice, HasForward vInProj (Tensor valueRequiresGradient valueLayout valueDevice valueDataType valueShape) weightsGeneratorOutputDevice (Tensor weightsRequiresGradient vLayout vDevice vDataType vShape0) vGeneratorOutputDevice, reshapedVShape0 ~ ReshapeF vShape0 ('Shape '[batchDim, keySeqDim, headDim, headEmbedDim]), Catch reshapedVShape0, transposedReshapedVShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) reshapedVShape0, Catch transposedReshapedVShape, multipliedWeightsTransposedReshapedVShape ~ MatmulF weightsShape transposedReshapedVShape, Catch multipliedWeightsTransposedReshapedVShape, outputQueryShape0 ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) multipliedWeightsTransposedReshapedVShape, Catch outputQueryShape0, HasForward outProj (Tensor weightsRequiresGradient (weightsLayout <+> vLayout) (weightsDevice <+> vDevice) (weightsDataType <+> vDataType) reshapedOutputQueryShape0) vGeneratorOutputDevice output generatorOutputDevice, reshapedOutputQueryShape0 ~ ReshapeF outputQueryShape0 ('Shape '[batchDim, querySeqDim, embedDim]), Catch reshapedOutputQueryShape0, SGetShape queryShape, SGetShape keyShape, SGetShape valueShape, batchDim ~ BatchDim queryShape keyShape valueShape, querySeqDim ~ QuerySeqDim queryShape, keySeqDim ~ KeySeqDim keyShape valueShape) => HasForward (GMultiHeadAttention headDim headEmbedDim embedDim qInProj kInProj vInProj outProj dropout) (Tensor queryRequiresGradient queryLayout queryDevice queryDataType queryShape, Tensor keyRequiresGradient keyLayout keyDevice keyDataType keyShape, Tensor valueRequiresGradient valueLayout valueDevice valueDataType valueShape, Tensor attentionBiasRequiresGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice output generatorOutputDevice Source #

HasForward instance for GMultiHeadAttention.

┌───────────────┐        ┌───────┐       ┌─────┐       ┌───────┐
│ attentionBias │        │ query │       │ key │       │ value │
└───────┬───────┘        └───┬───┘       └──┬──┘       └───┬───┘
        │                    │              │              │
        │                    ▼              ▼              ▼
        │                mhaQInProj     mhaKInProj     mhaVInProj
        │                    ▼              │              │
        │                (scaling)          │              │
        │                    ▼              ▼              ▼
        │                 reshape        reshape        reshape
        │                    ▼              ▼              ▼
        │                transpose      transpose      transpose
        │                    │              ▼              │
        │                    │          transpose          │
        │                    │              │              │
        │                    └───►matmul◄───┘              │
        │                           ▼                      │
        │                       (scaling)                  │
        │                           │                      │
        └──────────►add◄────────────┘                      │
                     ▼                                     │
                  softmax                                  │
                     ▼                                     │
                 mhaDropout                                │
                     │                                     │
                     └──────────────►matmul◄───────────────┘
                                       ▼
                                   transpose
                                       ▼
                                    reshape
                                       ▼
                                   mhaOutProj
                                       │
                                       ▼
                                   ┌───────┐
                                   │ query │
                                   └───────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GMultiHeadAttention

Methods

forward :: MonadThrow m => GMultiHeadAttention headDim headEmbedDim embedDim qInProj kInProj vInProj outProj dropout -> (Tensor queryRequiresGradient queryLayout queryDevice queryDataType queryShape, Tensor keyRequiresGradient keyLayout keyDevice keyDataType keyShape, Tensor valueRequiresGradient valueLayout valueDevice valueDataType valueShape, Tensor attentionBiasRequiresGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

type CatF selectDim (Tensor gradient layout device dataType shape :: TYPE LiftedRep) [] Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.IndexingSlicingJoining

type CatF selectDim (Tensor gradient layout device dataType shape :: TYPE LiftedRep) [] = CatListF selectDim (Tensor gradient layout device dataType shape)
type Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Autograd

type Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) = Tensor ('Gradient 'WithoutGradient) layout device dataType shape
type Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Autograd

type Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) = Tensor ('Gradient 'WithoutGradient) layout device dataType shape
type ModelSpec (Tensor gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Class

type ModelSpec (Tensor gradient layout device dataType shape) = TensorSpec gradient layout device dataType shape

data TensorSpec (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where Source #

Constructors

TensorSpec 

Fields

Instances

Instances details
Generic (TensorSpec gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Associated Types

type Rep (TensorSpec gradient layout device dataType shape) :: Type -> Type Source #

Methods

from :: TensorSpec gradient layout device dataType shape -> Rep (TensorSpec gradient layout device dataType shape) x Source #

to :: Rep (TensorSpec gradient layout device dataType shape) x -> TensorSpec gradient layout device dataType shape Source #

Show (TensorSpec gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

showsPrec :: Int -> TensorSpec gradient layout device dataType shape -> ShowS Source #

show :: TensorSpec gradient layout device dataType shape -> String Source #

showList :: [TensorSpec gradient layout device dataType shape] -> ShowS Source #

type Rep (TensorSpec gradient layout device dataType shape) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

type Rep (TensorSpec gradient layout device dataType shape) = D1 ('MetaData "TensorSpec" "Torch.GraduallyTyped.Tensor.Type" "hasktorch-gradually-typed-0.2.0.0-1KV1aIPzzbp6JpSr37tC1K" 'False) (C1 ('MetaCons "TensorSpec" 'PrefixI 'True) ((S1 ('MetaSel ('Just "tsGradient") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SGradient gradient)) :*: S1 ('MetaSel ('Just "tsLayout") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SLayout layout))) :*: (S1 ('MetaSel ('Just "tsDevice") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SDevice device)) :*: (S1 ('MetaSel ('Just "tsDataType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SDataType dataType)) :*: S1 ('MetaSel ('Just "tsShape") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SShape shape))))))

type CPUTensor = Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device 'CPU) Source #

Alias for a tensor on CPU memory without gradients.

type CPUParameter = Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) Source #

Alias for a tensor on CPU memory with gradients.

type SparseCPUTensor = Tensor ('Gradient 'WithoutGradient) ('Layout 'Sparse) ('Device 'CPU) Source #

Alias for a sparse tensor on CPU memory without gradients.

type SparseCPUParameter = Tensor ('Gradient 'WithGradient) ('Layout 'Sparse) ('Device 'CPU) Source #

Alias for a sparse tensor on CPU memory with gradients.

type CUDATensor deviceId = Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device ('CUDA deviceId)) Source #

Alias for a tensor on CUDA memory without gradients.

type CUDAParameter deviceId = Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device ('CUDA deviceId)) Source #

Alias for a tensor on CUDA memory with gradients.

type SparseCUDATensor deviceId = Tensor ('Gradient 'WithoutGradient) ('Layout 'Sparse) ('Device ('CUDA deviceId)) Source #

Alias for a sparse tensor on CUDA memory without gradients.

type SparseCUDAParameter deviceId = Tensor ('Gradient 'WithGradient) ('Layout 'Sparse) ('Device ('CUDA deviceId)) Source #

Alias for a sparse tensor on CUDA memory with gradients.

withoutGradient Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> IO (Tensor ('Gradient 'WithoutGradient) layout device dataType shape)

copy of the input tensor without gradient computations turned off.

Takes a tensor that may or may not require gradient computations and returns a copy that does not require them.

withGradient Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> IO (Tensor ('Gradient 'WithGradient) layout device dataType shape)

copy of the input tensor with gradient computations turned on.

Takes a tensor that does not requires gradient computations and returns a copy that requires them.

sSetGradient :: forall gradient gradient' layout device dataType shape. SGradient gradient -> Tensor gradient' layout device dataType shape -> IO (Tensor gradient layout device dataType shape) Source #

Turn gradient computations off or on for a tensor.

class SGetGradient (gradient :: Gradient RequiresGradient) where Source #

Minimal complete definition

sGetGradient

Methods

sGetGradient Source #

Arguments

:: forall layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> SGradient gradient

information about whether or not gradient computations are required

Returns the gradually typed information for whether or not gradient computations for the tensor are turned on.

>>> sOnes' gradient = sOnes $ TensorSpec gradient (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- sOnes' $ SGradient SWithGradient
>>> sGetGradient t
SGradient SWithGradient
>>> t <- sOnes' $ SUncheckedGradient WithoutGradient
>>> sGetGradient t
SUncheckedGradient WithoutGradient

getRequiresGradient Source #

Arguments

:: forall layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> RequiresGradient

information about whether or not gradient computations are required

Returns the untyped memory layout of the input tensor.

>>> sOnes' gradient = sOnes $ TensorSpec gradient (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- sOnes' $ SGradient SWithGradient
>>> getRequiresGradient t
WithGradient
>>> t <- sOnes' $ SUncheckedGradient WithoutGradient
>>> getRequiresGradient t
WithoutGradient

Instances

Instances details
SGetGradient ('UncheckedGradient :: Gradient RequiresGradient) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetGradient :: forall (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor 'UncheckedGradient layout device dataType shape -> SGradient 'UncheckedGradient Source #

getRequiresGradient :: forall (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor 'UncheckedGradient layout device dataType shape -> RequiresGradient Source #

SGetGradient ('Gradient 'WithGradient) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetGradient :: forall (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor ('Gradient 'WithGradient) layout device dataType shape -> SGradient ('Gradient 'WithGradient) Source #

getRequiresGradient :: forall (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor ('Gradient 'WithGradient) layout device dataType shape -> RequiresGradient Source #

SGetGradient ('Gradient 'WithoutGradient) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetGradient :: forall (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor ('Gradient 'WithoutGradient) layout device dataType shape -> SGradient ('Gradient 'WithoutGradient) Source #

getRequiresGradient :: forall (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor ('Gradient 'WithoutGradient) layout device dataType shape -> RequiresGradient Source #

sCheckedGradient Source #

Arguments

:: forall gradient' m gradient layout device dataType shape. (SGetGradient gradient, MonadThrow m, Catch (gradient <+> gradient')) 
=> SGradient gradient'

layout

-> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient' layout device dataType shape)

annotated output tensor wrapped in m

Checks whether or not gradient computations are required for a tensor and returns a statically annotated copy of it wrapped in a MonadThrow m.

For instance, if m is Maybe, then the result will be wrapped in Just if and only if gradients are computed for the tensor according to the argument gradient. If gradients are expected but none are computed, then the result will be Nothing. If gradients are not expected but are computed, then the result will be Nothing as well.

In the REPL, m will default to IO: >>> t <- sOnes $ TensorSpec (SUncheckedGradient WithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName "batch" :&: SSize 32 :|: SName "feature" :&: SSize 8 :|: SNil) >>> t' <- sCheckedGradient (SGradient SWithGradient) t >>> :type t' t' :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)]) >>> t' <- sCheckedGradient (SGradient SWithoutGradient) t *** Exception: GradientError {geExpected = WithoutGradient, geActual = WithGradient}

checkedGradient Source #

Arguments

:: forall gradient' m gradient layout device dataType shape. (SingI gradient', SGetGradient gradient, MonadThrow m, Catch (gradient <+> gradient')) 
=> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient' layout device dataType shape)

annotated output tensor wrapped in m

uncheckedGradient Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> Tensor 'UncheckedGradient layout device dataType shape

tensor without checked layout

Returns the input tensor but with UncheckedGradeint as gradient type annotation. Any static information about whether or not the gradient computation is required for the tensor is lost. However, the tensor's underlying data structure is not changed.

>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedGradient t
uncheckedGradient t
  :: Tensor
       'UncheckedGradient
       ('Layout 'Dense)
       ('Device 'CPU)
       ('DataType 'Float)
       ('Shape
          '[ 'Dim ('Name "batch") ('Size 32),
             'Dim ('Name "feature") ('Size 8)])

toDense Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient ('Layout 'Dense) device dataType shape)

dense copy

Returns a dense copy of the tensor.

toSparse Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient ('Layout 'Sparse) device dataType shape)

sparse copy

Returns a sparse copy of the tensor.

sSetLayout :: forall m gradient layout layout' device dataType shape. MonadThrow m => SLayout layout -> Tensor gradient layout' device dataType shape -> m (Tensor gradient layout device dataType shape) Source #

Set the memory layout of a tensor to a given layout.

class SGetLayout (layout :: Layout LayoutType) where Source #

Minimal complete definition

sGetLayout

Methods

sGetLayout Source #

Arguments

:: forall gradient device dataType shape. Tensor gradient layout device dataType shape

input

-> SLayout layout

memory layout

Returns the gradually typed memory layout of the input tensor.

>>> sOnes' layout = sOnes $ TensorSpec (SGradient SWithGradient) layout (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- sOnes' $ SLayout SDense
>>> sGetLayout t
SLayout SDense
>>> t <- sOnes' $ SUncheckedLayout Dense
>>> sGetLayout t
SUncheckedLayout Dense

getLayoutType Source #

Arguments

:: forall gradient device dataType shape. Tensor gradient layout device dataType shape

input

-> LayoutType

memory layout

Returns the untyped memory layout of the input tensor.

>>> sOnes' layout = sOnes $ TensorSpec (SGradient SWithGradient) layout (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- sOnes' $ SLayout SDense
>>> getLayoutType t
Dense
>>> t <- sOnes' $ SUncheckedLayout Dense
>>> getLayoutType t
Dense

Instances

Instances details
SGetLayout ('UncheckedLayout :: Layout LayoutType) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetLayout :: forall (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient 'UncheckedLayout device dataType shape -> SLayout 'UncheckedLayout Source #

getLayoutType :: forall (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient 'UncheckedLayout device dataType shape -> LayoutType Source #

SGetLayout ('Layout 'Dense) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetLayout :: forall (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient ('Layout 'Dense) device dataType shape -> SLayout ('Layout 'Dense) Source #

getLayoutType :: forall (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient ('Layout 'Dense) device dataType shape -> LayoutType Source #

SGetLayout ('Layout 'Sparse) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetLayout :: forall (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient ('Layout 'Sparse) device dataType shape -> SLayout ('Layout 'Sparse) Source #

getLayoutType :: forall (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient ('Layout 'Sparse) device dataType shape -> LayoutType Source #

sCheckedLayout Source #

Arguments

:: forall layout' m gradient layout device dataType shape. (SGetLayout layout, MonadThrow m, Catch (layout <+> layout')) 
=> SLayout layout'

layout

-> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout' device dataType shape)

annotated output tensor wrapped in m

Checks whether or not the input tensor has the memory layout layout and returns a statically annotated copy of it wrapped in a MonadThrow m.

For instance, if m is Maybe, then the result will be wrapped in Just if and only if the tensor has indeed the memory layout layout. If it does not have it, then the result will be Nothing.

In the REPL, m will default to IO: >>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SUncheckedLayout Dense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName "batch" :&: SSize 32 :|: SName "feature" :&: SSize 8 :|: SNil) >>> t' <- sCheckedLayout (SLayout SDense) t >>> :type t' t' :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)]) >>> t' <- sCheckedLayout (SLayout SSparse) t *** Exception: LayoutError {leExpected = Sparse, leActual = Dense}

checkedLayout Source #

Arguments

:: forall layout' m gradient layout device dataType shape. (SingI layout', SGetLayout layout, MonadThrow m, Catch (layout <+> layout')) 
=> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout' device dataType shape)

annotated output tensor wrapped in m

uncheckedLayout Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> Tensor gradient 'UncheckedLayout device dataType shape

tensor without checked layout

Returns the input tensor but with UncheckedLayout as memory layout type annotation. Any static information about the tensor's memory layout is thus erased. However, the tensor's underlying data structure is not changed.

>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedLayout t
uncheckedLayout t
  :: Tensor
       ('Gradient 'WithGradient)
       'UncheckedLayout
       ('Device 'CPU)
       ('DataType 'Float)
       ('Shape
          '[ 'Dim ('Name "batch") ('Size 32),
             'Dim ('Name "feature") ('Size 8)])

cpu Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient layout ('Device 'CPU) dataType shape)

copy in CPU memory

Returns a copy of the tensor in CPU memory.

cuda Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient layout ('Device ('CUDA 0)) dataType shape)

copy in CUDA memory

Returns a copy of the tensor in CUDA memory.

sSetDevice :: forall m gradient layout device device' dataType shape. MonadThrow m => SDevice device -> Tensor gradient layout device' dataType shape -> m (Tensor gradient layout device dataType shape) Source #

Reallocates a tensor on the specified device.

class SGetDevice (device :: Device (DeviceType Nat)) where Source #

Minimal complete definition

sGetDevice

Methods

sGetDevice Source #

Arguments

:: forall gradient layout dataType shape. Tensor gradient layout device dataType shape

input

-> SDevice device

compute device of the input tensor

Returns the gradually typed compute device of the input tensor.

>>> ones' device = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) device (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- ones' $ SDevice SCPU
>>> sGetDevice t
SDevice SCPU
>>> t <- ones' $ SUncheckedDevice CPU
>>> sGetDevice t
SUncheckedDevice CPU

getDeviceType Source #

Arguments

:: forall gradient layout dataType shape. Tensor gradient layout device dataType shape

input

-> DeviceType Int16

compute device of the input tensor

Returns the untyped compute device of the input tensor.

>>> ones' device = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) device (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- ones' $ SDevice SCPU
>>> getDeviceType t
CPU
>>> t <- ones' $ SUncheckedDevice CPU
>>> getDeviceType t
CPU

Instances

Instances details
SGetDevice ('UncheckedDevice :: Device (DeviceType Nat)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDevice :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout 'UncheckedDevice dataType shape -> SDevice 'UncheckedDevice Source #

getDeviceType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout 'UncheckedDevice dataType shape -> DeviceType Int16 Source #

SGetDevice ('Device ('CPU :: DeviceType Nat)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDevice :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout ('Device 'CPU) dataType shape -> SDevice ('Device 'CPU) Source #

getDeviceType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout ('Device 'CPU) dataType shape -> DeviceType Int16 Source #

KnownNat deviceIndex => SGetDevice ('Device ('CUDA deviceIndex)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDevice :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout ('Device ('CUDA deviceIndex)) dataType shape -> SDevice ('Device ('CUDA deviceIndex)) Source #

getDeviceType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout ('Device ('CUDA deviceIndex)) dataType shape -> DeviceType Int16 Source #

sCheckedDevice Source #

Arguments

:: forall device' m gradient layout device dataType shape. (SGetDevice device, MonadThrow m, Catch (device <+> device')) 
=> SDevice device'

device

-> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout device' dataType shape)

annotated output tensor wrapped in m

Checks whether or not the input tensor is in the memory of device and returns a statically annotated copy of it wrapped in a MonadThrow m.

For instance, if m is Maybe, then the result will be wrapped in Just if and only if the tensor is indeed on device. If it is not, then the result will be Nothing.

In the REPL, m will default to IO: >>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SUncheckedDevice CPU) (SDataType SFloat) (SShape $ SName "batch" :&: SSize 32 :|: SName "feature" :&: SSize 8 :|: SNil) >>> t' <- sCheckedDevice (SDevice SCPU) t >>> :type t' t' :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)]) >>> t' <- sCheckedDevice (SDevice (SCUDA @0)) t *** Exception: DeviceError {deExpected = CUDA 0, deActual = CPU}

checkedDevice Source #

Arguments

:: forall device' m gradient layout device dataType shape. (SingI device', SGetDevice device, MonadThrow m, Catch (device <+> device')) 
=> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout device' dataType shape)

annotated output tensor wrapped in m

uncheckedDevice Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> Tensor gradient layout 'UncheckedDevice dataType shape

tensor without checked device

Returns the input tensor but with UncheckedDevice as device type annotation. Any static information about the tensor's device is thus erased. However, the tensor's underlying data structure is not changed.

>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedDevice t
uncheckedDevice t
  :: Tensor
       ('Gradient 'WithGradient)
       ('Layout 'Dense)
       'UncheckedDevice
       ('DataType 'Float)
       ('Shape
          '[ 'Dim ('Name "batch") ('Size 32),
             'Dim ('Name "feature") ('Size 8)])

bool Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Bool) shape)

DType copy

Returns a copy of the tensor converted to DType.

byte Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'UInt8) shape)

UInt8 copy

Returns a copy of the tensor converted to UInt8.

char Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int8) shape)

Int8 copy

Returns a copy of the tensor converted to Int8.

short Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int16) shape)

DType copy

Returns a copy of the tensor converted to DType.

int Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int32) shape)

Int32 copy

Returns a copy of the tensor converted to Int32.

long Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int64) shape)

Int64 copy

Returns a copy of the tensor converted to Int64.

half Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient layout device ('DataType 'Half) shape)

Half copy

Returns a copy of the tensor converted to the 16-bit floating point format Half.

float Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient layout device ('DataType 'Float) shape)

DType copy

Returns a copy of the tensor converted to the 32-bit floating point format DType.

double Source #

Arguments

:: forall m gradient layout device dataType shape. MonadThrow m 
=> Tensor gradient layout device dataType shape

input

-> m (Tensor gradient layout device ('DataType 'Double) shape)

DType copy

Returns a copy of the tensor converted to the 32-bit floating point format DType.

sSetDataType :: forall m gradient layout device dataType dataType' shape. MonadThrow m => SDataType dataType -> Tensor gradient layout device dataType' shape -> m (Tensor gradient layout device dataType shape) Source #

Set the data type of a tensor to the specified data type.

class SGetDataType (dataType :: DataType DType) where Source #

Minimal complete definition

sGetDataType

Methods

sGetDataType Source #

Arguments

:: forall gradient layout device shape. Tensor gradient layout device dataType shape

input

-> SDataType dataType

data type of the input tensor

Returns the gradually typed compute data type of the input tensor.

>>> sOnes' dataType = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) dataType (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- sOnes' $ SDataType SFloat
>>> sGetDataType t
SDataType SFloat
>>> t <- sOnes' $ SUncheckedDataType Float
>>> sGetDataType t
SUncheckedDataType Float

getDType Source #

Arguments

:: forall gradient layout device shape. Tensor gradient layout device dataType shape

input

-> DType

data type of the input tensor

Returns the untyped compute data type of the input tensor.

>>> sOnes' dataType = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) dataType (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>> t <- sOnes' $ SDataType SFloat
>>> getDType t
Float
>>> t <- sOnes' $ SUncheckedDataType Float
>>> getDType t
Float

Instances

Instances details
SGetDataType ('UncheckedDataType :: DataType DType) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDataType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout device 'UncheckedDataType shape -> SDataType 'UncheckedDataType Source #

getDType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout device 'UncheckedDataType shape -> DType Source #

SingI dType => SGetDataType ('DataType dType) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDataType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout device ('DataType dType) shape -> SDataType ('DataType dType) Source #

getDType :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (shape :: Shape [Dim (Name Symbol) (Size Nat)]). Tensor gradient layout device ('DataType dType) shape -> DType Source #

sCheckedDataType Source #

Arguments

:: forall dataType' m gradient layout device dataType shape. (SGetDataType dataType, MonadThrow m, Catch (dataType <+> dataType')) 
=> SDataType dataType'

data type

-> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout device dataType' shape)

annotated output tensor wrapped in m

Checks whether or not the input tensor has the data type dataType and returns a statically annotated copy of it wrapped in a MonadThrow m.

For instance, if m is Maybe, then the result will be wrapped in Just if and only if the tensor has indeed the data type dataType. If it does not have it, then the result will be Nothing.

In the REPL, m will default to IO: >>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SUncheckedDataType Float) (SShape $ SName "batch" :&: SSize 32 :|: SName "feature" :&: SSize 8 :|: SNil) >>> t' <- checkedDataType ('DataType 'Float) t >>> :type t' t' :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)]) >>> t' <- checkedDataType ('DataType 'Double) t *** Exception: DataTypeError {dtExpected = Double, dtActual = Float}

checkedDataType Source #

Arguments

:: forall dataType' m gradient layout device dataType shape. (SingI dataType', SGetDataType dataType, MonadThrow m, Catch (dataType <+> dataType')) 
=> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout device dataType' shape)

annotated output tensor wrapped in m

uncheckedDataType Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> Tensor gradient layout device 'UncheckedDataType shape

tensor without checked data type

Returns the input tensor but with UncheckedDataType as data-type type annotation. Any static information about the tensor's data type is thus erased. However, the tensor's underlying data structure is not changed.

>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedDataType t
uncheckedDataType t
  :: Tensor
       ('Gradient 'WithGradient)
       ('Layout 'Dense)
       ('Device 'CPU)
       'UncheckedDataType
       ('Shape
          '[ 'Dim ('Name "batch") ('Size 32),
             'Dim ('Name "feature") ('Size 8)])

class SGetShape (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where Source #

Minimal complete definition

sGetShape

Methods

sGetShape :: forall gradient layout device dataType. Tensor gradient layout device dataType shape -> SShape shape Source #

Returns the gradually typed shape of the input tensor.

>>> sOnes' = sOnes . TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat)
>>> t <- sOnes' . SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil
>>> sGetShape t
SShape (SCons (SDim {sDimName = SName, sDimSize = SSize}) (SCons (SDim {sDimName = SName, sDimSize = SSize}) SNil))
>>> t <- sOnes' . SUncheckedShape $ [Dim "batch" 32, Dim "feature" 8]
>>> sGetShape t
SUncheckedShape [Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]
>>> t <- sOnes' . SShape $ SUncheckedName "batch" :&: SUncheckedSize 32 :|: SUncheckedName "feature" :&: SSize @32 :|: SNil
>>> sGetShape t
SShape (SCons (SDim {sDimName = SUncheckedName "batch", sDimSize = SUncheckedSize 32}) (SCons (SDim {sDimName = SUncheckedName "feature", sDimSize = SSize}) SNil))
>>> t <- sOnes' . SShape $ SName @"batch" :&: SUncheckedSize 32 :|: SName @"feature" :&: SUncheckedSize 8 :|: SNil
>>> sGetShape t
SShape (SCons (SDim {sDimName = SName, sDimSize = SUncheckedSize 32}) (SCons (SDim {sDimName = SName, sDimSize = SUncheckedSize 8}) SNil))

getDims :: forall gradient layout device dataType. Tensor gradient layout device dataType shape -> [Dim String Integer] Source #

Returns the untyped shape of the input tensor.

>>> sOnes' = sOnes . TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat)
>>> t <- sOnes' . SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil
>>> getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]
>>> t <- sOnes' . SUncheckedShape $ [Dim "batch" 32, Dim "feature" 8]
>>> getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]
>>> t <- sOnes' . SShape $ SUncheckedName "batch" :&: SUncheckedSize 32 :|: SUncheckedName "feature" :&: SSize @32 :|: SNil
>>> getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 32}]
>>> t <- sOnes' . SShape $ SName @"batch" :&: SUncheckedSize 32 :|: SName @"feature" :&: SUncheckedSize 8 :|: SNil
>>> getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]

Instances

Instances details
SGetShape ('UncheckedShape :: Shape [Dim (Name Symbol) (Size Nat)]) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetShape :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType). Tensor gradient layout device dataType 'UncheckedShape -> SShape 'UncheckedShape Source #

getDims :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType). Tensor gradient layout device dataType 'UncheckedShape -> [Dim String Integer] Source #

SGetDims dims => SGetShape ('Shape dims) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetShape :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType). Tensor gradient layout device dataType ('Shape dims) -> SShape ('Shape dims) Source #

getDims :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType). Tensor gradient layout device dataType ('Shape dims) -> [Dim String Integer] Source #

class SGetDims (dims :: [Dim (Name Symbol) (Size Nat)]) where Source #

Methods

sGetDims :: [String] -> [Integer] -> SList dims Source #

Instances

Instances details
SGetDims ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDims :: [String] -> [Integer] -> SList '[] Source #

(SGetDim dim, SGetDims dims) => SGetDims (dim ': dims) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDims :: [String] -> [Integer] -> SList (dim ': dims) Source #

dimsError :: forall a. a Source #

dimNameError :: forall a. String -> String -> a Source #

dimSizeError :: forall a b. Show a => a -> a -> b Source #

dimNameSizeError :: forall a b. Show a => String -> String -> a -> a -> b Source #

class SGetDim (dim :: Dim (Name Symbol) (Size Nat)) where Source #

Methods

sGetDim :: String -> Integer -> SDim dim Source #

Instances

Instances details
(KnownSymbol name, KnownNat size) => SGetDim ('Dim ('Name name) ('Size size)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDim :: String -> Integer -> SDim ('Dim ('Name name) ('Size size)) Source #

KnownSymbol name => SGetDim ('Dim ('Name name) ('UncheckedSize :: Size Nat)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDim :: String -> Integer -> SDim ('Dim ('Name name) 'UncheckedSize) Source #

KnownNat size => SGetDim ('Dim ('UncheckedName :: Name Symbol) ('Size size)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sGetDim :: String -> Integer -> SDim ('Dim 'UncheckedName ('Size size)) Source #

SGetDim ('Dim ('UncheckedName :: Name Symbol) ('UncheckedSize :: Size Nat)) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

sCheckedShape Source #

Arguments

:: forall shape' m gradient layout device dataType shape. (SGetShape shape, MonadThrow m, Catch (shape <+> shape')) 
=> SShape shape'

shape

-> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout device dataType shape')

annotated output tensor wrapped in m

Checks whether or not the input tensor has the shape shape and returns a statically annotated copy of it wrapped in a MonadThrow m.

For instance, if m is Maybe, then the result will be wrapped in Just if and only if the tensor has indeed the shape shape. If it is not, then the result will be Nothing.

In the REPL, m will default to IO: >>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SUncheckedShape [Dim "batch" 32, Dim "feature" 8]) >>> t' <- sCheckedShape (SShape $ SName "batch" :&: SSize 32 :|: SName "feature" :&: SSize 8 :|: SNil) t >>> :type t' t' :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)]) >>> t' <- sCheckedShape (SShape $ SUncheckedName "batch" :&: SSize 32 :|: SName "feature" :&: SUncheckedSize 8 :|: SNil) t >>> :type t' t' :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim 'UncheckedName ('Size 32), 'Dim ('Name "feature") 'UncheckedSize]) >>> t' <- sCheckedShape (SShape $ SName "batch" :&: SSize 32 :|: SName @"feature" :&: SUncheckedSize 32 :|: SNil) t *** Exception: ShapeError {seExpected = [Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 32}], seActual = [Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]}

checkedShape Source #

Arguments

:: forall shape' m gradient layout device dataType shape. (SingI shape', SGetShape shape, MonadThrow m, Catch (shape <+> shape')) 
=> Tensor gradient layout device dataType shape

input tensor

-> m (Tensor gradient layout device dataType shape')

annotated output tensor wrapped in m

uncheckedDim Source #

Arguments

:: forall selectDim gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> Tensor gradient layout device dataType (ReplaceDimF selectDim shape ('Dim 'UncheckedName 'UncheckedSize))

tensor with the selected dimensions unchecked

Returns the input tensor but with the selected dimension replaces with UncheckedDim as dimension type annotation. The static information about the selected tensor dimension is thus erased. However, the tensor's underlying data structure is not changed.

>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedDim @('SelectDim ('ByName "batch")) t
uncheckedDim @('SelectDim ('ByName "batch")) t
  :: Tensor
       ('Gradient 'WithGradient)
       ('Layout 'Dense)
       ('Device 'CPU)
       ('DataType 'Float)
       ('Shape
          '[ 'Dim 'UncheckedName 'UncheckedSize,
             'Dim ('Name "feature") ('Size 8)])
>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedDim @('SelectDim ('ByIndex 1)) t
uncheckedDim @('SelectDim ('ByIndex 1)) t
  :: Tensor
       ('Gradient 'WithGradient)
       ('Layout 'Dense)
       ('Device 'CPU)
       ('DataType 'Float)
       ('Shape
          '[ 'Dim ('Name "batch") ('Size 32),
             'Dim 'UncheckedName 'UncheckedSize])

uncheckedShape Source #

Arguments

:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape

input tensor

-> Tensor gradient layout device dataType 'UncheckedShape

tensor without checked shape

Returns the input tensor but with UncheckedShape as shape type annotation. Any static information about the tensor's shape is thus erased. However, the tensor's underlying data structure is not changed.

>>> t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>> :type uncheckedShape t
uncheckedShape t
  :: Tensor
       ('Gradient 'WithGradient)
       ('Layout 'Dense)
       ('Device 'CPU)
       ('DataType 'Float)
       'UncheckedShape

isContiguous :: Tensor gradient layout device dataType shape -> Bool Source #

contiguous :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #

withTensor :: Tensor gradient layout device dataType shape -> (Ptr () -> IO a) -> IO a Source #

class TensorLikeRaw a where Source #

Methods

guessDim Source #

Arguments

:: Maybe a

value Nothing if the data type wrapping a is empty.

-> Maybe Int

dimension Nothing if a is a scalar.

Guesses outer dim.

>>> guessDim @[[Int]] $ pure [[1, 2], [3, 4], [5, 6]]
Just 3

guessInnerDims Source #

Arguments

:: MonadThrow m 
=> Maybe a

value Nothing if the data type wrapping a is empty.

-> m [Int]

inner dimensions

Guesses inner dims.

>>> guessInnerDims @[[Int]] $ pure [[1, 2], [3, 4], [5, 6]]
[2]

tensorPeekElemOff Source #

Arguments

:: Ptr ()

pointer to tensor

-> Int

offset

-> [Int]

tensor dimensions

-> IO a

value

Reads a value from a tensor.

tensorPokeElemOff Source #

Arguments

:: Ptr ()

pointer to tensor

-> Int

offset

-> [Int]

tensor dimensions

-> a

value

-> IO () 

Writes a value to a tensor.

Instances

Instances details
TensorLikeRaw Bool Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

TensorLikeRaw Double Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

TensorLikeRaw Float Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

TensorLikeRaw Int Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

TensorLikeRaw a => TensorLikeRaw (Vector a) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

guessDim :: Maybe (Vector a) -> Maybe Int Source #

guessInnerDims :: MonadThrow m => Maybe (Vector a) -> m [Int] Source #

tensorPeekElemOff :: Ptr () -> Int -> [Int] -> IO (Vector a) Source #

tensorPokeElemOff :: Ptr () -> Int -> [Int] -> Vector a -> IO () Source #

TensorLikeRaw a => TensorLikeRaw [a] Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

guessDim :: Maybe [a] -> Maybe Int Source #

guessInnerDims :: MonadThrow m => Maybe [a] -> m [Int] Source #

tensorPeekElemOff :: Ptr () -> Int -> [Int] -> IO [a] Source #

tensorPokeElemOff :: Ptr () -> Int -> [Int] -> [a] -> IO () Source #

(KnownNat n, TensorLikeRaw a) => TensorLikeRaw (Vector n a) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

guessDim :: Maybe (Vector n a) -> Maybe Int Source #

guessInnerDims :: MonadThrow m => Maybe (Vector n a) -> m [Int] Source #

tensorPeekElemOff :: Ptr () -> Int -> [Int] -> IO (Vector n a) Source #

tensorPokeElemOff :: Ptr () -> Int -> [Int] -> Vector n a -> IO () Source #

(TensorLikeRaw a, TensorLikeRaw b) => TensorLikeRaw (a, b) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

guessDim :: Maybe (a, b) -> Maybe Int Source #

guessInnerDims :: MonadThrow m => Maybe (a, b) -> m [Int] Source #

tensorPeekElemOff :: Ptr () -> Int -> [Int] -> IO (a, b) Source #

tensorPokeElemOff :: Ptr () -> Int -> [Int] -> (a, b) -> IO () Source #

(TensorLikeRaw a, TensorLikeRaw b, TensorLikeRaw c) => TensorLikeRaw (a, b, c) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

guessDim :: Maybe (a, b, c) -> Maybe Int Source #

guessInnerDims :: MonadThrow m => Maybe (a, b, c) -> m [Int] Source #

tensorPeekElemOff :: Ptr () -> Int -> [Int] -> IO (a, b, c) Source #

tensorPokeElemOff :: Ptr () -> Int -> [Int] -> (a, b, c) -> IO () Source #

guessDims :: forall a m. (TensorLikeRaw a, MonadThrow m) => Maybe a -> m [Int] Source #

Guesses dims: concatenates guessDim with guessInnerDims.

>>> guessDims @[[Int]] $ pure [[1, 2], [3, 4], [5, 6]]
[3,2]

unexpectedDimsError :: forall a m b. (TensorLikeRaw a, MonadThrow m) => [Int] -> Maybe a -> m b Source #

class TensorLike a (dType :: DType) (dims :: [Dim (Name Symbol) (Size Nat)]) | a -> dims, a -> dType where Source #

Methods

sToTensor :: forall gradient layout device m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims)) Source #

Creates a tensor from a TensorLike value.

>>> t <- sToTensor (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) ([(1, 2), (3, 4), (5, 6)] :: [(Int, Int)])
>>> t
Tensor Int64 [3,2] [[ 1,  2],
                    [ 3,  4],
                    [ 5,  6]]
>>> :type t
t :: Tensor
       ('Gradient 'WithoutGradient)
       ('Layout 'Dense)
       ('Device 'CPU)
       ('DataType 'Int64)
       ('Shape
          '[ 'Dim ('Name "*") 'UncheckedSize, 'Dim ('Name "*") ('Size 2)])

fromTensor :: forall gradient layout device. Tensor gradient layout device ('DataType dType) ('Shape dims) -> a Source #

Creates a TensorLike from a tensor.

Instances

Instances details
TensorLike Bool 'Bool ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Bool0 -> m (Tensor gradient layout device ('DataType 'Bool) ('Shape '[])) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Bool) ('Shape '[]) -> Bool0 Source #

TensorLike Double 'Double ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Double0 -> m (Tensor gradient layout device ('DataType 'Double) ('Shape '[])) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Double) ('Shape '[]) -> Double0 Source #

TensorLike Float 'Float ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Float0 -> m (Tensor gradient layout device ('DataType 'Float) ('Shape '[])) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Float) ('Shape '[]) -> Float0 Source #

TensorLike Int 'Int64 ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Int -> m (Tensor gradient layout device ('DataType 'Int64) ('Shape '[])) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Int64) ('Shape '[]) -> Int Source #

(TensorLike a dType dims, TensorLikeRaw a, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape dims) ('Dim ('Name "*") ('UncheckedSize :: Size Nat))) => TensorLike (Vector a) dType dimsOut Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Vector a -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> Vector a Source #

(TensorLike a dType dims, TensorLikeRaw a, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape dims) ('Dim ('Name "*") ('UncheckedSize :: Size Nat))) => TensorLike [a] dType dimsOut Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> [a] -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> [a] Source #

(KnownNat n, TensorLike a dType dims, TensorLikeRaw a, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape dims) ('Dim ('Name "*") ('Size n))) => TensorLike (Vector n a) dType dimsOut Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Vector n a -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> Vector n a Source #

(TensorLike a dType dims, TensorLike b dType dims', TensorLikeRaw a, TensorLikeRaw b, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape (dims <+> dims')) ('Dim ('Name "*") ('Size 2))) => TensorLike (a, b) dType dimsOut Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> (a, b) -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> (a, b) Source #

(TensorLike a dType dims, TensorLike b dType dims', TensorLike c dType dims', TensorLikeRaw a, TensorLikeRaw b, TensorLikeRaw c, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape (dims <+> dims')) ('Dim ('Name "*") ('Size 3))) => TensorLike (a, b, c) dType dimsOut Source # 
Instance details

Defined in Torch.GraduallyTyped.Tensor.Type

Methods

sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> (a, b, c) -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source #

fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> (a, b, c) Source #

toTensor :: forall gradient layout device a dType dims m. (TensorLike a dType dims, SingI gradient, SingI layout, SingI device, MonadThrow m) => a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims)) Source #

Non-singleton version of sToTensor.

sToTensorRaw :: forall gradient layout device a dType dims m. (TensorLike a dType dims, TensorLikeRaw a, SingI dType, MonadThrow m) => SGradient gradient -> SLayout layout -> SDevice device -> a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims)) Source #

fromTensorRaw :: forall gradient layout device a dType dims. (TensorLike a dType dims, TensorLikeRaw a, SGetDims dims) => Tensor gradient layout device ('DataType dType) ('Shape dims) -> a Source #

checkDims :: MonadThrow m => [Int] -> [Int] -> m () Source #

unzip3 :: Functor f => f (a, b, c) -> (f a, f b, f c) Source #

sSetTensorOptions :: forall gradient layout device dataType gradientFrom layoutFrom deviceFrom dataTypeFrom shape. SGradient gradient -> SLayout layout -> SDevice device -> SDataType dataType -> Tensor gradientFrom layoutFrom deviceFrom dataTypeFrom shape -> IO (Tensor gradient layout device dataType shape) Source #

setTensorOptions :: forall gradient layout device dataType gradientFrom layoutFrom deviceFrom dataTypeFrom shape. (SingI gradient, SingI layout, SingI device, SingI dataType) => Tensor gradientFrom layoutFrom deviceFrom dataTypeFrom shape -> IO (Tensor gradient layout device dataType shape) Source #

Orphan instances

Castable (HList ('[] :: [k])) [ForeignPtr Tensor] Source # 
Instance details

Methods

cast :: HList '[] -> ([ForeignPtr Tensor] -> IO r) -> IO r Source #

uncast :: [ForeignPtr Tensor] -> (HList '[] -> IO r) -> IO r Source #

Castable (HList l) [ForeignPtr Tensor] => Castable (HList l) (ForeignPtr TensorList) Source # 
Instance details

Methods

cast :: HList l -> (ForeignPtr TensorList -> IO r) -> IO r Source #

uncast :: ForeignPtr TensorList -> (HList l -> IO r) -> IO r Source #