haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

diagR / diagRect documentation? #176

Open sid-kap opened 8 years ago

sid-kap commented 8 years ago

Hi,

What do the each of the arguments for diagR / diagRect functions specify? I couldn't find this in the documentation for either Numeric.LinearAlgebra or Numeric.LinearAlgebra.Numeric. If someone could give me a quick summary of this, I wouldn't mind making a PR to add this to the Haddock doc.

Here is the example usage of diagRect given in the docs:

>>> s
fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15]
>>> let d = diagRect 0 s 5 3
>>> disp 3 d
5x3
35.183  0.000  0.000
 0.000  1.477  0.000
 0.000  0.000  0.000
 0.000  0.000  0.000

What does the first argument of diagRect (which is 0 in the above example) do?

Also, regarding diagR (which has the type diagR :: forall m n k. (KnownNat m, KnownNat n, KnownNat k) => field -> vec k -> mat m n): Again, what does the first argument (which here has type field) signify?

albertoruiz commented 8 years ago

The first argument is the default value for the rest of elements not in the diagonal.

λ> diagRect 7 (fromList [1,2,3]) 4 5
(4><5)
 [ 1.0, 7.0, 7.0, 7.0, 7.0
 , 7.0, 2.0, 7.0, 7.0, 7.0
 , 7.0, 7.0, 3.0, 7.0, 7.0
 , 7.0, 7.0, 7.0, 7.0, 7.0 ]

λ> diagR 7 (vec3 1 2 3) :: L 4 5
(diag 7.0 [1.0,2.0,3.0,7.0] :: L 4 5)
λ> disp 3 it
L 4 5
1  7  7  7  7
7  2  7  7  7
7  7  3  7  7
7  7  7  7  7

I will explain it in the documentation.