-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMatTest.scala
65 lines (53 loc) · 2.99 KB
/
MatTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package neurocat
import minitest._
import cats._
import cats.implicits._
import org.nd4j.linalg.factory.Nd4j
import nd4j._
import org.nd4j.linalg.api.ops.impl.transforms.Sigmoid
import spire.std.double._
object MatTest extends SimpleTestSuite {
test("simple matrix") {
val x = Mat.randomD2[Double, 3 x 2](min = 1.0, max = 10.0)
val y = Mat.randomD2[Double, 2 x 4](min = 1.0, max = 10.0)
val y2 = Mat.randomD2[Double, 3 x 4](min = 1.0, max = 10.0)
val matcalc = implicitly[MatrixCalculus[Mat, Double]]
// Compiles
val z /*: Mat[Double, 3 x 4]*/ = matcalc.mult(x, y)
////////////////////////////////////////////////////////////////////////
// DOESN'T COMPILE... not multipliable dimensions
// val z2: Mat[Double, 2 x 4] = matcalc.mult(x, y)
// [error] val z: Mat[Double, 2 x 4] = matcalc.mult(x, y)
// [error] ^
// [error] found : neurocat.nd4j.Mat[Double,neurocat.Dim2[3,4]]
// [error] required: neurocat.nd4j.Mat[Double,neurocat.x[2,4]]
// [error] (which expands to) neurocat.nd4j.Mat[Double,neurocat.Dim2[2,4]]
// [error] val z: Mat[Double, 2 x 4] = matcalc.mult(x, y)
// [error] ^
////////////////////////////////////////////////////////////////////////
// DOESN'T COMPILE... not multipliable dimensions
// val z3 = matcalc.mult(x, y2)
// MatTest.scala:34: could not find implicit value for parameter mult: neurocat.DimMult[neurocat.x[3,2],neurocat.x[3,4]]
// [error] val z2 = matcalc.mult(x, y2)
// [error] ^
////////////////////////////////////////////////////////////////////////
// DOESN'T COMPILE ... not same dimensions (error is a bit ugly for now :D)
// val z4 = matcalc.minus(x, y)
// MatTest.scala:40: type mismatch;
// [error] found : neurocat.nd4j.Mat[Double,neurocat.x[3,2]]
// [error] (which expands to) neurocat.nd4j.Mat[Double,neurocat.Dim2[3,2]]
// [error] required: neurocat.nd4j.Mat[Double,neurocat.Dim2[_ >: 2 with 3 <: Int, _ >: 4 with 2 <: Int]]
// [error] Note: neurocat.x[3,2] <: neurocat.Dim2[_ >: 2 with 3 <: Int, _ >: 4 with 2 <: Int], but class Mat is invariant in type D.
// [error] You may wish to define D as +D instead. (SLS 4.5)
// [error] val z4 = matcalc.minus(x, y)
// [error] ^
// [error] /Users/mandubian/workspaces/mandubian/neurocat/src/test/scala/MatTest.scala:40: type mismatch;
// [error] found : neurocat.nd4j.Mat[Double,neurocat.x[2,4]]
// [error] (which expands to) neurocat.nd4j.Mat[Double,neurocat.Dim2[2,4]]
// [error] required: neurocat.nd4j.Mat[Double,neurocat.Dim2[_ >: 2 with 3 <: Int, _ >: 4 with 2 <: Int]]
// [error] Note: neurocat.x[2,4] <: neurocat.Dim2[_ >: 2 with 3 <: Int, _ >: 4 with 2 <: Int], but class Mat is invariant in type D.
// [error] You may wish to define D as +D instead. (SLS 4.5)
// [error] val z4 = matcalc.minus(x, y)
// [error] ^
}
}