From 9593058746aaf1f5afd9ce78c1dd5d64ef7b05a6 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Mon, 20 Sep 2010 08:39:33 +0000 Subject: move deprecated funcs to Numeric.Container --- lib/Data/Packed/Vector.hs | 40 --------------- lib/Numeric/Container.hs | 91 ++++++++++++++++++++++++++++++++- lib/Numeric/LinearAlgebra/Algorithms.hs | 2 +- lib/Numeric/Matrix.hs | 75 +-------------------------- 4 files changed, 93 insertions(+), 115 deletions(-) diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs index 253f2fa..49448b2 100644 --- a/lib/Data/Packed/Vector.hs +++ b/lib/Data/Packed/Vector.hs @@ -18,14 +18,6 @@ module Data.Packed.Vector ( fromList, (|>), toList, buildVector, dim, (@>), subVector, takesV, join, --- moved to Numeric.LinearAlgebra.Linear --- constant, linspace, --- moved to Data.Packed.Matrix --- vecdisp, --- moved to Numeric.LinearAlgebra.Linear typeclass --- vectorFMax, vectorFMin, vectorFMaxIndex, vectorFMinIndex, --- vectorMax, vectorMin, - vectorMaxIndex, vectorMinIndex, mapVector, zipVector, zipVectorWith, unzipVector, unzipVectorWith, mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, fscanfVector, fprintfVector, freadVector, fwriteVector, @@ -33,9 +25,6 @@ module Data.Packed.Vector ( ) where import Data.Packed.Internal.Vector -import Numeric.GSL.Vector --- import Data.Packed.ST - import Data.Binary import Foreign.Storable import Control.Monad(replicateM) @@ -72,35 +61,6 @@ instance (Binary a, Storable a) => Binary (Vector a) where ------------------------------------------------------------------- -{- -vectorFMax :: Vector Float -> Float -vectorFMax = toScalarF Max - -vectorFMin :: Vector Float -> Float -vectorFMin = toScalarF Min - -vectorFMaxIndex :: Vector Float -> Int -vectorFMaxIndex = round . toScalarF MaxIdx - -vectorFMinIndex :: Vector Float -> Int -vectorFMinIndex = round . toScalarF MinIdx - -vectorMax :: Vector Double -> Double -vectorMax = toScalarR Max - -vectorMin :: Vector Double -> Double -vectorMin = toScalarR Min --} - -{-# DEPRECATED vectorMaxIndex "use minIdx" #-} -vectorMaxIndex :: Vector Double -> Int -vectorMaxIndex = round . toScalarR MaxIdx - -{-# DEPRECATED vectorMinIndex "use maxIdx" #-} -vectorMinIndex :: Vector Double -> Int -vectorMinIndex = round . toScalarR MinIdx - - {- | creates a Vector of the specified length using the supplied function to to map the index to the value at that index. diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index 0fecf86..8cf3e07 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs @@ -20,11 +20,14 @@ ----------------------------------------------------------------------------- module Numeric.Container ( + -- * Generic operations Container(..), + -- * Matrix product and related functions Product(..), mXm,mXv,vXm, outer, kronecker, + -- * Element conversion Convert(..), Complexable(), RealElement(), @@ -32,7 +35,11 @@ module Numeric.Container ( RealOf, ComplexOf, SingleOf, DoubleOf, IndexOf, - module Data.Complex + module Data.Complex, + -- * Deprecated + (.*),(*/),(<|>),(<->), + vectorMax,vectorMin, + vectorMaxIndex, vectorMinIndex ) where import Data.Packed @@ -397,3 +404,85 @@ type family ElementOf c type instance ElementOf (Vector a) = a type instance ElementOf (Matrix a) = a +------------------------------------------------------------ + +---------------------------------------------------- + +{-# DEPRECATED (.*) "use scale a x or scalar a * x" #-} + +-- -- | @x .* a = scale x a@ +-- (.*) :: (Linear c a) => a -> c a -> c a +infixl 7 .* +a .* x = scale a x + +---------------------------------------------------- + +{-# DEPRECATED (*/) "use scale (recip a) x or x / scalar a" #-} + +-- -- | @a *\/ x = scale (recip x) a@ +-- (*/) :: (Linear c a) => c a -> a -> c a +infixl 7 */ +v */ x = scale (recip x) v + + +------------------------------------------------ + +{-# DEPRECATED (<|>) "define operator a & b = fromBlocks[[a,b]] and use asRow/asColumn to join vectors" #-} +{-# DEPRECATED (<->) "define operator a // b = fromBlocks[[a],[b]] and use asRow/asColumn to join vectors" #-} + +class Joinable a b where + joinH :: Element t => a t -> b t -> Matrix t + joinV :: Element t => a t -> b t -> Matrix t + +instance Joinable Matrix Matrix where + joinH m1 m2 = fromBlocks [[m1,m2]] + joinV m1 m2 = fromBlocks [[m1],[m2]] + +instance Joinable Matrix Vector where + joinH m v = joinH m (asColumn v) + joinV m v = joinV m (asRow v) + +instance Joinable Vector Matrix where + joinH v m = joinH (asColumn v) m + joinV v m = joinV (asRow v) m + +infixl 4 <|> +infixl 3 <-> + +{-- - | Horizontal concatenation of matrices and vectors: + +@> (ident 3 \<-\> 3 * ident 3) \<|\> fromList [1..6.0] +(6><4) + [ 1.0, 0.0, 0.0, 1.0 + , 0.0, 1.0, 0.0, 2.0 + , 0.0, 0.0, 1.0, 3.0 + , 3.0, 0.0, 0.0, 4.0 + , 0.0, 3.0, 0.0, 5.0 + , 0.0, 0.0, 3.0, 6.0 ]@ +-} +-- (<|>) :: (Element t, Joinable a b) => a t -> b t -> Matrix t +a <|> b = joinH a b + +-- -- | Vertical concatenation of matrices and vectors. +-- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t +a <-> b = joinV a b + +------------------------------------------------------------------- + +{-# DEPRECATED vectorMin "use minElement" #-} +vectorMin :: (Container Vector t, Element t) => Vector t -> t +vectorMin = minElement + +{-# DEPRECATED vectorMax "use maxElement" #-} +vectorMax :: (Container Vector t, Element t) => Vector t -> t +vectorMax = maxElement + + +{-# DEPRECATED vectorMaxIndex "use minIndex" #-} +vectorMaxIndex :: Vector Double -> Int +vectorMaxIndex = round . toScalarR MaxIdx + +{-# DEPRECATED vectorMinIndex "use maxIndex" #-} +vectorMinIndex :: Vector Double -> Int +vectorMinIndex = round . toScalarR MinIdx + diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 28cf88f..4f6f54d 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs @@ -79,7 +79,7 @@ import Data.Packed.Matrix import Numeric.LinearAlgebra.LAPACK as LAPACK import Data.List(foldl1') import Data.Array -import Numeric.Container +import Numeric.Container hiding ((.*),(*/)) -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. class (Product t, diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs index 3d1ac94..f78e0c2 100644 --- a/lib/Numeric/Matrix.hs +++ b/lib/Numeric/Matrix.hs @@ -31,10 +31,7 @@ module Numeric.Matrix ( --module Numeric.Container, optimiseMult, -- * Operators - (<>), (<\>), - -- * Deprecated - (.*),(*/),(<|>),(<->), - vectorMax,vectorMin + (<>), (<\>) ) where ------------------------------------------------------------------- @@ -101,77 +98,9 @@ instance Mul Matrix Vector Vector where instance Mul Vector Matrix Vector where (<>) v m = flatten $ (asRow v) <> m ----------------------------------------------------- - -{-# DEPRECATED (.*) "use scale a x or scalar a * x" #-} - --- -- | @x .* a = scale x a@ --- (.*) :: (Linear c a) => a -> c a -> c a -infixl 7 .* -a .* x = scale a x - ----------------------------------------------------- - -{-# DEPRECATED (*/) "use scale (recip a) x or x / scalar a" #-} - --- -- | @a *\/ x = scale (recip x) a@ --- (*/) :: (Linear c a) => c a -> a -> c a -infixl 7 */ -v */ x = scale (recip x) v +-------------------------------------------------------- -- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD). (<\>) :: (Field a) => Matrix a -> Vector a -> Vector a infixl 7 <\> m <\> v = flatten (linearSolveSVD m (reshape 1 v)) - ------------------------------------------------- - -{-# DEPRECATED (<|>) "define operator a & b = fromBlocks[[a,b]] and use asRow/asColumn to join vectors" #-} -{-# DEPRECATED (<->) "define operator a // b = fromBlocks[[a],[b]] and use asRow/asColumn to join vectors" #-} - -class Joinable a b where - joinH :: Element t => a t -> b t -> Matrix t - joinV :: Element t => a t -> b t -> Matrix t - -instance Joinable Matrix Matrix where - joinH m1 m2 = fromBlocks [[m1,m2]] - joinV m1 m2 = fromBlocks [[m1],[m2]] - -instance Joinable Matrix Vector where - joinH m v = joinH m (asColumn v) - joinV m v = joinV m (asRow v) - -instance Joinable Vector Matrix where - joinH v m = joinH (asColumn v) m - joinV v m = joinV (asRow v) m - -infixl 4 <|> -infixl 3 <-> - -{-- - | Horizontal concatenation of matrices and vectors: - -@> (ident 3 \<-\> 3 * ident 3) \<|\> fromList [1..6.0] -(6><4) - [ 1.0, 0.0, 0.0, 1.0 - , 0.0, 1.0, 0.0, 2.0 - , 0.0, 0.0, 1.0, 3.0 - , 3.0, 0.0, 0.0, 4.0 - , 0.0, 3.0, 0.0, 5.0 - , 0.0, 0.0, 3.0, 6.0 ]@ --} --- (<|>) :: (Element t, Joinable a b) => a t -> b t -> Matrix t -a <|> b = joinH a b - --- -- | Vertical concatenation of matrices and vectors. --- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t -a <-> b = joinV a b - -------------------------------------------------------------------- - -{-# DEPRECATED vectorMin "use minElement" #-} -vectorMin :: (Container Vector t, Element t) => Vector t -> t -vectorMin = minElement - -{-# DEPRECATED vectorMax "use maxElement" #-} -vectorMax :: (Container Vector t, Element t) => Vector t -> t -vectorMax = maxElement -- cgit v1.2.3