@@ -1,16 +1,28 @@
11module LinearAlgebra.Matrix
22 ( Matrix
3+ , replicate
4+ , zeros
35 ) where
4−
6+
7+import Prelude
8+import Data.Array as A
9+
510
611-- | Dense Matrix implementation
712type Matrix a =
813 { nrows :: Int
914 , ncols :: Int
10− , data :: Array a
15+ , values :: Array a
1116 }
1217
1318
14−-- -- | Create Matrix from array of values
15−-- fromArray :: ∀ a. Array a -> Int -> Int -> Maybe (Matrix a)
16−-- fromArray ds rows cols | length ds
19+-- | Create array of given dimmension containing replicated value
20+replicate :: ∀ a. Int -> Int -> a -> Matrix a
21+replicate r c v = {nrows: r, ncols: c, values: vs}
22+ where
23+ vs = A.replicate (r * c) v
24+
25+
26+-- | Create array of given dimmension with all values set to 0
27+zeros :: Int -> Int -> Matrix Number
28+zeros r c = replicate r c 0.0