forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#34 from javelinjs/scala-package-l
Change Shape from Vector to an independent class
- Loading branch information
Showing
20 changed files
with
166 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
scala-package/core/src/main/scala/ml/dmlc/mxnet/Shape.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ml.dmlc.mxnet | ||
|
||
/** | ||
* Shape of [[NDArray]] or other data | ||
* @author Yizhi Liu | ||
*/ | ||
class Shape(dims: Traversable[Int]) { | ||
private val shape = dims.toVector | ||
|
||
def this(dims: Int*) = { | ||
this(dims.toVector) | ||
} | ||
|
||
def apply(dim: Int): Int = shape(dim) | ||
def size: Int = shape.size | ||
def length: Int = shape.length | ||
def drop(dim: Int): Shape = new Shape(shape.drop(dim)) | ||
def slice(from: Int, end: Int): Shape = new Shape(shape.slice(from, end)) | ||
def product: Int = shape.product | ||
def head: Int = shape.head | ||
|
||
def ++(other: Shape): Shape = new Shape(shape ++ other.shape) | ||
|
||
def toArray: Array[Int] = shape.toArray | ||
def toVector: Vector[Int] = shape | ||
|
||
override def toString(): String = s"(${shape.mkString(",")})" | ||
|
||
override def equals(o: Any): Boolean = o match { | ||
case that: Shape => | ||
that != null && that.shape.sameElements(shape) | ||
case _ => false | ||
} | ||
|
||
override def hashCode(): Int = { | ||
shape.hashCode() | ||
} | ||
} | ||
|
||
object Shape { | ||
def apply(dims: Int *): Shape = new Shape(dims: _*) | ||
def apply(dims: Traversable[Int]): Shape = new Shape(dims) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
scala-package/core/src/main/scala/ml/dmlc/mxnet/io/MXDataIter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
scala-package/core/src/main/scala/ml/dmlc/mxnet/io/NDArrayIter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
scala-package/core/src/main/scala/ml/dmlc/mxnet/io/PrefetchingIter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.