X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FLinear%2FVector.hs;h=a7885e4aea628b91fdb205b232602082e52093e5;hb=d86da7a71b498a24b544ded9ad7191707fd0a123;hp=d728334db0c05d75e85b057bb01f992b008e3e9a;hpb=2d0ecad8695e129443e53311d6494b2465f1a672;p=numerical-analysis.git diff --git a/src/Linear/Vector.hs b/src/Linear/Vector.hs index d728334..a7885e4 100644 --- a/src/Linear/Vector.hs +++ b/src/Linear/Vector.hs @@ -7,7 +7,6 @@ module Linear.Vector where -import Data.List (intercalate) import Data.Vector.Fixed ( Dim, Fun(..), @@ -15,8 +14,10 @@ import Data.Vector.Fixed ( N2, N3, N4, + S, Vector(..), construct, + fromList, inspect, toList, ) @@ -24,8 +25,6 @@ import qualified Data.Vector.Fixed as V ( length, ) -import Normed - -- * Low-dimension vector wrappers. -- @@ -34,25 +33,25 @@ import Normed -- constructors, so you can pattern match out the individual -- components. -data D1 a = D1 a +data D1 a = D1 a deriving (Show, Eq) type instance Dim D1 = N1 instance Vector D1 a where inspect (D1 x) (Fun f) = f x construct = Fun D1 -data D2 a = D2 a a +data D2 a = D2 a a deriving (Show, Eq) type instance Dim D2 = N2 instance Vector D2 a where inspect (D2 x y) (Fun f) = f x y construct = Fun D2 -data D3 a = D3 a a a +data D3 a = D3 a a a deriving (Show, Eq) type instance Dim D3 = N3 instance Vector D3 a where inspect (D3 x y z) (Fun f) = f x y z construct = Fun D3 -data D4 a = D4 a a a a +data D4 a = D4 a a a a deriving (Show, Eq) type instance Dim D4 = N4 instance Vector D4 a where inspect (D4 w x y z) (Fun f) = f w x y z @@ -84,3 +83,19 @@ instance Vector D4 a where (!?) v1 idx | idx < 0 || idx >= V.length v1 = Nothing | otherwise = Just $ v1 ! idx + + +-- | Remove an element of the given vector. +-- +-- Examples: +-- +-- >>> let b = D3 1 2 3 +-- >>> delete b 1 :: D2 Int +-- D2 1 3 +-- +delete :: (Vector v a, Vector w a, Dim v ~ S (Dim w)) => v a -> Int -> w a +delete v1 idx = + fromList $ (lhalf ++ rhalf') + where + (lhalf, rhalf) = splitAt idx (toList v1) + rhalf' = tail rhalf