haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

Make Static vectors/matrices instance of Normed? #164

Closed sid-kap closed 8 years ago

sid-kap commented 8 years ago

I noticed that real-valued statically-sized vectors and matrices (R n and L m n) are not instances of the Normed class, so it is not possible to use the norm_0, norm_1, norm_2, norm_Inf, norm_Frob, and norm_nuclear functions on these values.

Would it be a good idea to add a Normed instance for R n and L m n? I would love to submit a PR if you believe this would be a useful addition.

albertoruiz commented 8 years ago

Yes, I think it is a good idea. Static could reexport Normed with these instances.

We can extract the arrays and work with the dynamic norms, but it is a bit ugly:

import Numeric.LinearAlgebra.Static
import qualified Numeric.LinearAlgebra as LA
λ> let m = fromList [1,2,3,4] :: M 2 2
λ> print $ (LA.norm_nuclear . extract) m
5.8309518948453
λ> let v = vector [1,2,3] :: R 3
λ> print $ (LA.norm_2 . extract) v
3.7416573867739413