Skip to content

tonyday567/numhask-array

Repository files navigation

numhask-array

https://img.shields.io/hackage/v/numhask-array.svg https://github.com/tonyday567/numhask-array/workflows/haskell-ci/badge.svg

Usage

This package provides an interface into the numhask API, and both type and value level shape manipulation routines.

:set -XRebindableSyntax
import NumHask.Prelude
import NumHask.Array

In situations where shape is only known at run-time, a clear module configuration is:

import NumHask.Array.Shape
import qualified NumHask.Array.Fixed as F
import qualified NumHask.Array.Dynamic as D

Development

:r
:set prompt "> "
:set -Wno-type-defaults
:set -Wno-unused-do-bind
:set -Wno-name-shadowing
:set -XOverloadedStrings
:set -XOverloadedLabels
:set -XRebindableSyntax
:set -XNoImplicitPrelude
:set -XDataKinds
import Data.Functor.Rep
import NumHask.Prelude
import NumHask.Array.Fixed
import NumHask.Array.Shape
import Data.FormatN
putStrLn "ok"
[1 of 4] Compiling NumHask.Array.Shape ( src/NumHask/Array/Shape.hs, interpreted ) [Flags changed]
[2 of 4] Compiling NumHask.Array.Dynamic ( src/NumHask/Array/Dynamic.hs, interpreted ) [Flags changed]
[3 of 4] Compiling NumHask.Array.Fixed ( src/NumHask/Array/Fixed.hs, interpreted ) [Flags changed]
[4 of 4] Compiling NumHask.Array    ( src/NumHask/Array.hs, interpreted ) [Flags changed]
Ok, four modules loaded.
ok

Cholesky decomposition

‘chol’ uses the Cholesky-Crout algorithm.

Example from https://rosettacode.org/wiki/Cholesky_decomposition#Haskell

a = [25, 15, -5 ,15, 18, 0 ,-5,  0, 11] :: Matrix 3 3 Double
b = [ 18, 22, 54, 42 , 22, 70, 86, 62 , 54, 86, 174, 134 , 42, 62, 134, 106] :: Matrix 4 4 Double
chol a
chol b
fmap (fixed (Just 3)) (a `mmult` recip a)
fmap (fixed (Just 3)) (b `mmult` recip b)
fmap (fixed (Just 3)) (dot sum (*) b (recip b))
[[5.0, 0.0, 0.0],
 [3.0, 3.0, 0.0],
 [-1.0, 1.0, 3.0]]
[[4.242640687119285, 0.0, 0.0, -5.102196573270443e-15],
 [5.185449728701349, 6.565905201197403, 0.0, 0.0],
 [12.727922061357857, 3.0460384954008553, 1.6497422479090704, 0.0],
 [9.899494936611667, 1.624553864213788, 1.8497110052313648, 1.3926212476456026]]
[["1.000", "0.000", "-0.000"],
 ["0.000", "1.000", "0.000"],
 ["-0.000", "0.000", "1.000"]]
[["1.000", "0.000", "-0.000", "0.000"],
 ["-0.000", "1.000", "-0.000", "0.000"],
 ["-0.000", "0.000", "1.000", "0.000"],
 ["-0.000", "0.000", "-0.000", "1.000"]]
[["1.000", "0.000", "-0.000", "0.000"],
 ["-0.000", "1.000", "-0.000", "0.000"],
 ["-0.000", "0.000", "1.000", "0.000"],
 ["-0.000", "0.000", "-0.000", "1.000"]]

About

higher-kinded numbers

Resources

License

Stars

Watchers

Forks

Packages

No packages published