hTensor 0.6.0 → 0.7.0
raw patch · 6 files changed
+38/−28 lines, 6 filesdep ~hmatrixPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hmatrix
API changes (from Hackage documentation)
- Numeric.LinearAlgebra.Array: instance (Coord t, Compat i, Fractional (NArray i t), Floating (Vector t)) => Floating (NArray i t)
- Numeric.LinearAlgebra.Array.Util: class (Element e) => Container c :: (* -> *) e
- Numeric.LinearAlgebra.Array.Util: comp :: (Container c e) => c e -> c (Complex e)
- Numeric.LinearAlgebra.Array.Util: complex :: (Container c e) => c e -> c (Complex Double)
- Numeric.LinearAlgebra.Array.Util: conj :: (Container c e) => c (Complex e) -> c (Complex e)
- Numeric.LinearAlgebra.Array.Util: fromComplex :: (Container c e) => c (Complex e) -> (c e, c e)
- Numeric.LinearAlgebra.Array.Util: real :: (Container c e) => c Double -> c e
- Numeric.LinearAlgebra.Array.Util: toComplex :: (Container c e) => (c e, c e) -> c (Complex e)
- Numeric.LinearAlgebra.Tensor: instance (Coord t) => Show (Tensor t)
+ Numeric.LinearAlgebra.Array: instance (Coord t, Compat i, Fractional (NArray i t), Floating t, Floating (Vector t)) => Floating (NArray i t)
+ Numeric.LinearAlgebra.Tensor: instance Coord t => Show (Tensor t)
- Numeric.LinearAlgebra.Array: (~>) :: (Coord t) => NArray i t -> String -> NArray i t
+ Numeric.LinearAlgebra.Array: (~>) :: Coord t => NArray i t -> String -> NArray i t
- Numeric.LinearAlgebra.Array: index :: (Coord t) => Name -> [Array t] -> Array t
+ Numeric.LinearAlgebra.Array: index :: Coord t => Name -> [Array t] -> Array t
- Numeric.LinearAlgebra.Array: listArray :: (Coord t) => [Int] -> [t] -> Array t
+ Numeric.LinearAlgebra.Array: listArray :: Coord t => [Int] -> [t] -> Array t
- Numeric.LinearAlgebra.Array: scalar :: (Coord t) => t -> NArray i t
+ Numeric.LinearAlgebra.Array: scalar :: Coord t => t -> NArray i t
- Numeric.LinearAlgebra.Array.Solve: eqnorm :: (Coord t, Coord (Complex t), Compat i, Num (NArray i t), Normed (Vector t)) => [NArray i t] -> [NArray i t]
+ Numeric.LinearAlgebra.Array.Solve: eqnorm :: (Compat i, Show (NArray i Double)) => [NArray i Double] -> [NArray i Double]
- Numeric.LinearAlgebra.Array.Solve: infoRank :: (Field t) => Matrix t -> Matrix t
+ Numeric.LinearAlgebra.Array.Solve: infoRank :: Field t => Matrix t -> Matrix t
- Numeric.LinearAlgebra.Array.Solve: mlSolve :: (Compat i, Coord t, Num (NArray i t), Normed (Vector t)) => ALSParam i t -> [NArray i t] -> [NArray i t] -> NArray i t -> ([NArray i t], [Double])
+ Numeric.LinearAlgebra.Array.Solve: mlSolve :: (Compat i, Coord t, Num (NArray i t)) => ALSParam i t -> [NArray i t] -> [NArray i t] -> NArray i t -> ([NArray i t], [Double])
- Numeric.LinearAlgebra.Array.Solve: mlSolveH :: (Compat i, Coord t, Num (NArray i t), Normed (Vector t)) => ALSParam i t -> [NArray i t] -> [NArray i t] -> ([NArray i t], [Double])
+ Numeric.LinearAlgebra.Array.Solve: mlSolveH :: (Compat i, Coord t, Num (NArray i t)) => ALSParam i t -> [NArray i t] -> [NArray i t] -> ([NArray i t], [Double])
- Numeric.LinearAlgebra.Array.Solve: solve' :: (Coord t, Compat i, Coord t1) => (Matrix t1 -> Matrix t) -> NArray i t1 -> NArray i t -> NArray i t
+ Numeric.LinearAlgebra.Array.Solve: solve' :: (Compat i, Coord t, Coord t1) => (Matrix t1 -> Matrix t) -> NArray i t1 -> NArray i t -> NArray i t
- Numeric.LinearAlgebra.Array.Solve: solveFactors :: (Coord t, Random t, Compat i, Num (NArray i t), Normed (Vector t)) => Int -> ALSParam i t -> [NArray i t] -> String -> NArray i t -> ([NArray i t], [Double])
+ Numeric.LinearAlgebra.Array.Solve: solveFactors :: (Coord t, Random t, Compat i, Num (NArray i t)) => Int -> ALSParam i t -> [NArray i t] -> String -> NArray i t -> ([NArray i t], [Double])
- Numeric.LinearAlgebra.Array.Solve: solveFactorsH :: (Coord t, Random t, Compat i, Num (NArray i t), Normed (Vector t)) => Int -> ALSParam i t -> [NArray i t] -> String -> ([NArray i t], [Double])
+ Numeric.LinearAlgebra.Array.Solve: solveFactorsH :: (Coord t, Random t, Compat i, Num (NArray i t)) => Int -> ALSParam i t -> [NArray i t] -> String -> ([NArray i t], [Double])
- Numeric.LinearAlgebra.Array.Solve: solveHomog' :: (Coord t1, Compat i, Coord t) => (Matrix t -> Matrix t1) -> NArray i t -> [Name] -> Either Double Int -> [NArray i t1]
+ Numeric.LinearAlgebra.Array.Solve: solveHomog' :: (Compat i, Coord t1, Coord t) => (Matrix t -> Matrix t1) -> NArray i t -> [Name] -> Either Double Int -> [NArray i t1]
- Numeric.LinearAlgebra.Array.Solve: solveHomog1' :: (Coord t1, Compat i, Coord t) => (Matrix t -> Matrix t1) -> NArray i t -> [Name] -> NArray i t1
+ Numeric.LinearAlgebra.Array.Solve: solveHomog1' :: (Compat i, Coord t, Coord t1) => (Matrix t -> Matrix t1) -> NArray i t -> [Name] -> NArray i t1
- Numeric.LinearAlgebra.Array.Solve: solveP' :: (Coord b) => (Matrix Double -> Matrix b) -> NArray Variant Double -> NArray Variant Double -> Name -> NArray Variant b
+ Numeric.LinearAlgebra.Array.Solve: solveP' :: Coord t => (Matrix Double -> Matrix t) -> NArray Variant Double -> NArray Variant Double -> Name -> NArray Variant t
- Numeric.LinearAlgebra.Array.Util: (~>) :: (Coord t) => NArray i t -> String -> NArray i t
+ Numeric.LinearAlgebra.Array.Util: (~>) :: Coord t => NArray i t -> String -> NArray i t
- Numeric.LinearAlgebra.Array.Util: asMatrix :: (Coord t) => NArray i t -> Matrix t
+ Numeric.LinearAlgebra.Array.Util: asMatrix :: Coord t => NArray i t -> Matrix t
- Numeric.LinearAlgebra.Array.Util: asScalar :: (Coord t) => NArray i t -> t
+ Numeric.LinearAlgebra.Array.Util: asScalar :: Coord t => NArray i t -> t
- Numeric.LinearAlgebra.Array.Util: asVector :: (Coord t) => NArray i t -> Vector t
+ Numeric.LinearAlgebra.Array.Util: asVector :: Coord t => NArray i t -> Vector t
- Numeric.LinearAlgebra.Array.Util: basisOf :: (Coord t) => NArray i t -> [NArray i t]
+ Numeric.LinearAlgebra.Array.Util: basisOf :: Coord t => NArray i t -> [NArray i t]
- Numeric.LinearAlgebra.Array.Util: class (Num (Vector t), Field t, Storable t) => Coord t
+ Numeric.LinearAlgebra.Array.Util: class (Num (Vector t), Field t, Normed Vector t) => Coord t
- Numeric.LinearAlgebra.Array.Util: compat :: (Compat a) => Idx a -> Idx a -> Bool
+ Numeric.LinearAlgebra.Array.Util: compat :: Compat a => Idx a -> Idx a -> Bool
- Numeric.LinearAlgebra.Array.Util: conformable :: (Compat i) => [[Idx i]] -> Maybe [Idx i]
+ Numeric.LinearAlgebra.Array.Util: conformable :: Compat i => [[Idx i]] -> Maybe [Idx i]
- Numeric.LinearAlgebra.Array.Util: dummyAt :: (Coord t) => Int -> NArray i t -> NArray i t
+ Numeric.LinearAlgebra.Array.Util: dummyAt :: Coord t => Int -> NArray i t -> NArray i t
- Numeric.LinearAlgebra.Array.Util: fibers :: (Coord t) => Name -> NArray i t -> Matrix t
+ Numeric.LinearAlgebra.Array.Util: fibers :: Coord t => Name -> NArray i t -> Matrix t
- Numeric.LinearAlgebra.Array.Util: formatFixed :: (Compat i) => Int -> NArray i Double -> String
+ Numeric.LinearAlgebra.Array.Util: formatFixed :: Compat i => Int -> NArray i Double -> String
- Numeric.LinearAlgebra.Array.Util: formatScaled :: (Compat i) => Int -> NArray i Double -> String
+ Numeric.LinearAlgebra.Array.Util: formatScaled :: Compat i => Int -> NArray i Double -> String
- Numeric.LinearAlgebra.Array.Util: mapArray :: (Coord b) => (Vector a -> Vector b) -> NArray i a -> NArray i b
+ Numeric.LinearAlgebra.Array.Util: mapArray :: Coord b => (Vector a -> Vector b) -> NArray i a -> NArray i b
- Numeric.LinearAlgebra.Array.Util: matrixator :: (Coord t) => NArray i t -> [Name] -> [Name] -> Matrix t
+ Numeric.LinearAlgebra.Array.Util: matrixator :: Coord t => NArray i t -> [Name] -> [Name] -> Matrix t
- Numeric.LinearAlgebra.Array.Util: matrixatorFree :: (Coord t) => NArray i t -> [Name] -> (Matrix t, [Name])
+ Numeric.LinearAlgebra.Array.Util: matrixatorFree :: Coord t => NArray i t -> [Name] -> (Matrix t, [Name])
- Numeric.LinearAlgebra.Array.Util: noIdx :: (Compat i) => NArray i t -> NArray i t
+ Numeric.LinearAlgebra.Array.Util: noIdx :: Compat i => NArray i t -> NArray i t
- Numeric.LinearAlgebra.Array.Util: opos :: (Compat a) => Idx a -> Idx a
+ Numeric.LinearAlgebra.Array.Util: opos :: Compat a => Idx a -> Idx a
- Numeric.LinearAlgebra.Array.Util: parts :: (Coord t) => NArray i t -> Name -> [NArray i t]
+ Numeric.LinearAlgebra.Array.Util: parts :: Coord t => NArray i t -> Name -> [NArray i t]
- Numeric.LinearAlgebra.Array.Util: reorder :: (Coord t) => [Name] -> NArray i t -> NArray i t
+ Numeric.LinearAlgebra.Array.Util: reorder :: Coord t => [Name] -> NArray i t -> NArray i t
- Numeric.LinearAlgebra.Array.Util: sameStructure :: (Eq i) => NArray i t1 -> NArray i t2 -> Bool
+ Numeric.LinearAlgebra.Array.Util: sameStructure :: Eq i => NArray i t1 -> NArray i t2 -> Bool
- Numeric.LinearAlgebra.Array.Util: scalar :: (Coord t) => t -> NArray i t
+ Numeric.LinearAlgebra.Array.Util: scalar :: Coord t => t -> NArray i t
- Numeric.LinearAlgebra.Array.Util: typeOf :: (Compat i) => Name -> NArray i t -> i
+ Numeric.LinearAlgebra.Array.Util: typeOf :: Compat i => Name -> NArray i t -> i
- Numeric.LinearAlgebra.Exterior: (/\) :: (Coord t) => Tensor t -> Tensor t -> Tensor t
+ Numeric.LinearAlgebra.Exterior: (/\) :: Coord t => Tensor t -> Tensor t -> Tensor t
- Numeric.LinearAlgebra.Exterior: inner :: (Coord t) => Tensor t -> Tensor t -> Tensor t
+ Numeric.LinearAlgebra.Exterior: inner :: Coord t => Tensor t -> Tensor t -> Tensor t
- Numeric.LinearAlgebra.Tensor: listTensor :: (Coord t) => [Int] -> [t] -> Tensor t
+ Numeric.LinearAlgebra.Tensor: listTensor :: Coord t => [Int] -> [t] -> Tensor t
- Numeric.LinearAlgebra.Tensor: subindex :: (Coord t) => Name -> [Tensor t] -> Tensor t
+ Numeric.LinearAlgebra.Tensor: subindex :: Coord t => Name -> [Tensor t] -> Tensor t
- Numeric.LinearAlgebra.Tensor: superindex :: (Coord t) => Name -> [Tensor t] -> Tensor t
+ Numeric.LinearAlgebra.Tensor: superindex :: Coord t => Name -> [Tensor t] -> Tensor t
Files
- hTensor.cabal +3/−3
- lib/Numeric/LinearAlgebra/Array.hs +1/−1
- lib/Numeric/LinearAlgebra/Array/Display.hs +1/−0
- lib/Numeric/LinearAlgebra/Array/Internal.hs +21/−12
- lib/Numeric/LinearAlgebra/Array/Solve.hs +9/−9
- lib/Numeric/LinearAlgebra/Array/Util.hs +3/−3
hTensor.cabal view
@@ -1,5 +1,5 @@ Name: hTensor-Version: 0.6.0+Version: 0.7.0 License: GPL License-file: LICENSE Author: Alberto Ruiz@@ -28,7 +28,7 @@ Category: Math tested-with: GHC ==6.12.1 -cabal-version: >=1.2+cabal-version: >=1.6 build-type: Simple extra-source-files:@@ -42,7 +42,7 @@ else build-depends: base < 3 - Build-Depends: hmatrix >= 0.9.3, containers, random+ Build-Depends: hmatrix == 0.10.*, containers, random hs-source-dirs: lib Exposed-modules: Numeric.LinearAlgebra.Array.Util
lib/Numeric/LinearAlgebra/Array.hs view
@@ -58,7 +58,7 @@ (/) = zipArray (/) recip = mapArray recip -instance (Coord t, Compat i, Fractional (NArray i t), Floating (Vector t)) => Floating (NArray i t) where+instance (Coord t, Compat i, Fractional (NArray i t), Floating t, Floating (Vector t)) => Floating (NArray i t) where sin = mapArray sin cos = mapArray cos tan = mapArray tan
lib/Numeric/LinearAlgebra/Array/Display.hs view
@@ -18,6 +18,7 @@ import Numeric.LinearAlgebra.Array.Internal import Data.Packed+import Numeric.Container(format) import Data.List import Text.Printf
lib/Numeric/LinearAlgebra/Array/Internal.hs view
@@ -60,18 +60,23 @@ ) where import Data.Packed+import Numeric.Container(konst)+import Data.Complex import Data.List-import Numeric.LinearAlgebra((<>),Field)+import Numeric.LinearAlgebra((<>),Field,Normed) import Control.Applicative+--import Control.Arrow ((***)) import Data.Function(on)-import Foreign(Storable)+-- import Foreign(Storable) -- import Control.Parallel.Strategies import Debug.Trace +ident n = diagRect 0 (konst 1 n) n n+ debug m f x = trace (m ++ show (f x)) x -- | Types that can be elements of the multidimensional arrays.-class (Num (Vector t), Field t, Storable t) => Coord t+class (Num (Vector t), Field t, Normed Vector t) => Coord t instance Coord Double instance Coord (Complex Double) @@ -339,15 +344,19 @@ ------------------------------------------------------------- -instance (Coord t, Coord (Complex t), Compat i, Container Vector t) => Container (NArray i) t where- toComplex (r,c) = zipArray (curry toComplex) r c- fromComplex t = let (r,c) = fromComplex (coords t)- in (mapArray (const r) t, mapArray (const c) t)- comp = mapArray comp- conj = mapArray conj- real = mapArray real- complex = mapArray complex-+-- instance (Container Vector, Compat i) => ComplexContainer (NArray i) where+-- -- cmap f (A d v) = A d (cmap f v)+-- conj (A d v) = A d (conj v)+-- complex' (A d v) = A d (complex' v) -- mapArray without constraints+-- +-- toComplex (A d1 r, A d2 c) -- zipArray without constraints+-- | d1==d2 = A d1 (toComplex (r,c))+-- | otherwise = error "toComplex on arrays with different structure"+-- +-- fromComplex (A d v) = (A d *** A d) (fromComplex v)+-- +-- single' (A d v) = A d (single' v)+-- double' (A d v) = A d (double' v) -- instance (NFData t, Element t) => NFData (NArray i t) where -- rnf = rnf . coords
lib/Numeric/LinearAlgebra/Array/Solve.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleContexts, TypeFamilies #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Packed.Array.Solve@@ -154,7 +154,7 @@ g v = v / atT v [n] n = size h t - 1 -frobT t = pnorm PNorm2 . coords $ t+frobT t = realToFrac . pnorm PNorm2 . coords $ t --unitT t = t / scalar (frobT t) dropElemPos k xs = take k xs ++ drop (k+1) xs@@ -172,7 +172,7 @@ -- | Solution of a multilinear system a x y z ... = b based on alternating least squares. mlSolve- :: (Compat i, Coord t, Num (NArray i t), Normed (Vector t))+ :: (Compat i, Coord t, Num (NArray i t)) => ALSParam i t -- ^ optimization parameters -> [NArray i t] -- ^ coefficients (a), given as a list of factors. -> [NArray i t] -- ^ initial solution [x,y,z...]@@ -192,7 +192,7 @@ -- | Solution of the homogeneous multilinear system a x y z ... = 0 based on alternating least squares. mlSolveH- :: (Compat i, Coord t, Num (NArray i t), Normed (Vector t))+ :: (Compat i, Coord t, Num (NArray i t)) => ALSParam i t -- ^ optimization parameters -> [NArray i t] -- ^ coefficients (a), given as a list of factors. -> [NArray i t] -- ^ initial solution [x,y,z...]@@ -232,7 +232,7 @@ {- | Given two arrays a (source) and b (target), we try to compute linear transformations x,y,z,... for each dimension, such that product [a,x,y,z,...] == b. (We can use 'eqnorm' for 'post' processing, or 'id'.) -}-solveFactors :: (Coord t, Random t, Compat i, Num (NArray i t), Normed (Vector t))+solveFactors :: (Coord t, Random t, Compat i, Num (NArray i t)) => Int -- ^ seed for random initialization -> ALSParam i t -- ^ optimization parameters -> [NArray i t] -- ^ source (also factorized)@@ -264,7 +264,7 @@ -- [\"pi\",\"qj\", \"rk\", etc.], we try to compute linear transformations -- x!\"pi\", y!\"pi\", z!\"rk\", etc. such that product [a,x,y,z,...] == 0. solveFactorsH- :: (Coord t, Random t, Compat i, Num (NArray i t), Normed (Vector t))+ :: (Coord t, Random t, Compat i, Num (NArray i t)) => Int -- ^ seed for random initialization -> ALSParam i t -- ^ optimization parameters -> [NArray i t] -- ^ coefficient array (a), (also factorized)@@ -287,15 +287,15 @@ -- | post processing function that modifies a list of tensors so that they -- have equal frobenius norm-eqnorm :: (Coord t, Coord (Complex t), Compat i, Num (NArray i t), Normed (Vector t) )- => [NArray i t] -> [NArray i t]+eqnorm :: (Compat i,Show (NArray i Double))+ => [NArray i Double] -> [NArray i Double] eqnorm [] = error "eqnorm []" eqnorm as = as' where n = length as fs = map (frobT) as s = product fs ** (1/fromIntegral n)- as' = zipWith g as fs where g a f = a * real (scalar (s/f))+ as' = zipWith g as fs where g a f = a * (scalar (s/f)) -- | nMax = 20, epsilon = 1E-3, delta = 1, post = id, postk = const id, presys = id defaultParameters :: ALSParam i t
lib/Numeric/LinearAlgebra/Array/Util.hs view
@@ -40,13 +40,13 @@ renameParts, asScalar, asVector, asMatrix, applyAsMatrix, fibers, matrixator, matrixatorFree, analyzeProduct,- fromVector, fromMatrix,- Container(..),+ fromVector, fromMatrix+ -- ,Container(..), ) where import Numeric.LinearAlgebra.Array.Internal import Numeric.LinearAlgebra.Array.Display-import Data.Packed(Container(..),Matrix)+import Data.Packed(Matrix) import Numeric.LinearAlgebra.Array.Simple import Data.List(intersperse,sort,foldl1')