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

Torch.GraduallyTyped.Tensor.Creation

Synopsis

Documentation

sOnes :: forall gradient layout device dataType shape m. MonadThrow m => TensorSpec gradient layout device dataType shape -> m (Tensor gradient layout device dataType shape) Source #

Create a gradually typed tensor of ones.

>>> shape = SShape $ SName @"batch" :&: SSize @32 :|: SUncheckedName "feature" :&: SUncheckedSize 8 :|: SNil
>>> :type sOnes $ TensorSpec (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) (SDataType SInt64) shape
sOnes $ TensorSpec (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) (SDataType SInt64) shape
  :: MonadThrow m =>
     m (Tensor
          ('Gradient 'WithoutGradient)
          ('Layout 'Dense)
          ('Device 'CPU)
          ('DataType 'Int64)
          ('Shape
             '[ 'Dim ('Name "batch") ('Size 32),
                'Dim 'UncheckedName 'UncheckedSize]))

ones :: forall gradient layout device dataType shape m. MonadThrow m => (SingI gradient, SingI layout, SingI device, SingI dataType, SingI shape) => m (Tensor gradient layout device dataType shape) Source #

Create a typed tensor of ones.

>>> ones :: IO (CPUParameter ('DataType 'Float) ('Shape '[]))
Tensor Float []  1.0000
>>> ones :: IO (CPUTensor ('DataType 'Int64) ('Shape '[ 'Dim ('Name "*") ('Size 1)]))
Tensor Int64 [1] [ 1]

sZeros :: forall gradient layout device dataType shape m. MonadThrow m => TensorSpec gradient layout device dataType shape -> m (Tensor gradient layout device dataType shape) Source #

Create a gradually typed tensor of zeros.

>>> shape = SShape $ SName @"batch" :&: SSize @32 :|: SUncheckedName "feature" :&: SUncheckedSize 8 :|: SNil
>>> :type sZeros $ TensorSpec (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) (SDataType SInt64) shape
sZeros $ TensorSpec (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) (SDataType SInt64) shape
  :: MonadThrow m =>
     m (Tensor
          ('Gradient 'WithoutGradient)
          ('Layout 'Dense)
          ('Device 'CPU)
          ('DataType 'Int64)
          ('Shape
             '[ 'Dim ('Name "batch") ('Size 32),
                'Dim 'UncheckedName 'UncheckedSize]))

zeros :: forall gradient layout device dataType shape m. MonadThrow m => (SingI gradient, SingI layout, SingI device, SingI dataType, SingI shape) => m (Tensor gradient layout device dataType shape) Source #

Create a typed tensor of zeros.

>>> zeros :: IO (CPUParameter ('DataType 'Float) ('Shape '[]))
Tensor Float []  0.0000
>>> zeros :: IO (CPUTensor ('DataType 'Int64) ('Shape '[ 'Dim ('Name "*") ('Size 1)]))
Tensor Int64 [1] [ 0]

sFull :: forall gradient layout device dataType shape input m. (MonadThrow m, Scalar input) => TensorSpec gradient layout device dataType shape -> input -> m (Tensor gradient layout device dataType shape) Source #

Create a gradually typed tensor filled with a given scalar value.

>>> shape = SShape $ SName @"batch" :&: SSize @32 :|: SUncheckedName "feature" :&: SUncheckedSize 8 :|: SNil
>>> input = -1
>>> :type sFull (TensorSpec (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) (SDataType SInt64) shape) input
sFull (TensorSpec (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) (SDataType SInt64) shape) input
  :: MonadThrow m =>
     m (Tensor
          ('Gradient 'WithoutGradient)
          ('Layout 'Dense)
          ('Device 'CPU)
          ('DataType 'Int64)
          ('Shape
             '[ 'Dim ('Name "batch") ('Size 32),
                'Dim 'UncheckedName 'UncheckedSize]))

full :: forall gradient layout device dataType shape input m. (MonadThrow m, SingI gradient, SingI layout, SingI device, SingI dataType, SingI shape, Scalar input) => input -> m (Tensor gradient layout device dataType shape) Source #

Create a typed tensor filled with a given scalar value.

>>> full (-1) :: IO (CPUParameter ('DataType 'Float) ('Shape '[]))
Tensor Float [] -1.0000
>>> full (-1) :: IO (CPUTensor ('DataType 'Int64) ('Shape '[ 'Dim ('Name "*") ('Size 1)]))
Tensor Int64 [1] [-1]

sRandn :: forall gradient layout device dataType shape generatorDevice m. (SGetGeneratorDevice generatorDevice, MonadThrow m) => TensorSpec gradient layout device dataType shape -> Generator generatorDevice -> m (Tensor gradient layout (device <+> generatorDevice) dataType shape, Generator (device <+> generatorDevice)) Source #

Create a gradually typed random tensor.

randn :: forall gradient layout device dataType shape generatorDevice m. (SGetGeneratorDevice generatorDevice, MonadThrow m) => (SingI gradient, SingI layout, SingI device, SingI dataType, SingI shape) => Generator generatorDevice -> m (Tensor gradient layout (device <+> generatorDevice) dataType shape, Generator (device <+> generatorDevice)) Source #

Create typed random tensor.

sArangeNaturals :: forall m gradient layout device dataType size shape. (MonadThrow m, shape ~ 'Shape '['Dim ('Name "*") size]) => SGradient gradient -> SLayout layout -> SDevice device -> SDataType dataType -> SSize size -> m (Tensor gradient layout device dataType shape) Source #

Create a gradually typed one-dimensional tensor of the numbers 0 to size -1.

arangeNaturals :: forall size gradient layout device dataType shape m. (MonadThrow m, shape ~ 'Shape '['Dim ('Name "*") size], SingI gradient, SingI layout, SingI device, SingI dataType, SingI size) => m (Tensor gradient layout device dataType shape) Source #

Create a typed one-dimensional tensor of the numbers 0 to size -1.

sEye :: forall gradient layout device dataType rows cols shape m. (MonadThrow m, shape ~ 'Shape '['Dim ('Name "*") rows, 'Dim ('Name "*") cols]) => SGradient gradient -> SLayout layout -> SDevice device -> SDataType dataType -> SSize rows -> SSize cols -> m (Tensor gradient layout device dataType shape) Source #

Create a gradually typed rectangular tensor with ones on the diagonal and zeros elsewhere.

eye :: forall rows cols gradient layout device dataType shape m. (MonadThrow m, shape ~ 'Shape '['Dim ('Name "*") rows, 'Dim ('Name "*") cols], SingI gradient, SingI layout, SingI device, SingI dataType, SingI rows, SingI cols) => m (Tensor gradient layout device dataType shape) Source #

Create a typed rectangular tensor with ones on the diagonal and zeros elsewhere.

sEyeSquare :: forall gradient layout device dataType size shape m. (MonadThrow m, shape ~ 'Shape '['Dim ('Name "*") size, 'Dim ('Name "*") size]) => SGradient gradient -> SLayout layout -> SDevice device -> SDataType dataType -> SSize size -> m (Tensor gradient layout device dataType shape) Source #

Create a gradually typed square tensor with ones on the diagonal and zeros elsewhere.

eyeSquare :: forall size gradient layout device dataType shape m. (MonadThrow m, shape ~ 'Shape '['Dim ('Name "*") size, 'Dim ('Name "*") size], SingI gradient, SingI layout, SingI device, SingI dataType, SingI size) => m (Tensor gradient layout device dataType shape) Source #

Create a typed square tensor with ones on the diagonal and zeros elsewhere.