From 4956048a11b9d439fc72405cdb52796655b391fb Mon Sep 17 00:00:00 2001 From: Alexander Stoyakin Date: Tue, 8 Oct 2019 17:38:43 +0300 Subject: [PATCH] Tests added Signed-off-by: Alexander Stoyakin --- .../main/scala/org/nd4s/samediff/SameDiff.scala | 14 ++++---------- .../org/nd4s/samediff/implicits/Implicits.scala | 3 +++ .../test/scala/org/nd4s/samediff/MathTest.scala | 17 ++++++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/nd4s/src/main/scala/org/nd4s/samediff/SameDiff.scala b/nd4s/src/main/scala/org/nd4s/samediff/SameDiff.scala index de14258b9..801309c85 100644 --- a/nd4s/src/main/scala/org/nd4s/samediff/SameDiff.scala +++ b/nd4s/src/main/scala/org/nd4s/samediff/SameDiff.scala @@ -54,9 +54,9 @@ class SameDiffWrapper { sd.placeHolder(name, dataType, shape: _*) } -case class SDIndexWrapper(start: Long) { +case class SDIndexWrapper(end: Long) { - def ::(end: Long): SDIndex = + def ::(start: Long): SDIndex = SDIndex.interval(start, end) } @@ -75,18 +75,12 @@ class SDVariableWrapper { thisVariable = variable } + // Indexing def apply(index: Long): SDVariable = thisVariable.get(SDIndex.point(index)) def apply(index: SDIndex*): SDVariable = thisVariable.get(index: _*) - /*def apply(x: SDIndex, y: SDIndex): SDVariable = - (x, y) match { - case (_, y) => thisVariable.get(SDIndex.all(), y) - case (x, _) => thisVariable.get(x, SDIndex.all()) - case (_, _) => thisVariable.get(SDIndex.all(), SDIndex.all()) - case (x, y) => thisVariable.get(x, y) - }*/ - + // Arithmetic def add(other: Double): Unit = thisVariable.add(other) def *(other: SDVariable): SDVariable = diff --git a/nd4s/src/main/scala/org/nd4s/samediff/implicits/Implicits.scala b/nd4s/src/main/scala/org/nd4s/samediff/implicits/Implicits.scala index 0673cb3d8..004cb6703 100644 --- a/nd4s/src/main/scala/org/nd4s/samediff/implicits/Implicits.scala +++ b/nd4s/src/main/scala/org/nd4s/samediff/implicits/Implicits.scala @@ -48,4 +48,7 @@ object Implicits { val result = new SDIndexWrapper(start) result } + + implicit def LongToPoint(x: Long): SDIndex = + SDIndex.point(x) } diff --git a/nd4s/src/test/scala/org/nd4s/samediff/MathTest.scala b/nd4s/src/test/scala/org/nd4s/samediff/MathTest.scala index c82d1b45c..890f70853 100644 --- a/nd4s/src/test/scala/org/nd4s/samediff/MathTest.scala +++ b/nd4s/src/test/scala/org/nd4s/samediff/MathTest.scala @@ -219,16 +219,19 @@ class MathTest extends FlatSpec with Matchers { val x = sd.bind(arr) - println(x(SDIndex.point(0), ---).getArr) + x(0, ---).eval shouldBe x(SDIndex.point(0), SDIndex.all()).eval - val data1 = x(SDIndex.interval(0: Long, 2: Long), ---).getArr - println(data1) + val slice1 = x.get(SDIndex.interval(0, 2), SDIndex.all()).eval + val slice2 = x(0 :: 2, ---).eval + slice1 shouldBe slice2 + } - val data2 = x(0 :: 2, ---).getArr - println(data2) + "SDVariable " should "be indexable in 3d" in { + implicit val sd = SameDiff.create - //assert(indices.indices == List(0, 1, 2, 3, 4, 5)) - //assert(indices.targetShape.toList == List(2, 3)) + val arr = Nd4j.linspace(DataType.FLOAT, 1.0, 1.0, 18).reshape(3, 3, 2) + val x = sd.bind(arr) + println(x(0,0,SDIndex.all()).eval) } }