Skip to content

Commit

Permalink
Docs & website sphinx errors squished 🌦 (apache#13488)
Browse files Browse the repository at this point in the history
* fix scala ndarray docs; remove interpreter style

* fix docs error in kvstore

* remove interpreter format in examples

* remove python indicator for these non-functioning python code blocks; clears a sphinx error

* remove old table that was not being used and was triggering a sphinx error

* get rid of curly braces that was causing a pygments error

* fix ambiguous reference causing sphinx error

* nudging file for CI
  • Loading branch information
aaronmarkham authored and zhaoyao73 committed Dec 9, 2018
1 parent 833919f commit 3285084
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 204 deletions.
18 changes: 9 additions & 9 deletions docs/api/scala/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ See the [MXNet Scala API Documentation](docs/index.html#org.apache.mxnet.package
symbol.md
```


## Image Classification with the Scala Infer API
The Infer API can be used for single and batch image classification. More information can be found at the following locations:

Expand All @@ -32,20 +33,19 @@ The Infer API can be used for single and batch image classification. More inform
You can perform tensor or matrix computation in pure Scala:

```scala
scala> import org.apache.mxnet._
import org.apache.mxnet._

scala> val arr = NDArray.ones(2, 3)
arr: org.apache.mxnet.NDArray = org.apache.mxnet.NDArray@f5e74790
val arr = NDArray.ones(2, 3)
// arr: org.apache.mxnet.NDArray = org.apache.mxnet.NDArray@f5e74790

scala> arr.shape
res0: org.apache.mxnet.Shape = (2,3)
arr.shape
// org.apache.mxnet.Shape = (2,3)

scala> (arr * 2).toArray
res2: Array[Float] = Array(2.0, 2.0, 2.0, 2.0, 2.0, 2.0)
(arr * 2).toArray
// Array[Float] = Array(2.0, 2.0, 2.0, 2.0, 2.0, 2.0)

scala> (arr * 2).shape
res3: org.apache.mxnet.Shape = (2,3)
(arr * 2).shape
// org.apache.mxnet.Shape = (2,3)
```


Expand Down
98 changes: 49 additions & 49 deletions docs/api/scala/kvstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,61 @@ Let's consider a simple example. It initializes
a (`int`, `NDArray`) pair into the store, and then pulls the value out.

```scala
scala> val kv = KVStore.create("local") // create a local kv store.
scala> val shape = Shape(2,3)
scala> kv.init(3, NDArray.ones(shape)*2)
scala> val a = NDArray.zeros(shape)
scala> kv.pull(3, out = a)
scala> a.toArray
Array[Float] = Array(2.0, 2.0, 2.0, 2.0, 2.0, 2.0)
val kv = KVStore.create("local") // create a local kv store.
val shape = Shape(2,3)
kv.init(3, NDArray.ones(shape)*2)
val a = NDArray.zeros(shape)
kv.pull(3, out = a)
a.toArray
// Array[Float] = Array(2.0, 2.0, 2.0, 2.0, 2.0, 2.0)
```

### Push, Aggregation, and Updater

For any key that's been initialized, you can push a new value with the same shape to the key, as follows:

```scala
scala> kv.push(3, NDArray.ones(shape)*8)
scala> kv.pull(3, out = a) // pull out the value
scala> a.toArray
Array[Float] = Array(8.0, 8.0, 8.0, 8.0, 8.0, 8.0)
kv.push(3, NDArray.ones(shape)*8)
kv.pull(3, out = a) // pull out the value
a.toArray
// Array[Float] = Array(8.0, 8.0, 8.0, 8.0, 8.0, 8.0)
```

The data that you want to push can be stored on any device. Furthermore, you can push multiple
values into the same key, where KVStore first sums all of these
values, and then pushes the aggregated value, as follows:

```scala
scala> val gpus = Array(Context.gpu(0), Context.gpu(1), Context.gpu(2), Context.gpu(3))
scala> val b = Array(NDArray.ones(shape, gpus(0)), NDArray.ones(shape, gpus(1)), \
scala> NDArray.ones(shape, gpus(2)), NDArray.ones(shape, gpus(3)))
scala> kv.push(3, b)
scala> kv.pull(3, out = a)
scala> a.toArray
Array[Float] = Array(4.0, 4.0, 4.0, 4.0, 4.0, 4.0)
val gpus = Array(Context.gpu(0), Context.gpu(1), Context.gpu(2), Context.gpu(3))
val b = Array(NDArray.ones(shape, gpus(0)), NDArray.ones(shape, gpus(1)), \
NDArray.ones(shape, gpus(2)), NDArray.ones(shape, gpus(3)))
kv.push(3, b)
kv.pull(3, out = a)
a.toArray
// Array[Float] = Array(4.0, 4.0, 4.0, 4.0, 4.0, 4.0)
```

For each push command, KVStore applies the pushed value to the value stored by an
`updater`. The default updater is `ASSIGN`. You can replace the default to
control how data is merged.

```scala
scala> val updater = new MXKVStoreUpdater {
override def update(key: Int, input: NDArray, stored: NDArray): Unit = {
println(s"update on key $key")
stored += input * 2
}
override def dispose(): Unit = {}
}
scala> kv.setUpdater(updater)
scala> kv.pull(3, a)
scala> a.toArray
Array[Float] = Array(4.0, 4.0, 4.0, 4.0, 4.0, 4.0)
scala> kv.push(3, NDArray.ones(shape))
update on key 3
scala> kv.pull(3, a)
scala> a.toArray
Array[Float] = Array(6.0, 6.0, 6.0, 6.0, 6.0, 6.0)
val updater = new MXKVStoreUpdater {
override def update(key: Int, input: NDArray, stored: NDArray): Unit = {
println(s"update on key $key")
stored += input * 2
}
override def dispose(): Unit = {}
}
kv.setUpdater(updater)
kv.pull(3, a)
a.toArray
// Array[Float] = Array(4.0, 4.0, 4.0, 4.0, 4.0, 4.0)
kv.push(3, NDArray.ones(shape))
// update on key 3
kv.pull(3, a)
a.toArray
// Array[Float] = Array(6.0, 6.0, 6.0, 6.0, 6.0, 6.0)
```

### Pull
Expand All @@ -79,11 +79,11 @@ You've already seen how to pull a single key-value pair. Similar to the way that
pull the value into several devices with a single call.

```scala
scala> val b = Array(NDArray.ones(shape, gpus(0)), NDArray.ones(shape, gpus(1)),\
scala> NDArray.ones(shape, gpus(2)), NDArray.ones(shape, gpus(3)))
scala> kv.pull(3, outs = b)
scala> b(1).toArray
Array[Float] = Array(6.0, 6.0, 6.0, 6.0, 6.0, 6.0)
val b = Array(NDArray.ones(shape, gpus(0)), NDArray.ones(shape, gpus(1)),\
NDArray.ones(shape, gpus(2)), NDArray.ones(shape, gpus(3)))
kv.pull(3, outs = b)
b(1).toArray
// Array[Float] = Array(6.0, 6.0, 6.0, 6.0, 6.0, 6.0)
```

## List Key-Value Pairs
Expand All @@ -92,14 +92,14 @@ All of the operations that we've discussed so far are performed on a single key.
the interface for generating a list of key-value pairs. For a single device, use the following:

```scala
scala> val keys = Array(5, 7, 9)
scala> kv.init(keys, Array.fill(keys.length)(NDArray.ones(shape)))
scala> kv.push(keys, Array.fill(keys.length)(NDArray.ones(shape)))
update on key: 5
update on key: 7
update on key: 9
scala> val b = Array.fill(keys.length)(NDArray.zeros(shape))
scala> kv.pull(keys, outs = b)
scala> b(1).toArray
Array[Float] = Array(3.0, 3.0, 3.0, 3.0, 3.0, 3.0)
val keys = Array(5, 7, 9)
kv.init(keys, Array.fill(keys.length)(NDArray.ones(shape)))
kv.push(keys, Array.fill(keys.length)(NDArray.ones(shape)))
// update on key: 5
// update on key: 7
// update on key: 9
val b = Array.fill(keys.length)(NDArray.zeros(shape))
kv.pull(keys, outs = b)
b(1).toArray
// Array[Float] = Array(3.0, 3.0, 3.0, 3.0, 3.0, 3.0)
```
Loading

0 comments on commit 3285084

Please sign in to comment.