git.iko.soy/rowtype-yoga/purescript-linear-algebra
on master help sign in
Fixed to work with PureScript 0.12
a48264elogiclogue
test/Main.purs+3−6
@@ -1,19 +1,16 @@
1module Test.Main where
1module Test.Main where
2
2
3import Prelude
3import Prelude
4−import Control.Monad.Eff (Eff)
4+import Effect (Effect)
5−import Control.Monad.Eff.Console (CONSOLE)
6−
7−import Test.Assert (ASSERT)
8
5
9import Test.LinearAlgebra.Matrix (testMatrix)
6import Test.LinearAlgebra.Matrix (testMatrix)
10import Test.LinearAlgebra.Vector (testVector)
7import Test.LinearAlgebra.Vector (testVector)
11import Test.PerfTest (perfTests)
8import Test.PerfTest (perfTests)
12
9
13
10
14−main :: ∀ eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
11+main :: Effect Unit
15main = do
12main = do
16 testMatrix
13 testMatrix
17 testVector
14 testVector
18 perfTests
15 perfTests
19−
16+
test/Test/LinearAlgebra/Matrix.purs+18−18
@@ -1,15 +1,15 @@
1module Test.LinearAlgebra.Matrix (testMatrix) where
1module Test.LinearAlgebra.Matrix (testMatrix) where
2
2
3import Prelude
3import Prelude
4−import Control.Monad.Eff (Eff)
4+import Effect (Effect)
5−import Control.Monad.Eff.Console (log, CONSOLE)
5+import Effect.Class.Console (log)
6import Data.Maybe (Maybe(..), fromMaybe, isJust, isNothing)
6import Data.Maybe (Maybe(..), fromMaybe, isJust, isNothing)
7−import Test.Assert (assert, ASSERT)
7+import Test.Assert (assert)
8
8
9import LinearAlgebra.Matrix as M
9import LinearAlgebra.Matrix as M
10
10
11
11
12−testMatrix :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
12+testMatrix :: Effect Unit
13testMatrix = do
13testMatrix = do
14 log "\n# Test Matrix"
14 log "\n# Test Matrix"
15 testCreate
15 testCreate
@@ -28,7 +28,7 @@ testMatrix = do
28 testIdentity
28 testIdentity
29
29
30
30
31−testCreate :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
31+testCreate :: Effect Unit
32testCreate = do
32testCreate = do
33 log " * Create matrix"
33 log " * Create matrix"
34 let z1 = M.zeros 5 4
34 let z1 = M.zeros 5 4
@@ -36,49 +36,49 @@ testCreate = do
36 assert $ M.ncols z1 == 4
36 assert $ M.ncols z1 == 4
37
37
38
38
39−testFromArray :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
39+testFromArray :: Effect Unit
40testFromArray = do
40testFromArray = do
41 log " * From Array"
41 log " * From Array"
42 assert $ isNothing (M.fromArray 2 3 [1.0])
42 assert $ isNothing (M.fromArray 2 3 [1.0])
43 assert $ isJust (M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
43 assert $ isJust (M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
44
44
45
45
46−testGetRow :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
46+testGetRow :: Effect Unit
47testGetRow = do
47testGetRow = do
48 log " * Get specific row"
48 log " * Get specific row"
49 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
49 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
50 assert $ M.row 0 mat == [1.0, 2.0, 3.0]
50 assert $ M.row 0 mat == [1.0, 2.0, 3.0]
51
51
52
52
53−testGetCol :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
53+testGetCol :: Effect Unit
54testGetCol = do
54testGetCol = do
55 log " * Get specific column"
55 log " * Get specific column"
56 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
56 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
57 assert $ M.column 1 mat == [2.0, 5.0]
57 assert $ M.column 1 mat == [2.0, 5.0]
58
58
59
59
60−testGetValue :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
60+testGetValue :: Effect Unit
61testGetValue = do
61testGetValue = do
62 log " * Get specific value"
62 log " * Get specific value"
63 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
63 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
64 assert $ M.element 1 2 mat == Just 6.0
64 assert $ M.element 1 2 mat == Just 6.0
65
65
66
66
67−testRows :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
67+testRows :: Effect Unit
68testRows = do
68testRows = do
69 log " * Get list of rows"
69 log " * Get list of rows"
70 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
70 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
71 assert $ M.rows mat == [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
71 assert $ M.rows mat == [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
72
72
73
73
74−testColumns :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
74+testColumns :: Effect Unit
75testColumns = do
75testColumns = do
76 log " * Get list of columns"
76 log " * Get list of columns"
77 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
77 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
78 assert $ M.columns mat == [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]
78 assert $ M.columns mat == [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]
79
79
80
80
81−testSliceColumns :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
81+testSliceColumns :: Effect Unit
82testSliceColumns = do
82testSliceColumns = do
83 log " * Slice columns"
83 log " * Slice columns"
84 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
84 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
@@ -86,7 +86,7 @@ testSliceColumns = do
86 assert $ M.sliceCols 0 1 mat == expected
86 assert $ M.sliceCols 0 1 mat == expected
87
87
88
88
89−testSliceRows :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
89+testSliceRows :: Effect Unit
90testSliceRows = do
90testSliceRows = do
91 log " * Slice rows"
91 log " * Slice rows"
92 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 3 2 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
92 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 3 2 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
@@ -94,7 +94,7 @@ testSliceRows = do
94 assert $ M.sliceRows 0 1 mat == expected
94 assert $ M.sliceRows 0 1 mat == expected
95
95
96
96
97−testInsertColumn :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
97+testInsertColumn :: Effect Unit
98testInsertColumn = do
98testInsertColumn = do
99 log " * Insert column"
99 log " * Insert column"
100 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 2 [1.0, 2.0, 4.0, 5.0]
100 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 2 [1.0, 2.0, 4.0, 5.0]
@@ -104,7 +104,7 @@ testInsertColumn = do
104 assert $ M.insertCol 0 [3.0, 6.0] mat == expected2
104 assert $ M.insertCol 0 [3.0, 6.0] mat == expected2
105
105
106
106
107−testAdd :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
107+testAdd :: Effect Unit
108testAdd = do
108testAdd = do
109 log " * Multiply matrices"
109 log " * Multiply matrices"
110 let m1 = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
110 let m1 = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
@@ -112,7 +112,7 @@ testAdd = do
112 assert $ M.add m1 m1 == expected
112 assert $ M.add m1 m1 == expected
113
113
114
114
115−testMultiply :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
115+testMultiply :: Effect Unit
116testMultiply = do
116testMultiply = do
117 log " * Multiply matrices"
117 log " * Multiply matrices"
118 let m1 = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
118 let m1 = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
@@ -121,7 +121,7 @@ testMultiply = do
121 assert $ M.multiply m1 m2 == expected
121 assert $ M.multiply m1 m2 == expected
122
122
123
123
124−testTranspose :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
124+testTranspose :: Effect Unit
125testTranspose = do
125testTranspose = do
126 log " * Transpose matrix"
126 log " * Transpose matrix"
127 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
127 let mat = fromMaybe (M.zeros 1 1) $ M.fromArray 2 3 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
@@ -129,7 +129,7 @@ testTranspose = do
129 assert $ M.transpose mat == expected
129 assert $ M.transpose mat == expected
130
130
131
131
132−testIdentity :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
132+testIdentity :: Effect Unit
133testIdentity = do
133testIdentity = do
134 log " * Identity matrix"
134 log " * Identity matrix"
135 let expected = fromMaybe (M.zeros 1 1) $ M.fromArray 3 3 [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
135 let expected = fromMaybe (M.zeros 1 1) $ M.fromArray 3 3 [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
test/Test/LinearAlgebra/Vector.purs+11−11
@@ -1,15 +1,15 @@
1module Test.LinearAlgebra.Vector (testVector) where
1module Test.LinearAlgebra.Vector (testVector) where
2
2
3import Prelude
3import Prelude
4−import Control.Monad.Eff (Eff)
4+import Effect (Effect)
5−import Control.Monad.Eff.Console (log, CONSOLE)
5+import Effect.Class.Console (log)
6import Data.Maybe (Maybe(..))
6import Data.Maybe (Maybe(..))
7−import Test.Assert (assert, ASSERT)
7+import Test.Assert (assert)
8
8
9import LinearAlgebra.Vector as V
9import LinearAlgebra.Vector as V
10
10
11
11
12−testVector :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
12+testVector :: Effect Unit
13testVector = do
13testVector = do
14 log "\n# Vector tests"
14 log "\n# Vector tests"
15 testAdd
15 testAdd
@@ -20,40 +20,40 @@ testVector = do
20 testtestArgMin
20 testtestArgMin
21
21
22
22
23−testAdd :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
23+testAdd :: Effect Unit
24testAdd = do
24testAdd = do
25 log " * Add vectors"
25 log " * Add vectors"
26 assert $ V.add [1.0, 2.0, -3.0] [1.0, 1.0, 1.0, 5.0] == []
26 assert $ V.add [1.0, 2.0, -3.0] [1.0, 1.0, 1.0, 5.0] == []
27 assert $ V.add [1.0, 2.0, -3.0] [1.0, 1.0, 1.0] == [2.0, 3.0, -2.0]
27 assert $ V.add [1.0, 2.0, -3.0] [1.0, 1.0, 1.0] == [2.0, 3.0, -2.0]
28
28
29
29
30−testDifference :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
30+testDifference :: Effect Unit
31testDifference = do
31testDifference = do
32 log " * Difference"
32 log " * Difference"
33 assert $ V.diff [1.0, 2.0, -3.0] [1.0, 1.0, 1.0, 5.0] == []
33 assert $ V.diff [1.0, 2.0, -3.0] [1.0, 1.0, 1.0, 5.0] == []
34 assert $ V.diff [1.0, 2.0, -3.0] [1.0, 1.0, 1.0] == [0.0, 1.0, -4.0]
34 assert $ V.diff [1.0, 2.0, -3.0] [1.0, 1.0, 1.0] == [0.0, 1.0, -4.0]
35
35
36
36
37−testDot :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
37+testDot :: Effect Unit
38testDot = do
38testDot = do
39 log " * Dot product"
39 log " * Dot product"
40 assert $ V.dot [1.0, 2.0, -3.0] [1.0, 2.0, 1.0] == Just 2.0
40 assert $ V.dot [1.0, 2.0, -3.0] [1.0, 2.0, 1.0] == Just 2.0
41
41
42
42
43−testMulScalar :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
43+testMulScalar :: Effect Unit
44testMulScalar = do
44testMulScalar = do
45 log " * Multiply by scalar"
45 log " * Multiply by scalar"
46 assert $ V.mulScalar 2.0 [1.0, 2.0, -3.0] == [2.0, 4.0, -6.0]
46 assert $ V.mulScalar 2.0 [1.0, 2.0, -3.0] == [2.0, 4.0, -6.0]
47
47
48
48
49−testArgMax :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
49+testArgMax :: Effect Unit
50testArgMax = do
50testArgMax = do
51 log " * argmax"
51 log " * argmax"
52 assert $ V.argmax [1.0, 2.0, -3.0, 1.0, 2.0, 1.0] == 1
52 assert $ V.argmax [1.0, 2.0, -3.0, 1.0, 2.0, 1.0] == 1
53
53
54
54
55−testtestArgMin :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
55+testtestArgMin :: Effect Unit
56testtestArgMin = do
56testtestArgMin = do
57 log " * argmin"
57 log " * argmin"
58 assert $ V.argmin [1.0, 2.0, -3.0, 1.0, 2.0, 1.0] == 2
58 assert $ V.argmin [1.0, 2.0, -3.0, 1.0, 2.0, 1.0] == 2
59−
59+
test/Test/PerfTest.purs+4−4
@@ -1,16 +1,16 @@
1module Test.PerfTest (perfTests) where
1module Test.PerfTest (perfTests) where
2
2
3import Prelude
3import Prelude
4−import Control.Monad.Eff (Eff)
4+import Effect (Effect)
5−import Control.Monad.Eff.Console (log, CONSOLE)
5+import Effect.Class.Console (log)
6import Data.Array as A
6import Data.Array as A
7import Data.Maybe (fromJust)
7import Data.Maybe (fromJust)
8−import Test.Assert (assert, ASSERT)
8+import Test.Assert (assert)
9import Partial.Unsafe (unsafePartial)
9import Partial.Unsafe (unsafePartial)
10import LinearAlgebra.Matrix as M
10import LinearAlgebra.Matrix as M
11
11
12
12
13−perfTests :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
13+perfTests :: Effect Unit
14perfTests = do
14perfTests = do
15
15
16 log "\n# Run Benchmarks"
16 log "\n# Run Benchmarks"