Expand description
Dynamic tensor types for gradual shape adoption.
This module provides types for working with tensors whose shapes are not known at compile time, enabling gradual adoption of shape-indexed types.
§Overview
Shape-indexed tensors (Tensor '[m, n] Float) provide compile-time dimension
checking, but sometimes shapes are only known at runtime. DynTensor bridges
this gap by providing an existentially-quantified wrapper.
§Usage Pattern
-- Convert static to dynamic (always succeeds)
toDynamic :: Tensor shape a -> DynTensor a
-- Convert dynamic to static (may fail at runtime)
fromDynamic :: KnownShape shape => DynTensor a -> Maybe (Tensor shape a)
-- Example:
processData :: DynTensor Float -> IO ()
processData dyn = case fromDynamic @'[1024, 768] dyn of
Just tensor -> optimizedPath tensor -- statically known shape
Nothing -> fallbackPath dyn -- dynamic shape handling§Type Signatures
DynTensor :: * -> *
toDynamic :: forall shape a. Tensor shape a -> DynTensor a
fromDynamic :: forall shape a. KnownShape shape
=> DynTensor a -> Maybe (Tensor shape a)
withDynShape :: DynTensor a -> (forall shape. Tensor shape a -> r) -> r
dynShape :: DynTensor a -> [Int]Functions§
- dyn_
rank_ type - Creates the type for
dynRank. - dyn_
shape_ type - Creates the type for
dynShape. - dyn_
tensor_ elem_ type - Extracts the element type from a
DynTensor atype. - dyn_
tensor_ of - Creates a
DynTensor atype. - dyn_
tensor_ tycon - Creates the
DynTensortype constructor. - from_
dynamic_ type - Creates the type for
fromDynamic. - is_
dyn_ tensor - Checks if a type is a
DynTensortype. - shape_
witness_ of - Creates a
ShapeWitness shapetype. - shape_
witness_ tycon - Creates the
ShapeWitnesstype constructor. - static_
shape_ witness - Creates a static shape witness type from concrete dimensions.
- to_
dynamic_ type - Creates the type for
toDynamic. - with_
dyn_ shape_ type - Creates the type for
withDynShape.