From f38aba5c0086e662a9e49043f414d03a0dacb044 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Mon, 25 May 2015 11:00:20 +0200 Subject: indexable and normed CInt elements --- packages/base/src/Numeric/LinearAlgebra/Util.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/base/src/Numeric/LinearAlgebra/Util.hs b/packages/base/src/Numeric/LinearAlgebra/Util.hs index 370ca27..2e632b7 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util.hs @@ -66,6 +66,7 @@ import Control.Monad(when) import Text.Printf import Data.List.Split(splitOn) import Data.List(intercalate) +import Foreign.C.Types(CInt) type ℝ = Double type ℕ = Int @@ -270,6 +271,14 @@ instance Normed (Matrix ℂ) norm_2 = pnorm PNorm2 norm_Inf = pnorm Infinity +instance Normed (Vector CInt) + where + norm_0 = fromIntegral . sumElements . step . abs + norm_1 = fromIntegral . norm1 + norm_2 v = sqrt . fromIntegral $ dot v v + norm_Inf = fromIntegral . normInf + + norm_Frob :: (Normed (Vector t), Element t) => Matrix t -> ℝ norm_Frob = norm_2 . flatten @@ -324,6 +333,10 @@ instance Indexable (Vector Float) Float where (!) = (@>) +instance Indexable (Vector CInt) CInt + where + (!) = (@>) + instance Indexable (Vector (Complex Double)) (Complex Double) where (!) = (@>) -- cgit v1.2.3