-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | core package for Numerical Haskell project -- -- the core package for Numerical Haskell. Still immature and incomplete @package numerical @version 0.0.0.0 module Control.NumericalApplicative.Backwards -- | The same functor, but with an Applicative instance that -- performs actions in the reverse order. newtype Backwards f a Backwards :: f a -> Backwards f a [forwards] :: Backwards f a -> f a (<**>) :: Applicative f => f a -> f (a -> b) -> f b liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c instance GHC.Base.Functor f => GHC.Base.Functor (Control.NumericalApplicative.Backwards.Backwards f) instance GHC.Base.Applicative f => GHC.Base.Applicative (Control.NumericalApplicative.Backwards.Backwards f) instance GHC.Base.Alternative f => GHC.Base.Alternative (Control.NumericalApplicative.Backwards.Backwards f) instance Data.Foldable.Foldable f => Data.Foldable.Foldable (Control.NumericalApplicative.Backwards.Backwards f) instance Data.Traversable.Traversable f => Data.Traversable.Traversable (Control.NumericalApplicative.Backwards.Backwards f) module Control.NumericalMonad.State.Strict -- | Identity functor and monad. newtype Identity a Identity :: a -> Identity a [runIdentity] :: Identity a -> a -- | A state monad parameterized by the type s of the state to -- carry. -- -- The return function leaves the state unchanged, while -- >>= uses the final state of the first computation as -- the initial state of the second. type State s = StateT s Identity -- | Construct a state monad computation from a function. (The inverse of -- runState.) state :: Monad m => (s -> (a, s)) -> StateT s m a -- | Unwrap a state monad computation as a function. (The inverse of -- state.) runState :: State s a -> s -> (a, s) -- | Evaluate a state computation with the given initial state and return -- the final value, discarding the final state. -- --
evalState :: State s a -> s -> a -- | Evaluate a state computation with the given initial state and return -- the final state, discarding the final value. -- -- execState :: State s a -> s -> s -- | Map both the return value and final state of a computation using the -- given function. -- -- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b -- | withState f m executes action m on a state -- modified by applying f. -- -- withState :: (s -> s) -> State s a -> State s a -- | A state transformer monad parameterized by: -- --evalStateT m s = liftM fst -- (runStateT m s)
execStateT m s = liftM snd -- (runStateT m s)
withStateT f m = modify f >> m
-- >>> Proxy :: Proxy (Void, Int -> Int) -- Proxy ---- -- Proxy can even hold types of higher kinds, -- --
-- >>> Proxy :: Proxy Either -- Proxy ---- --
-- >>> Proxy :: Proxy Functor -- Proxy ---- --
-- >>> Proxy :: Proxy complicatedStructure -- Proxy --data Proxy (t :: k) :: forall k. () => k -> Type Proxy :: Proxy type LitNat = Nat type family U (n :: Nat) :: Nat instance Data.Data.Data Numerical.Nat.Nat instance GHC.Read.Read Numerical.Nat.Nat instance GHC.Show.Show Numerical.Nat.Nat instance GHC.Classes.Eq Numerical.Nat.Nat module Numerical.Array.Shape data Shape (rank :: Nat) a [Nil] :: Shape 'Z a [:*] :: !a -> !Shape r a -> Shape ( 'S r) a infixr 3 :* foldl :: forall a b r. Foldable (Shape r) => (b -> a -> b) -> b -> Shape r a -> b foldr :: forall a b r. Foldable (Shape r) => (a -> b -> b) -> b -> Shape r a -> b foldl' :: forall a b r. Foldable (Shape r) => (b -> a -> b) -> b -> Shape r a -> b foldl1 :: forall b r. Foldable (Shape ( 'S r)) => (b -> b -> b) -> Shape ( 'S r) b -> b foldr1 :: forall b r. Foldable (Shape ( 'S r)) => (b -> b -> b) -> Shape ( 'S r) b -> b map :: forall a b r. Applicative (Shape r) => (a -> b) -> Shape r a -> Shape r b map2 :: forall a b c r. Applicative (Shape r) => (a -> b -> c) -> Shape r a -> Shape r b -> Shape r c reverseShape :: Shape n a -> Shape n a data Nat S :: !Nat -> Nat Z :: Nat shapeSize :: Foldable (Shape n) => Shape n a -> Int data SNat :: Nat -> * [SZero] :: SNat 'Z [SSucc] :: SNat n -> SNat ( 'S n) -- | weaklyDominates is the <= operator lifted onto a -- sized vector to induce a partial order relation weaklyDominates :: (Ord a, Applicative (Shape n), Foldable (Shape n)) => Shape n a -> Shape n a -> Bool -- | strictlyDominates is the < operator lifted onto a -- sized vector to induce a partial order relation strictlyDominates :: (Ord a, Applicative (Shape n), Foldable (Shape n)) => Shape n a -> Shape n a -> Bool shapeToList :: Shape n a -> [a] type Index rank = Shape rank Int backwards :: (Traversable t, Applicative f) => ((a -> Backwards f b) -> t a -> Backwards f (t b)) -> (a -> f b) -> t a -> f (t b) class (Unbox (Shape n a)) => UnBoxedShapeMorphism n a unShapeMVector :: UnBoxedShapeMorphism n a => MVector s (Shape n a) -> (Int, Shape n (MVector s a)) reShapeMVector :: UnBoxedShapeMorphism n a => (Int, Shape n (MVector s a)) -> MVector s (Shape n a) unShapeVector :: (UnBoxedShapeMorphism n a, Traversable (Shape n), Unbox a) => Vector (Shape n a) -> (Int, Shape n (Vector a)) reShapeVector :: (UnBoxedShapeMorphism n a, Traversable (Shape n), Unbox a) => (Int, Shape n (Vector a)) -> Vector (Shape n a) -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and collect the results. For a version that -- ignores the results see traverse_. traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) instance Data.Vector.Unboxed.Base.Unbox a => Numerical.Array.Shape.UnBoxedShapeMorphism 'Numerical.Nat.Z a instance Data.Vector.Unboxed.Base.Unbox a => Numerical.Array.Shape.UnBoxedShapeMorphism ('Numerical.Nat.S 'Numerical.Nat.Z) a instance (Data.Vector.Unboxed.Base.Unbox a, Numerical.Array.Shape.UnBoxedShapeMorphism ('Numerical.Nat.S n) a) => Numerical.Array.Shape.UnBoxedShapeMorphism ('Numerical.Nat.S ('Numerical.Nat.S n)) a instance (Data.Data.Data a, Data.Typeable.Internal.Typeable 'Numerical.Nat.Z) => Data.Data.Data (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance (Data.Data.Data a, Data.Data.Data (Numerical.Array.Shape.Shape n a), Data.Typeable.Internal.Typeable ('Numerical.Nat.S n)) => Data.Data.Data (Numerical.Array.Shape.Shape ('Numerical.Nat.S n) a) instance GHC.Classes.Eq (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance (GHC.Classes.Eq a, GHC.Classes.Eq (Numerical.Array.Shape.Shape s a)) => GHC.Classes.Eq (Numerical.Array.Shape.Shape ('Numerical.Nat.S s) a) instance GHC.Show.Show (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance (GHC.Show.Show a, GHC.Show.Show (Numerical.Array.Shape.Shape s a)) => GHC.Show.Show (Numerical.Array.Shape.Shape ('Numerical.Nat.S s) a) instance Data.Traversable.Traversable (Numerical.Array.Shape.Shape 'Numerical.Nat.Z) instance Data.Traversable.Traversable (Numerical.Array.Shape.Shape ('Numerical.Nat.S 'Numerical.Nat.Z)) instance Data.Traversable.Traversable (Numerical.Array.Shape.Shape ('Numerical.Nat.S n)) => Data.Traversable.Traversable (Numerical.Array.Shape.Shape ('Numerical.Nat.S ('Numerical.Nat.S n))) instance GHC.Base.Functor (Numerical.Array.Shape.Shape 'Numerical.Nat.Z) instance GHC.Base.Functor (Numerical.Array.Shape.Shape r) => GHC.Base.Functor (Numerical.Array.Shape.Shape ('Numerical.Nat.S r)) instance GHC.Base.Applicative (Numerical.Array.Shape.Shape 'Numerical.Nat.Z) instance GHC.Base.Applicative (Numerical.Array.Shape.Shape r) => GHC.Base.Applicative (Numerical.Array.Shape.Shape ('Numerical.Nat.S r)) instance Data.Foldable.Foldable (Numerical.Array.Shape.Shape 'Numerical.Nat.Z) instance Data.Foldable.Foldable (Numerical.Array.Shape.Shape ('Numerical.Nat.S 'Numerical.Nat.Z)) instance Data.Foldable.Foldable (Numerical.Array.Shape.Shape ('Numerical.Nat.S r)) => Data.Foldable.Foldable (Numerical.Array.Shape.Shape ('Numerical.Nat.S ('Numerical.Nat.S r))) instance (GHC.Base.Semigroup a, GHC.Base.Applicative (Numerical.Array.Shape.Shape n)) => GHC.Base.Semigroup (Numerical.Array.Shape.Shape n a) instance (GHC.Base.Monoid a, GHC.Base.Applicative (Numerical.Array.Shape.Shape n)) => GHC.Base.Monoid (Numerical.Array.Shape.Shape n a) instance Foreign.Storable.Storable a => Foreign.Storable.Storable (Numerical.Array.Shape.Shape ('Numerical.Nat.S 'Numerical.Nat.Z) a) instance (Foreign.Storable.Storable a, Foreign.Storable.Storable (Numerical.Array.Shape.Shape ('Numerical.Nat.S n) a)) => Foreign.Storable.Storable (Numerical.Array.Shape.Shape ('Numerical.Nat.S ('Numerical.Nat.S n)) a) instance Foreign.Storable.Storable a => Foreign.Storable.Storable (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance Data.Vector.Unboxed.Base.Unbox a => Data.Vector.Unboxed.Base.Unbox (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance Data.Vector.Unboxed.Base.Unbox a => Data.Vector.Unboxed.Base.Unbox (Numerical.Array.Shape.Shape ('Numerical.Nat.S 'Numerical.Nat.Z) a) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox (Numerical.Array.Shape.Shape ('Numerical.Nat.S n) a)) => Data.Vector.Unboxed.Base.Unbox (Numerical.Array.Shape.Shape ('Numerical.Nat.S ('Numerical.Nat.S n)) a) instance Data.Vector.Unboxed.Base.Unbox a => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance Data.Vector.Unboxed.Base.Unbox a => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Numerical.Array.Shape.Shape 'Numerical.Nat.Z a) instance Data.Vector.Unboxed.Base.Unbox a => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Numerical.Array.Shape.Shape ('Numerical.Nat.S 'Numerical.Nat.Z) a) instance Data.Vector.Unboxed.Base.Unbox a => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Numerical.Array.Shape.Shape ('Numerical.Nat.S 'Numerical.Nat.Z) a) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox (Numerical.Array.Shape.Shape ('Numerical.Nat.S n) a)) => Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector (Numerical.Array.Shape.Shape ('Numerical.Nat.S ('Numerical.Nat.S n)) a) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Vector.Unboxed.Base.Unbox (Numerical.Array.Shape.Shape ('Numerical.Nat.S n) a)) => Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector (Numerical.Array.Shape.Shape ('Numerical.Nat.S ('Numerical.Nat.S n)) a) -- | Comments for this modules module Numerical.Array.Layout.Base -- | the Layout type class class Layout form (rank :: Nat) | form -> rank -- | basicLogicalShape gives the extent of the format basicLogicalShape :: Layout form rank => form -> Shape rank Int -- | basicLogicalForm converts a given format into its "contiguous" -- analogue this is useful for supporting various address translation -- manipulation tricks efficiently. Note that any valid simple format -- should strive to ensure this is an O(1) operation. though certain -- composite Layout instances may provide a slower implementation. basicLogicalForm :: (Layout form rank, logicalForm ~ LayoutLogicalFormat form) => form -> logicalForm -- | transposedLayout transposes the format data type transposedLayout :: (Layout form rank, form ~ Transposed transform, transform ~ Transposed form) => form -> transform -- | basicCompareIndex lets you compare where two (presumably -- inbounds) Index values are in a formats ordering. The logical -- Shape of the array is not needed basicCompareIndex :: Layout form rank => p form -> Shape rank Int -> Shape rank Int -> Ordering -- | the (possibly empty) min and max of the valid addresses for a given -- format. minAddress = fmap _RangeMin . rangedFormatAddress and -- maxAddress = fmap _RangeMax . rangedFormatAddress FIXME : -- This also is a terrible name basicAddressRange :: (Layout form rank, address ~ LayoutAddress form) => form -> Maybe (Range address) -- | basicToAddress takes an Index, and tries to translate it to an -- address if its in bounds basicToAddress :: (Layout form rank, address ~ LayoutAddress form) => form -> Index rank -> Maybe address -- | basicToIndex takes an address, and always successfully -- translates it to a valid index. Behavior of invalid addresses -- constructed by a library user is unspecified. basicToIndex :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Index rank -- | basicNextAddress takes an address, and tries to compute the -- next valid address, or returns Nothing if there is no subsequent valid -- address. basicNextAddress :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Maybe address -- | basicNextIndex form ix mbeAddress computes the next -- valid index after ix if it exists. It takes a -- Maybe address as a hint for where to do the search for -- the successor. If the index is in bounds and not the last index, it -- returns both the index and the associated address. basicNextIndex :: (Layout form rank, address ~ LayoutAddress form) => form -> Index rank -> Maybe address -> Maybe (Index rank, address) basicAddressPopCount :: (Layout form rank, address ~ LayoutAddress form) => form -> Range address -> Int -- | This operation is REALLY unsafe This should ONLY be used on Formats -- that are directly paired with a Buffer or Mutable Buffer (ie a Vector) -- This operation being in this class is also kinda a hack but lets leave -- it here for now basicAddressAsInt :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Int -- | The semantics of basicAffineAddressShift form addr -- step is that when step > 0, its equivalent to iteratively -- computing basicNextAddress step times. However, the -- step size can be negative, which means it can basicAffineAddressShift :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Int -> Maybe address -- | DenseLayout only has instances for Dense array formats. this -- class will need some sprucing up for the beta, but its ok for now. NB -- that DenseLayout is really strictly meant to be used for -- optimization purposes, and not meant as a default api class Layout form rank => DenseLayout form (rank :: Nat) | form -> rank basicToDenseAddress :: DenseLayout form rank => form -> Index rank -> Address basicToDenseIndex :: DenseLayout form rank => form -> Address -> Index rank basicNextDenseAddress :: DenseLayout form rank => form -> Address -> Address basicNextDenseIndex :: DenseLayout form rank => form -> Index rank -> (Index rank, Address) -- | RectilinearLayout is the type class that supports the modle -- widely usable class of slicing operations in Numerical. for every -- instance RectilinearLayout format rank orientation, a -- corresponding RectOrientationForm form , -- RectDownRankForm form and InnerContigForm -- form type family instance should be defined -- -- The purpose of RectilinearLayout class is to provide class Layout form rank => RectilinearLayout form (rank :: Nat) (oriented :: MajorOrientation) | form -> rank oriented -- | formRectOrientation provides a runtime mechanism for reflecting -- the orientation of the format formRectOrientation :: RectilinearLayout form rank oriented => p form -> SMajorOrientation oriented -- | For rectlinearShape form==shp, we always have that -- basicLogicalShape form weaklyDominates shp. -- when strictlyDominates holds, that implies that the underlying -- array format is a rectilinear layout whose "elements" are tiles of a -- fixed size array format. For this initial release and initial set of -- applicable rectilinear array formats, the following is always true -- basicLogicalShape form == basicLogicalShape' form -- Should be O(1) always. Or more precisely O(rank) rectlinearShape :: RectilinearLayout form rank oriented => form -> Index rank unconsOuter :: (RectilinearLayout form rank oriented, 'S down ~ rank) => p form -> Shape rank a -> (a, Shape down a) consOuter :: (RectilinearLayout form rank oriented, 'S down ~ rank) => p form -> a -> Shape down a -> Shape rank a -- | majorAxisSlice fm (x,y) requires that y-x>=1, ie -- that more than one sub range wrt the major axis be selected, so that -- the logical rank of the selected array stays the same. This operation -- also preserves memory locality as applicable. O(1) / -- O(rank) majorAxisSlice :: RectilinearLayout form rank oriented => form -> (Int, Int) -> form -- | majorAxixProject form x picks a "row" with respect -- to the outer most dimension of the array format. This will -- O(1) or O(rank) majorAxisProject :: (RectilinearLayout form rank oriented, RectilinearLayout downForm subRank oriented, rank ~ 'S subRank, downForm ~ RectDownRankForm form) => form -> Int -> downForm -- | this is the nonstrided subset of general array slice notation. Invoke -- as rectilinearSlice form leastCorner greatestCorner, -- where the least and greatest corners of the sub array are determined -- by the strictlyDominates partial order on the bounds of the sub -- array. For Dense array formats, this should be O(1) or more -- precisely O(rank) For the basic Sparse array formats thus far -- the complexity should be O(size of outermost dimension), -- which could be computed by fst . unconsOuter [form] . -- rectilinearShape $ form rectlinearSlice :: (RectilinearLayout form rank oriented, RectilinearLayout icForm rank oriented, icForm ~ InnerContigForm form) => form -> Index rank -> Index rank -> icForm type family LayoutAddress (form :: *) :: * -- | every format has a "logical" sibling, that represents the address -- translation when the underlying buffer layer is contiguous and packed. -- So it could be claimed that any type that obeys -- a~LayoutLogicalFormat a is one that an be a legal -- instance of LayoutBuilder? type family LayoutLogicalFormat (form :: *) :: * type family Transposed (form :: *) :: * type family FormatStorageRep (a :: *) :: * -- | Every instance of RectilinearLayout needs to have a -- corresponding RectOrientationForm, RectDownRankForm, and -- InnerContigForm type family RectOrientationForm form :: MajorOrientation type family RectDownRankForm form :: * type family InnerContigForm form :: * data family Format lay (contiguity :: Locality) (rank :: Nat) rep -- | this is kinda a hack newtype TaggedShape (form :: *) (rank :: Nat) TaggedShape :: Shape rank Int -> TaggedShape [unTagShape] :: TaggedShape -> Shape rank Int -- | Generalized Dense Slice Projection notation, not sure if it should be -- defined in this module or elsewhere This provides a type safe -- interface for the classical general array slice notation. That said, -- its only useful for dense array formats, at least in general. For -- formats that aren't "rectilinear dense", this COULD be used as a -- description format for traversing over various rectilinear subsets of -- points though? data GDSlice (from :: Nat) (to :: Nat) :: * [GDNil] :: GDSlice 'Z 'Z [GDPick] :: Int -> !GDSlice from to -> GDSlice ( 'S from) to [GDRange] :: (Int, Int, Int) -> !GDSlice from to -> GDSlice ( 'S from) ( 'S to) [GDAll] :: !GDSlice from to -> GDSlice ( 'S from) ( 'S to) data SMajorOrientation (o :: MajorOrientation) [SRowed] :: SMajorOrientation 'Rowed [SColumned] :: SMajorOrientation 'Columned [SBlockedRow] :: SMajorOrientation 'BlockedRow [SBlockedColumn] :: SMajorOrientation 'BlockedColumn -- | these names aren't ideal, but lets punt on bikeshedding till theres -- >= 2 serious users data MajorOrientation Rowed :: MajorOrientation Columned :: MajorOrientation BlockedColumn :: MajorOrientation BlockedRow :: MajorOrientation majorCompareRightToLeft :: Ordering -> Ordering -> Ordering majorCompareLeftToRight :: Ordering -> Ordering -> Ordering shapeCompareRightToLeft :: (Foldable (Shape r), Applicative (Shape r), Ord a) => Shape r a -> Shape r a -> Ordering shapeCompareLeftToRight :: (Foldable (Shape r), Applicative (Shape r), Ord a) => Shape r a -> Shape r a -> Ordering instance Data.Data.Data Numerical.Array.Layout.Base.MajorOrientation instance (GHC.Classes.Eq (Numerical.Array.Shape.Shape rank GHC.Types.Int), Numerical.Array.Layout.Base.Layout form rank) => GHC.Classes.Ord (Numerical.Array.Layout.Base.TaggedShape form rank) instance GHC.Show.Show (Numerical.Array.Layout.Base.GDSlice 'Numerical.Nat.Z 'Numerical.Nat.Z) instance (GHC.Show.Show (Numerical.Array.Layout.Base.GDSlice f ('Numerical.Nat.S t)), GHC.Show.Show (Numerical.Array.Layout.Base.GDSlice f t)) => GHC.Show.Show (Numerical.Array.Layout.Base.GDSlice ('Numerical.Nat.S f) ('Numerical.Nat.S t)) instance GHC.Show.Show (Numerical.Array.Layout.Base.GDSlice f 'Numerical.Nat.Z) => GHC.Show.Show (Numerical.Array.Layout.Base.GDSlice ('Numerical.Nat.S f) 'Numerical.Nat.Z) instance GHC.Classes.Eq (Numerical.Array.Shape.Shape rank GHC.Types.Int) => GHC.Classes.Eq (Numerical.Array.Layout.Base.TaggedShape f rank) instance GHC.Show.Show (Numerical.Array.Shape.Shape rank GHC.Types.Int) => GHC.Show.Show (Numerical.Array.Layout.Base.TaggedShape f rank) module Numerical.Array.Layout.Sparse -- | the Layout type class class Layout form (rank :: Nat) | form -> rank -- | basicLogicalShape gives the extent of the format basicLogicalShape :: Layout form rank => form -> Shape rank Int -- | basicLogicalForm converts a given format into its "contiguous" -- analogue this is useful for supporting various address translation -- manipulation tricks efficiently. Note that any valid simple format -- should strive to ensure this is an O(1) operation. though certain -- composite Layout instances may provide a slower implementation. basicLogicalForm :: (Layout form rank, logicalForm ~ LayoutLogicalFormat form) => form -> logicalForm -- | transposedLayout transposes the format data type transposedLayout :: (Layout form rank, form ~ Transposed transform, transform ~ Transposed form) => form -> transform -- | basicCompareIndex lets you compare where two (presumably -- inbounds) Index values are in a formats ordering. The logical -- Shape of the array is not needed basicCompareIndex :: Layout form rank => p form -> Shape rank Int -> Shape rank Int -> Ordering -- | the (possibly empty) min and max of the valid addresses for a given -- format. minAddress = fmap _RangeMin . rangedFormatAddress and -- maxAddress = fmap _RangeMax . rangedFormatAddress FIXME : -- This also is a terrible name basicAddressRange :: (Layout form rank, address ~ LayoutAddress form) => form -> Maybe (Range address) -- | basicToAddress takes an Index, and tries to translate it to an -- address if its in bounds basicToAddress :: (Layout form rank, address ~ LayoutAddress form) => form -> Index rank -> Maybe address -- | basicToIndex takes an address, and always successfully -- translates it to a valid index. Behavior of invalid addresses -- constructed by a library user is unspecified. basicToIndex :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Index rank -- | basicNextAddress takes an address, and tries to compute the -- next valid address, or returns Nothing if there is no subsequent valid -- address. basicNextAddress :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Maybe address -- | basicNextIndex form ix mbeAddress computes the next -- valid index after ix if it exists. It takes a -- Maybe address as a hint for where to do the search for -- the successor. If the index is in bounds and not the last index, it -- returns both the index and the associated address. basicNextIndex :: (Layout form rank, address ~ LayoutAddress form) => form -> Index rank -> Maybe address -> Maybe (Index rank, address) basicAddressPopCount :: (Layout form rank, address ~ LayoutAddress form) => form -> Range address -> Int -- | This operation is REALLY unsafe This should ONLY be used on Formats -- that are directly paired with a Buffer or Mutable Buffer (ie a Vector) -- This operation being in this class is also kinda a hack but lets leave -- it here for now basicAddressAsInt :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Int -- | The semantics of basicAffineAddressShift form addr -- step is that when step > 0, its equivalent to iteratively -- computing basicNextAddress step times. However, the -- step size can be negative, which means it can basicAffineAddressShift :: (Layout form rank, address ~ LayoutAddress form) => form -> address -> Int -> Maybe address data DirectSparse type CSR = CompressedSparseRow type CSC = CompressedSparseColumn data CompressedSparseRow data CompressedSparseColumn data family Format lay (contiguity :: Locality) (rank :: Nat) rep data ContiguousCompressedSparseMatrix rep FormatContiguousCompressedSparseInternal :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !BufferPure rep Int -> !BufferPure rep Int -> ContiguousCompressedSparseMatrix rep [_outerDimContiguousSparseFormat] :: ContiguousCompressedSparseMatrix rep -> {-# UNPACK #-} !Int [_innerDimContiguousSparseFormat] :: ContiguousCompressedSparseMatrix rep -> {-# UNPACK #-} !Int [_innerDimIndexContiguousSparseFormat] :: ContiguousCompressedSparseMatrix rep -> !BufferPure rep Int [_outerDim2InnerDimContiguousSparseFormat] :: ContiguousCompressedSparseMatrix rep -> !BufferPure rep Int data InnerContiguousCompressedSparseMatrix rep FormatInnerContiguousCompressedSparseInternal :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !BufferPure rep Int -> !BufferPure rep Int -> !BufferPure rep Int -> InnerContiguousCompressedSparseMatrix rep [_outerDimInnerContiguousSparseFormat] :: InnerContiguousCompressedSparseMatrix rep -> {-# UNPACK #-} !Int [_innerDimInnerContiguousSparseFormat] :: InnerContiguousCompressedSparseMatrix rep -> {-# UNPACK #-} !Int [_innerDimIndexShiftInnerContiguousSparseFormat] :: InnerContiguousCompressedSparseMatrix rep -> {-# UNPACK #-} !Int [_innerDimIndexInnerContiguousSparseFormat] :: InnerContiguousCompressedSparseMatrix rep -> !BufferPure rep Int [_outerDim2InnerDimStartInnerContiguousSparseFormat] :: InnerContiguousCompressedSparseMatrix rep -> !BufferPure rep Int [_outerDim2InnerDimEndInnerContiguousSparseFormat] :: InnerContiguousCompressedSparseMatrix rep -> !BufferPure rep Int instance GHC.Show.Show (Numerical.Array.Storage.BufferPure rep GHC.Types.Int) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.DirectSparse 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) instance GHC.Show.Show (Numerical.Array.Storage.BufferPure rep GHC.Types.Int) => GHC.Show.Show (Numerical.Array.Layout.Sparse.ContiguousCompressedSparseMatrix rep) instance GHC.Show.Show (Numerical.Array.Storage.BufferPure rep GHC.Types.Int) => GHC.Show.Show (Numerical.Array.Layout.Sparse.InnerContiguousCompressedSparseMatrix rep) instance GHC.Show.Show (Numerical.Array.Layout.Sparse.ContiguousCompressedSparseMatrix rep) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.CompressedSparseRow 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) rep) instance GHC.Show.Show (Numerical.Array.Layout.Sparse.ContiguousCompressedSparseMatrix rep) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.CompressedSparseColumn 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) rep) instance GHC.Show.Show (Numerical.Array.Layout.Sparse.InnerContiguousCompressedSparseMatrix rep) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.CompressedSparseRow 'Numerical.Array.Locality.InnerContiguous ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) rep) instance GHC.Show.Show (Numerical.Array.Layout.Sparse.InnerContiguousCompressedSparseMatrix rep) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.CompressedSparseColumn 'Numerical.Array.Locality.InnerContiguous ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) rep) instance Data.Vector.Generic.Base.Vector (Numerical.Array.Storage.BufferPure rep) GHC.Types.Int => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.CompressedSparseRow 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) rep) ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) instance Data.Vector.Generic.Base.Vector (Numerical.Array.Storage.BufferPure rep) GHC.Types.Int => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.DirectSparse 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) module Numerical.Array.Layout.Dense -- | DenseLayout only has instances for Dense array formats. this -- class will need some sprucing up for the beta, but its ok for now. NB -- that DenseLayout is really strictly meant to be used for -- optimization purposes, and not meant as a default api class Layout form rank => DenseLayout form (rank :: Nat) | form -> rank basicToDenseAddress :: DenseLayout form rank => form -> Index rank -> Address basicToDenseIndex :: DenseLayout form rank => form -> Address -> Index rank basicNextDenseAddress :: DenseLayout form rank => form -> Address -> Address basicNextDenseIndex :: DenseLayout form rank => form -> Index rank -> (Index rank, Address) data Locality Contiguous :: Locality Strided :: Locality InnerContiguous :: Locality data family Format lay (contiguity :: Locality) (rank :: Nat) rep data Row data Column data Direct instance Data.Data.Data rep => Data.Data.Data (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) instance GHC.Classes.Eq (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) instance GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) instance GHC.Show.Show (Numerical.Array.Shape.Shape n GHC.Types.Int) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.InnerContiguous n rep) instance (Data.Data.Data (Numerical.Array.Shape.Shape n GHC.Types.Int), Data.Typeable.Internal.Typeable n, Data.Typeable.Internal.Typeable rep) => Data.Data.Data (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.InnerContiguous n rep) instance GHC.Show.Show (Numerical.Array.Shape.Shape n GHC.Types.Int) => GHC.Show.Show (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Strided n rep) instance (Data.Data.Data (Numerical.Array.Shape.Shape n GHC.Types.Int), Data.Typeable.Internal.Typeable n, Data.Typeable.Internal.Typeable rep) => Data.Data.Data (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Strided n rep) instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Contiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.InnerContiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Strided rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Foldable.Foldable (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Contiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Foldable.Foldable (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.InnerContiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Foldable.Foldable (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Strided rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.Contiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.InnerContiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.Strided rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Foldable.Foldable (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.Contiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Foldable.Foldable (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.InnerContiguous rank rep) rank instance (GHC.Base.Applicative (Numerical.Array.Shape.Shape rank), Data.Foldable.Foldable (Numerical.Array.Shape.Shape rank), Data.Traversable.Traversable (Numerical.Array.Shape.Shape rank)) => Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.Strided rank rep) rank instance Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) instance Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Strided ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) instance Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) instance Numerical.Array.Layout.Base.DenseLayout (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Strided ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) module Numerical.Array.Layout.Builder data BatchInit v BatchInit :: !Int -> !Either [v] (IntFun v) -> BatchInit v [batchInitSize] :: BatchInit v -> !Int [batchInitKV] :: BatchInit v -> !Either [v] (IntFun v) materializeBatchMV :: (PrimMonad m, MVector mv a) => BatchInit a -> m (mv (PrimState m) a) newtype AnyMV mv e AMV :: (forall s. mv s e) -> AnyMV mv e newtype IntFun a IntFun :: (forall m. PrimMonad m => Int -> m a) -> IntFun a fromListBI :: [a] -> BatchInit a fromVectorBI :: Vector v e => v e -> BatchInit e fromMVectorBI :: MVector mv e => AnyMV mv e -> BatchInit e class Layout form (rank :: Nat) => LayoutBuilder form (rank :: Nat) | form -> rank buildFormatM :: (LayoutBuilder form rank, store ~ FormatStorageRep form, Buffer store Int, Buffer store a, PrimMonad m) => Index rank -> proxy form -> a -> Maybe (BatchInit (Index rank, a)) -> m (form, BufferMut store (PrimState m) a) buildFormatPure :: forall store form rank proxy m a. (LayoutBuilder form (rank :: Nat), store ~ FormatStorageRep form, Buffer store Int, Buffer store a, Monad m) => Index rank -> proxy form -> a -> Maybe (BatchInit (Index rank, a)) -> m (form, BufferPure store a) isStrictlyMonotonicV :: Vector v e => (e -> e -> Ordering) -> v e -> Maybe Int computeRunLengths :: (Vector v e, Eq e) => v e -> [(e, Int)] computeStarts :: (Enum a, Ord a, Num b) => [(a, b)] -> a -> a -> [(a, b)] instance Numerical.Array.Layout.Builder.LayoutBuilder (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Direct 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) instance (Data.Foldable.Foldable (Numerical.Array.Shape.Shape r), Data.Traversable.Traversable (Numerical.Array.Shape.Shape r), GHC.Base.Applicative (Numerical.Array.Shape.Shape r)) => Numerical.Array.Layout.Builder.LayoutBuilder (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Row 'Numerical.Array.Locality.Contiguous r rep) r instance (Data.Foldable.Foldable (Numerical.Array.Shape.Shape r), Data.Traversable.Traversable (Numerical.Array.Shape.Shape r), GHC.Base.Applicative (Numerical.Array.Shape.Shape r)) => Numerical.Array.Layout.Builder.LayoutBuilder (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Dense.Column 'Numerical.Array.Locality.Contiguous r rep) r instance Numerical.Array.Storage.Buffer rep GHC.Types.Int => Numerical.Array.Layout.Builder.LayoutBuilder (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.DirectSparse 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S 'Numerical.Nat.Z) rep) ('Numerical.Nat.S 'Numerical.Nat.Z) instance Numerical.Array.Storage.Buffer rep GHC.Types.Int => Numerical.Array.Layout.Builder.LayoutBuilder (Numerical.Array.Layout.Base.Format Numerical.Array.Layout.Sparse.CompressedSparseRow 'Numerical.Array.Locality.Contiguous ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) rep) ('Numerical.Nat.S ('Numerical.Nat.S 'Numerical.Nat.Z)) instance GHC.Show.Show a => GHC.Show.Show (Numerical.Array.Layout.Builder.BatchInit a) instance GHC.Base.Functor Numerical.Array.Layout.Builder.BatchInit instance GHC.Base.Functor Numerical.Array.Layout.Builder.IntFun module Numerical.Array.Layout module Numerical.World -- | Every numerical algorithm runs somewhere. -- -- This could be on a CPU, a GPU, data Native data ForeignNative module Numerical.Array.Pure data family ImmArray world rep lay (view :: Locality) (rank :: Nat) el class PureArray arr (rank :: Nat) a | arr -> rank where { type family PureArrayAddress (arr :: * -> *) :: *; } -- | gives the shape, a rank length list of the dimensions basicShape :: PureArray arr rank a => arr a -> Index rank basicSparseIndexToAddress :: (PureArray arr rank a, address ~ PureArrayAddress arr) => arr a -> Index rank -> Maybe address basicAddressToIndex :: (PureArray arr rank a, address ~ PureArrayAddress arr) => arr a -> address -> Index rank -- | return the Range of valid logical addresses basicAddressRange :: (PureArray arr rank a, address ~ PureArrayAddress arr) => arr a -> Maybe (Range address) -- | gives the next valid logical address undefined on invalid addresses -- and the greatest valid address. Note that for invalid addresses in -- between minAddress and maxAddress, will return the next valid address basicNextAddress :: (PureArray arr rank a, address ~ PureArrayAddress arr) => arr a -> address -> Maybe address -- | gives the next valid array index undefined on invalid indices and the -- greatest valid index basicNextIndex :: (PureArray arr rank a, address ~ PureArrayAddress arr) => arr a -> Index rank -> Maybe address -> Maybe (Index rank, address) -- | for a given valid address, basicAddressRegion addr -- will return an AddressInterval that contains addr. This will -- be a singleton when the "maximal uniform stride interval" containing -- addr has strictly less than 3 elements. Otherwise will return -- an Address range covering the maximal interval that will have -- cardinality at least 3. basicUnsafeAddressRead :: (PureArray arr rank a, Monad m, address ~ PureArrayAddress arr) => arr a -> address -> m a -- | Yield the element at the given position. This method should not be -- called directly, use unsafeSparseRead instead. basicUnsafeSparseRead :: (PureArray arr rank a, Monad m) => arr a -> Index rank -> m (Maybe a) class PureArray arr rank a => PureDenseArray arr rank a -- | basicIndexInBounds is an O(1) bounds check. basicIndexInBounds :: PureDenseArray arr rank a => arr a -> Index rank -> Bool basicUnsafeAddressDenseRead :: (PureDenseArray arr rank a, address ~ PureArrayAddress arr, Monad m) => arr a -> address -> m a -- | Yield the element at the given position. This method should not be -- called directly, use unsafeRead instead. basicUnsafeDenseReadM :: (PureDenseArray arr rank a, Monad m) => arr a -> Index rank -> m a instance (Numerical.Array.Storage.Buffer rep el, Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format lay locality rank rep) rank) => Numerical.Array.Pure.PureArray (Numerical.Array.Pure.ImmArray Numerical.World.Native rep lay locality rank) rank el module Numerical.Array.Mutable -- | MArray is the generic data family that data family MArray world rep lay (view :: Locality) (rank :: Nat) st el class PureArray (ArrPure marr) rank a => Array marr (rank :: Nat) a | marr -> rank where { type family ArrPure (marr :: * -> * -> *) :: * -> *; type family MArrayAddress (marr :: * -> * -> *) :: *; } -- | basicUnsafeAffineAddressShift is needed to handle abstracting -- access in popcount space basicUnsafeAffineAddressShift :: (Array marr rank a, address ~ MArrayAddress marr) => marr st a -> Int -> address -> address -- | Unsafely convert a mutable Array to its immutable version without -- copying. The mutable Array may not be used after this operation. -- Assumed O(1) complexity basicUnsafeFreeze :: (Array marr rank a, PrimMonad m, arr ~ ArrPure marr, marr ~ ArrMutable arr) => marr (PrimState m) a -> m (arr a) -- | Unsafely convert a pure Array to its mutable version without copying. -- the pure array may not be used after this operation. Assumed O(1) -- complexity basicUnsafeThaw :: (Array marr rank a, PrimMonad m, marr ~ ArrMutable arr, arr ~ ArrPure marr) => arr a -> m (marr (PrimState m) a) -- | gives the shape, a rank length list of the dimensions basicShape :: Array marr rank a => marr st a -> Index rank -- | basicCardinality reports the number of manifest -- addresses/entries are in the array in a given address sub range. This -- is useful for determining when to switch from a recursive algorithm to -- a direct algorithm. Should this be renamed to something like -- basicPopCount/ basicCardinality :: (Array marr rank a, address ~ MArrayAddress marr) => marr st a -> Range address -> Int basicSparseIndexToAddress :: (Array marr rank a, address ~ MArrayAddress marr) => marr s a -> Index rank -> Maybe address -- | basicMutableAddressToIndex assumes you only give it legal -- manifest addresses basicAddressToIndex :: (Array marr rank a, address ~ MArrayAddress marr) => marr s a -> address -> Index rank -- | return the smallest and largest valid logical address basicAddressRange :: (Array marr rank a, address ~ MArrayAddress marr) => marr st a -> Maybe (Range address) -- | gives the next valid logical address undefined on invalid addresses -- and the greatest valid address. Note that for invalid addresses in -- between minAddress and maxAddress, will return the next valid address. basicSparseNextAddress :: (Array marr rank a, address ~ MArrayAddress marr) => marr st a -> address -> Maybe address -- | gives the next valid array index, the least valid index that is or basicSparseNextIndex :: (Array marr rank a, address ~ MArrayAddress marr) => marr st a -> Index rank -> Maybe address -> Maybe (Index rank, address) -- | for a given valid address, basicAddressRegion addr -- will return an AddressInterval that contains addr. This will -- be a singleton when the "maximal uniform stride interval" containing -- addr has strictly less than 3 elements. Otherwise will return -- an Address range covering the maximal interval that will have -- cardinality at least 3. basicLocalAffineAddressRegion :: (Array marr rank a, address ~ MArrayAddress marr) => marr st a -> address -> AffineRange address -- | this doesn't quite fit in this class, but thats ok, will deal with -- that later basicOverlaps :: Array marr rank a => marr st a -> marr st a -> Bool -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. This method should not be called directly, use clear -- instead. basicClear :: (Array marr rank a, PrimMonad m) => marr (PrimState m) a -> m () basicUnsafeAddressRead :: (Array marr rank a, PrimMonad m, address ~ MArrayAddress marr) => marr (PrimState m) a -> address -> m a basicUnsafeAddressWrite :: (Array marr rank a, PrimMonad m, address ~ MArrayAddress marr) => marr (PrimState m) a -> address -> a -> m () -- | Yield the element at the given position. This method should not be -- called directly, use unsafeSparseRead instead. basicUnsafeSparseRead :: (Array marr rank a, PrimMonad m) => marr (PrimState m) a -> Index rank -> m (Maybe a) class RectilinearArray marr rank a | marr -> rank where { -- | MutableRectilinearOrientation marr should equal Row or -- Column for any sane choice of instance, because every -- MutableRectilinear instance will have a notion of what the nominal -- major axix will be. The intended use case is side condition -- constraints like MutableRectilinearOrientation -- marr~Row)=> marr -> b for operations where majorAxix -- projections are correct only for Row major formats. Such as Row based -- forward/backward substitution (triangular solvers) type family MutableRectilinearOrientation marr :: *; type family MutableArrayDownRank marr (st :: *) a; -- | MutableInnerContigArray is the "meet" (minimum) of the locality level -- of marr and InnerContiguous. Thus both Contiguous and InnerContiguous -- are made InnerContiguous, and Strided stays Strided for now this makes -- sense to have in the MutableRectilinear class, though that may change. -- This could also be thought of as being the GLB (greatest lower bound) -- on locality type family MutableInnerContigArray (marr :: * -> * -> *) st a; } -- | basicSliceMajorAxis arr (x,y) returns the sub array -- of the same rank, with the outermost (ie major axis) dimension of arr -- restricted to the (x,y) is an inclusive interval, MUST satisfy x<y -- , and be a valid subinterval of the major axis of arr. basicMutableSliceMajorAxis :: (RectilinearArray marr rank a, PrimMonad m) => marr (PrimState m) a -> (Int, Int) -> m (marr (PrimState m) a) basicMutableProjectMajorAxis :: (RectilinearArray marr rank a, PrimMonad m) => marr (PrimState m) a -> Int -> m (MutableArrayDownRank marr (PrimState m) a) -- | basicMutableSlice arr ix1 ix2 picks out the (hyper) -- rectangle in dimension rank where ix1 is the minimal corner -- and ix2 basicMutableSlice :: (RectilinearArray marr rank a, PrimMonad m) => marr (PrimState m) a -> Index rank -> Index rank -> m (MutableInnerContigArray marr (PrimState m) a) class DenseArray marr rank a => DenseArrayBuilder marr rank a basicUnsafeNew :: (DenseArrayBuilder marr rank a, PrimMonad m) => Index rank -> m (marr (PrimState m) a) basicUnsafeReplicate :: (DenseArrayBuilder marr rank a, PrimMonad m) => Index rank -> a -> m (marr (PrimState m) a) class (Array marr rank a, PureDenseArray (ArrPure marr) rank a) => DenseArray marr rank a | marr -> rank -- | for Dense arrays, it is always easy to check if a given index is -- valid. this operation better have O(1) complexity or else! basicIndexInBounds :: DenseArray marr rank a => marr st a -> Index rank -> Bool -- | Yield the element at the given position. This method should not be -- called directly, use unsafeRead instead. basicUnsafeDenseRead :: (DenseArray marr rank a, PrimMonad m) => marr (PrimState m) a -> Index rank -> m a -- | Replace the element at the given position. This method should not be -- called directly, use unsafeWrite instead. basicUnsafeDenseWrite :: (DenseArray marr rank a, PrimMonad m) => marr (PrimState m) a -> Index rank -> a -> m () -- | gives the next valid logical address undefined on invalid addresses -- and the greatest valid address. Note that for invalid addresses in -- between minAddress and maxAddress, will return the next valid address. basicNextAddress :: DenseArray marr rank a => marr st a -> Address -> Address -- | gives the next valid array index undefined on invalid indices and the -- greatest valid index basicNextIndex :: DenseArray marr rank a => marr st a -> Index rank -> Index rank -- | Boxed is the type index for Buffers that use the boxed -- data structure Vector as the underlying storage representation. data Boxed -- | Unboxed is the type index for Buffers that use the -- unboxed data structure Vector as the underlying storage -- representation. data Unboxed -- | Stored is the type index for Buffers that use the -- Storable for values, in pinned byte array buffers, provided by -- Storable data Stored instance (Numerical.Array.Storage.Buffer rep el, Numerical.Array.Layout.Base.Layout (Numerical.Array.Layout.Base.Format lay locality rank rep) rank) => Numerical.Array.Mutable.Array (Numerical.Array.Mutable.MArray Numerical.World.Native rep lay locality rank) rank el