inf-backprop-0.2.0.0: Automatic differentiation and backpropagation.
Copyright(C) 2025 Alexey Tochin
LicenseBSD3 (see the file LICENSE)
MaintainerAlexey Tochin <Alexey.Tochin@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Numeric.InfBackprop.Utils.SizedVector

Description

Utility functions for working with sized vector.

Synopsis

Documentation

type BoxedVector (n :: Nat) a = Vector Vector n a Source #

Type alias for boxed sized vectors.

boxedVectorBasis :: forall (v :: Type -> Type) a (n :: Nat). (Vector v a, KnownNat n) => Finite n -> a -> a -> Vector v n a Source #

Creates a sized vector of size n with all elements set to x :: a except for the one at index k, which is set to y :: a.

Examples

Expand
>>> import GHC.Base (Int, String)
>>> import qualified Data.Vector as DV
>>> import qualified Data.Vector.Generic.Sized as DVGS
>>> boxedVectorBasis 2 0 1 :: DVGS.Vector DV.Vector 4 Int
Vector [0,0,1,0]
>>> boxedVectorBasis 1 "zero" "one" :: DVGS.Vector DV.Vector 5 String
Vector ["zero","one","zero","zero","zero"]

boxedVectorSum :: forall a (n :: Nat). Additive a => Vector Vector n a -> a Source #

Sums all elements of a sized array.

Examples

Expand
>>> import GHC.Base (Int)
>>> import qualified Data.Vector as DV
>>> import qualified Data.Vector.Generic.Sized as DVGS
>>> boxedVectorSum (DVGS.fromTuple (1, 2, 3) :: DVGS.Vector DV.Vector 3 Int)
6