numhask-array 0.1.1.0 → 0.2.0.0
raw patch · 6 files changed
+59/−138 lines, 6 filesdep +numhask-preludedep −ghc-typelits-natnormalisedep −numhaskdep −typelits-witnessesdep ~QuickCheckdep ~basedep ~dimensions
Dependencies added: numhask-prelude
Dependencies removed: ghc-typelits-natnormalise, numhask, typelits-witnesses
Dependency ranges changed: QuickCheck, base, dimensions, singletons
Files
- numhask-array.cabal +17/−21
- readme.md +0/−34
- src/NumHask/Array.hs +25/−30
- src/NumHask/Array/Constraints.hs +12/−46
- src/NumHask/Array/Example.hs +0/−1
- stack.yaml +5/−6
numhask-array.cabal view
@@ -1,13 +1,7 @@--- This file has been generated from package.yaml by hpack version 0.20.0.------ see: https://github.com/sol/hpack------ hash: dbff2763bd788a93f04e74c660ca7a73e5e09eac07a547a74e401cc486f17b5d- name: numhask-array-version: 0.1.1.0-synopsis: See readme.md-description: See readme.md for description.+version: 0.2.0.0+synopsis: n-dimensional arrays+description: n-dimensional arrays founded on numhask. category: project homepage: https://github.com/tonyday567/numhask-array#readme bug-reports: https://github.com/tonyday567/numhask-array/issues@@ -18,10 +12,9 @@ license-file: LICENSE tested-with: GHC==8.0.1 GHC==8.2.1 GHC==8.2.2 build-type: Simple-cabal-version: >= 1.10+cabal-version: >= 1.18 extra-source-files:- readme.md stack.yaml source-repository head@@ -32,18 +25,22 @@ hs-source-dirs: src default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax+ ghc-options:+ -Wall+ -Wcompat+ -Wincomplete-record-updates+ -Wincomplete-uni-patterns+ -Wredundant-constraints build-depends:- QuickCheck+ QuickCheck >= 2.0 && < 2.12 , adjunctions >=4.0 && <5- , base >=4.7 && <5+ , base >=4.7 && <4.12 , deepseq >=1.4.2.0 && <2- , dimensions+ , dimensions >=0.3.2.0 && <0.4 , distributive >=0.4 && <0.6- , ghc-typelits-natnormalise >=0.4 && <0.6- , numhask >=0.1.2 && <0.2+ , numhask-prelude >=0.0 && <0.1 , protolude >=0.1 && <0.3- , singletons >=2.0 && <3- , typelits-witnesses >=0.2 && <0.3+ , singletons >=2.0 && <2.5 , vector >=0.10 && <0.13 exposed-modules: NumHask.Array@@ -61,11 +58,10 @@ test default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax build-depends:- QuickCheck- , base >=4.7 && <5+ base >=4.7 && <4.12 , doctest- , numhask >=0.1.2 && <0.2 , numhask-array+ , numhask-prelude >=0.0 && <0.1 , tasty , tasty-quickcheck other-modules:
− readme.md
@@ -1,34 +0,0 @@-numhask-array-===--[](https://travis-ci.org/tonyday567/numhask-array) [](https://hackage.haskell.org/package/numhask-array) [](http://stackage.org/lts/package/numhask-array) [](http://stackage.org/nightly/package/numhask-array) --An experimental array with:--- a polymorphic container-- shape specified at the type level-- Representable instances-- [numhask](https://www.stackage.org/package/numhask) heirarchy instances--See [Examples](src/NumHask/Array/Example.hs) for the emergent API.--Workflow------```-stack build --test --ghc-options -freverse-errors-```--To try out in ghci:--```-stack ghci-> :set -XDataKinds-> :set -XOverloadedLists-> import NumHask.Prelude-> let a = [0..5] :: Array [] '[2,3] Int-> a + a-[[0, 2, 4],- [6, 8, 10]]-```-
src/NumHask/Array.hs view
@@ -16,9 +16,8 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}--- you don't need this for ghc-8.2.2--- intero cracks about it though--- and doctest as well+-- fixme+{-# OPTIONS_GHC -fno-warn-deprecations #-} {-# LANGUAGE DatatypeContexts #-} module NumHask.Array where@@ -28,19 +27,18 @@ import Data.Kind import Data.List ((!!)) import Data.Promotion.Prelude-import Data.Singletons-import Data.Singletons.TypeLits+import Data.Singletons as S+import Data.Singletons.TypeLits as S import GHC.Exts import GHC.Show import NumHask.Array.Constraints import NumHask.Prelude as P import NumHask.Shape-import Numeric.Dimensions-import Numeric.Dimensions.Idx+import Numeric.Dimensions as D import Numeric.Dimensions.XDim- import qualified Data.Singletons.Prelude as S import qualified Data.Vector as V+import qualified Protolude as Proto import qualified Test.QuickCheck as QC -- $setup@@ -63,10 +61,13 @@ -- | instance where dimensions are known at compile time newtype instance (Dimensions ds) =>- Array c ds t =+ Array c (ds :: [Nat]) t = Array { _getContainer :: c t} deriving (Functor, Foldable) +instance NFData (Array c ds t) where+ rnf a = seq a ()+ -- | instance of array where some of the dimensions are known at compile time -- it wraps an Array with some weird magic data instance Array c (xds :: [XNat]) t = forall (ds :: [Nat]).@@ -239,7 +240,7 @@ QC.Arbitrary (Vector c n a) where arbitrary = QC.frequency [(1, pure zero), (9, fromList <$> QC.vector n)] where- n = fromInteger $ natVal (Proxy :: Proxy n)+ n = fromInteger $ P.natVal (Proxy :: Proxy n) instance ( IsList (c a)@@ -254,8 +255,8 @@ QC.Arbitrary (Matrix c m n a) where arbitrary = QC.frequency [(1, pure zero), (9, fromList <$> QC.vector (m * n))] where- n = fromInteger $ natVal (Proxy :: Proxy n)- m = fromInteger $ natVal (Proxy :: Proxy m)+ n = fromInteger $ P.natVal (Proxy :: Proxy n)+ m = fromInteger $ P.natVal (Proxy :: Proxy m) -- ** Operations@@ -272,10 +273,10 @@ , CRing a , Dimensions r , Dimensions s- , Dimensions (r ++ s))+ , Dimensions ((D.++) r s)) => Array c r a -> Array c s a- -> Array c (r ++ s) a+ -> Array c ((D.++) r s) a (><) m n = tabulate (\i -> index m (take dimm i) * index n (drop dimm i)) where dimm = length (shape m)@@ -302,9 +303,6 @@ , Dimensions '[ k, n] , Dimensions '[ m, n] , Container c- , Semiring a- , Num a- , CRing a , KnownNat m , KnownNat n , KnownNat k@@ -321,19 +319,17 @@ , KnownNat m , KnownNat n , KnownNat i- , (i S.:< m) ~ 'True+ , ((S.<) i m) ~ 'True ) => Proxy i -> Matrix c m n a -> Vector c n a row i_ = unsafeRow i where- i = (fromIntegral . S.fromSing . S.singByProxy) i_+ i = (Proto.fromIntegral . S.fromSing . S.singByProxy) i_ unsafeRow :: forall c a m n. ( Container c- , KnownNat m- , KnownNat n , Dimensions '[ m, n]) => Int -> Matrix c m n a@@ -349,17 +345,17 @@ , KnownNat m , KnownNat n , KnownNat j- , (j S.:< n) ~ 'True+ , ((S.<) j n) ~ 'True ) => Proxy j -> Matrix c m n a -> Vector c m a col j_ = unsafeCol j where- j = (fromIntegral . S.fromSing . S.singByProxy) j_+ j = (Proto.fromIntegral . S.fromSing . S.singByProxy) j_ unsafeCol ::- forall c a m n. (Container c, KnownNat m, KnownNat n, Dimensions '[ m, n])+ forall c a m n. (Container c, Dimensions '[ m, n]) => Int -> Matrix c m n a -> Vector c m a@@ -398,11 +394,11 @@ type instance S.Apply AllLTSym0 l = AllLTSym1 l type instance S.Apply (AllLTSym1 l) n =- Data.Promotion.Prelude.All ((S.:>$$) n) l+ Data.Promotion.Prelude.All ((S.>@#@$$) n) l -- | ----- todo: an ambiguous type variable has snucjk in here somewhere+-- todo: an ambiguous type variable has snuck in here somewhere -- -- > slice (Proxy :: Proxy '[ '[0,1],'[2],'[1,2]]) a -- [[[10, 11]],@@ -464,7 +460,7 @@ [] md) where- s = (fromInteger . fromSing . singByProxy) s_+ s = (Proto.fromIntegral . fromSing . singByProxy) s_ md = chunkItUp [] (product $ drop s $ shape a) v -- |@@ -496,7 +492,7 @@ [] md) where- s = (fromInteger . fromSing . singByProxy) s_+ s = (Proto.fromIntegral . fromSing . singByProxy) s_ md = chunkItUp [] (product $ drop s $ shape a) v -- |@@ -524,7 +520,7 @@ concatenate s_ r@(Array vr) t@(Array vt) = Array . cconcat $ (concat . reverse . P.transpose) [rm, tm] where- s = (fromInteger . fromSing . singByProxy) s_+ s = (Proto.fromIntegral . fromSing . singByProxy) s_ rm = chunkItUp [] (product $ drop s $ shape t) vt tm = chunkItUp [] (product $ drop s $ shape r) vr @@ -549,7 +545,6 @@ => Array c s a -> Array c t a transpose (Array x) = Array x- -- | --
src/NumHask/Array/Constraints.hs view
@@ -4,12 +4,10 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-}-{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-}@@ -23,8 +21,6 @@ , Squeeze , Concatenate , IsValidTranspose- , DimShuffle- , dimShuffle , Fold , FoldAlong , TailModule@@ -33,50 +29,28 @@ ) where import Data.Singletons.Prelude hiding (Max)-import Data.Singletons.Prelude.List- ((:!!$), Drop, Filter, Head, Insert,- Length, Minimum, SplitAt, Sum, Take, ZipWith,)+import Data.Singletons.Prelude.List hiding (Transpose) import Data.Singletons.Prelude.Tuple (Fst, Snd)-import Data.Singletons.TH (promote) import Data.Singletons.TypeLits (Nat) import qualified Protolude as P-import GHC.Err (error) -#if ( __GLASGOW_HASKELL__ < 801 )-instance P.Eq Nat where- x == y = P.not (x P./= y)- x /= y = P.not (x P.== y)--instance P.Ord Nat where- x > y = P.not (x P./= y) P.&& P.not (x P.< y)- x < y = P.not (x P./= y) P.&& P.not (x P.> y)- x <= y = (x P.== y) P.|| P.not (x P.> y)- x >= y = (x P.== y) P.|| P.not (x P.< y)-#endif--(!!) :: [a] -> Nat -> a-[] !! _ = error "Data.Singletons.List.!!: index too large"-(x:xs) !! n =- if n P.== 0- then x- else xs !! (n P.- 1)- type family DropDim d a :: [b] where DropDim 0 xs = Drop 1 xs- DropDim d xs = Take (d :- 1) (Fst (SplitAt d xs)) :++ Snd (SplitAt d xs)+ DropDim d xs = Take (d - 1) (Fst (SplitAt d xs)) ++ Snd (SplitAt d xs) type family IsValidConcat i (a :: [Nat]) (b :: [Nat]) :: P.Bool where IsValidConcat _ '[] _ = 'P.False IsValidConcat _ _ '[] = 'P.False- IsValidConcat i a b = And (ZipWith (:==$) (DropDim i a) (DropDim i b))+ IsValidConcat i a b =+ And (ZipWith (==@#@$) (DropDim i a) (DropDim i b)) type family Squeeze (a :: [Nat]) where Squeeze '[] = '[]- Squeeze a = Filter ((:/=$$) 1) a+ Squeeze a = Filter ((/=@#@$$) 1) a type family IsValidTranspose (p :: [Nat]) (a :: [Nat]) :: P.Bool where IsValidTranspose p a =- (Minimum p :>= 0) :&& (Minimum a :>= 0) :&& (Sum a :== Sum p) :&& Length p :== Length a+ (Minimum p >= 0) && (Minimum a >= 0) && (Sum a == Sum p) && Length p == Length a type family Transpose a where Transpose a = Reverse a@@ -86,19 +60,19 @@ type family Concatenate i (a :: [Nat]) (b :: [Nat]) :: [Nat] where Concatenate i a b =- Take i (Fst (SplitAt (i :+ 1) a)) :++- ('[ Head (Drop i a) :+ Head (Drop i b)]) :++- Snd (SplitAt (i :+ 1) b)+ Take i (Fst (SplitAt (i + 1) a)) +++ ('[ Head (Drop i a) + Head (Drop i b)]) +++ Snd (SplitAt (i + 1) b) -- | Reduces axis i in shape s. Maintains singlton dimension type family FoldAlong i (s :: [Nat]) where FoldAlong _ '[] = '[]- FoldAlong d xs = Take d (Fst (SplitAt (d :+ 1) xs)) :++ '[ 1] :++ Snd (SplitAt (d :+ 1) xs)+ FoldAlong d xs = Take d (Fst (SplitAt (d + 1) xs)) ++ '[ 1] ++ Snd (SplitAt (d + 1) xs) -- | Reduces axis i in shape s. Does not maintain singlton dimension. type family Fold i (s :: [Nat]) where Fold _ '[] = '[]- Fold d xs = Take d (Fst (SplitAt (d :+ 1) xs)) :++ Snd (SplitAt (d :+ 1) xs)+ Fold d xs = Take d (Fst (SplitAt (d + 1) xs)) ++ Snd (SplitAt (d + 1) xs) type family TailModule i (s :: [Nat]) where TailModule _ '[] = '[]@@ -108,12 +82,4 @@ HeadModule _ '[] = '[] HeadModule d xs = (Fst (SplitAt d xs)) -$(promote- [d|- dimShuffle :: P.Eq a => [a] -> [Nat] -> [a]- dimShuffle _ [] = []- dimShuffle [] _ = []- dimShuffle (x : xs) (b : bs)- = if b P.== 0 then x : dimShuffle xs bs else- (xs !! (b P.- 1)) : dimShuffle xs bs- |])+
src/NumHask/Array/Example.hs view
@@ -39,7 +39,6 @@ ) where -import NumHask.Array as A import NumHask.Shape import NumHask.Prelude as P
stack.yaml view
@@ -1,10 +1,9 @@-resolver: nightly-2018-01-18+resolver: nightly-2018-04-04 packages:- - '.'+ - .+ - ../numhask+ - ../numhask-prelude extra-deps:- #- numhask-0.1.3- - dimensions-0.3.2.0- # - deepseq-1.4.3.0i-+ - dimensions-0.3.2.0 # not on stack