git.iko.soy/rowtype-yoga/purescript-linear-algebra
on master help sign in
Matrix creation. First tests and travis build
commitc3cd2a921b77c3fe2887a7000636ccd58cb6d317 authorKrzysztof Langner <klangner@gmail.com> dateTue 11 Apr 2017, 15:00 (10 years ago) parent4ddbf88
5 files changed+59−9
.travis.yml+12 bower.json+3−1 src/LinearAlgebra/Matrix.purs+17−5 test/Main.purs+9−3 test/Test/LinearAlgebra/Matrix.purs+18
.travis.ymlnew file+12
@@ -0,0 +1,12 @@
1+language: node_js
2+sudo: false
3+node_js: stable
4+install:
5+ - npm install
6+ - npm install purescript pulp bower -g
7+ - bower install
8+script:
9+ - pulp build && pulp test
10+notifications:
11+ email: false
12+
bower.json+3−1
@@ -15,9 +15,11 @@
1515 ],
1616 "dependencies": {
1717 "purescript-prelude": "^3.0.0",
18− "purescript-console": "^3.0.0"
18+ "purescript-arrays": "^4.0.1"
1919 },
2020 "devDependencies": {
21+ "purescript-assert": "^3.0.0",
22+ "purescript-console": "^3.0.0",
2123 "purescript-psci-support": "^3.0.0"
2224 }
2325}
src/LinearAlgebra/Matrix.purs+17−5
@@ -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
test/Main.purs+9−3
@@ -2,8 +2,14 @@ module Test.Main where
22
33import Prelude
44import Control.Monad.Eff (Eff)
5−import Control.Monad.Eff.Console (CONSOLE, log)
5+import Control.Monad.Eff.Console (CONSOLE)
66
7−main :: forall e. Eff (console :: CONSOLE | e) Unit
7+import Test.Assert (ASSERT)
8+
9+import Test.LinearAlgebra.Matrix (testMatrix)
10+
11+
12+main :: ∀ eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
813main = do
9− log "You should add some tests."
14+ testMatrix
15+
test/Test/LinearAlgebra/Matrix.pursnew file+18
@@ -0,0 +1,18 @@
1+module Test.LinearAlgebra.Matrix (testMatrix) where
2+
3+import Prelude
4+import Control.Monad.Eff (Eff)
5+import Control.Monad.Eff.Console (log, CONSOLE)
6+import Test.Assert (assert, ASSERT)
7+import LinearAlgebra.Matrix as M
8+
9+
10+testMatrix :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
11+testMatrix = do
12+
13+ log "Init Matrix test case data"
14+ let z1 = M.zeros 5 4
15+
16+ log "Create zero matrix"
17+ assert $ z1.nrows == 5
18+ assert $ z1.ncols == 4