-
---instance (RealFloat a, Ord a, Vector v a) => Normed (Vn v a) where
- -- | The infinity norm. We don't use V.maximum here because it
- -- relies on a type constraint that the vector be non-empty and I
- -- don't know how to pattern match it away.
- --
- -- Examples:
- --
- -- >>> let v1 = make3d (1,5,2)
- -- >>> norm_infty v1
- -- 5
- --
--- norm_infty (Vn v1) = realToFrac $ V.foldl max 0 v1
-
- -- | Generic p-norms. The usual norm in R^n is (norm_p 2).
- --
- -- Examples:
- --
- -- >>> let v1 = make2d (3,4)
- -- >>> norm_p 1 v1
- -- 7.0
- -- >>> norm_p 2 v1
- -- 5.0
- --
--- norm_p p (Vn v1) =
--- realToFrac $ root $ V.sum $ V.map (exponentiate . abs) v1
--- where
--- exponentiate = (** (fromIntegral p))
--- root = (** (recip (fromIntegral p)))
-
-
-
-
-
--- | Convenient constructor for 2D vectors.
+-- | Remove an element of the given vector.
+--
+-- Examples:
+--
+-- >>> import Data.Vector.Fixed (mk3)
+-- >>> let b = mk3 1 2 3 :: Vec3 Int
+-- >>> delete b 1 :: Vec2 Int
+-- fromList [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
+
+
+-- | We provide our own sum because sum relies on a Num instance
+-- from the Prelude that we don't have.