This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[clojure-package] fix docstrings in normal.clj
#14295
Merged
gigasquid
merged 1 commit into
apache:master
from
Chouffe:chouffe/clojure-package-fix-random-normal-docstring
Mar 5, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,70 +16,84 @@ | |
;; | ||
|
||
(ns org.apache.clojure-mxnet.random | ||
"Random Number interface of mxnet." | ||
(:require | ||
[org.apache.clojure-mxnet.shape :as mx-shape] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[clojure.spec.alpha :as s] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[org.apache.clojure-mxnet.shape :as mx-shape] | ||
[org.apache.clojure-mxnet.util :as util]) | ||
(:import (org.apache.mxnet Context Random))) | ||
|
||
(s/def ::low number?) | ||
(s/def ::high number?) | ||
(s/def ::low-high (fn [[low high]] (<= low high))) | ||
(s/def ::shape-vec (s/coll-of pos-int? :kind vector?)) | ||
(s/def ::ctx #(instance? Context %)) | ||
(s/def ::uniform-opts (s/keys :opt-un [::ctx])) | ||
|
||
(defn uniform | ||
"Generate uniform distribution in [low, high) with shape. | ||
low: The lower bound of distribution. | ||
high: The upper bound of distribution. | ||
shape-vec: vector shape of the ndarray generated. | ||
opts-map { | ||
ctx: Context of output ndarray, will use default context if not specified. | ||
out: Output place holder} | ||
returns: The result ndarray with generated result./" | ||
"Generate uniform distribution in [`low`, `high`) with shape. | ||
`low`: The lower bound of distribution. | ||
`high`: The upper bound of distribution. | ||
`shape-vec`: vector shape of the ndarray generated. | ||
`opts-map` { | ||
`ctx`: Context of output ndarray, will use default context if not specified. | ||
`out`: Output place holder} | ||
returns: The result ndarray with generated result. | ||
Ex: | ||
(uniform 0 1 [1 10]) | ||
(uniform -10 10 [100 100])" | ||
([low high shape-vec {:keys [ctx out] :as opts}] | ||
(util/validate! ::uniform-opts opts "Incorrect random uniform parameters") | ||
(util/validate! ::uniform-opts opts "Incorrect random uniform parameters") | ||
(util/validate! ::low low "Incorrect random uniform parameter") | ||
(util/validate! ::high high "Incorrect random uniform parameters") | ||
(util/validate! ::low-high [low high] "Incorrect random uniform parameters") | ||
(util/validate! ::shape-vec shape-vec "Incorrect random uniform parameters") | ||
(Random/uniform (float low) (float high) (mx-shape/->shape shape-vec) ctx out)) | ||
([low high shape-vec] | ||
(uniform low high shape-vec {}))) | ||
|
||
(s/def ::loc number?) | ||
(s/def ::scale number?) | ||
(s/def ::scale (s/and number? pos?)) | ||
(s/def ::normal-opts (s/keys :opt-un [::ctx])) | ||
|
||
(defn normal | ||
"Generate normal(Gaussian) distribution N(mean, stdvar^^2) with shape. | ||
loc: The standard deviation of the normal distribution | ||
scale: The upper bound of distribution. | ||
shape-vec: vector shape of the ndarray generated. | ||
opts-map { | ||
ctx: Context of output ndarray, will use default context if not specified. | ||
out: Output place holder} | ||
returns: The result ndarray with generated result./" | ||
"Generate normal (Gaussian) distribution N(mean, stdvar^^2) with shape. | ||
`loc`: Mean (centre) of the distribution. | ||
`scale`: Standard deviation (spread or width) of the distribution. | ||
`shape-vec`: vector shape of the ndarray generated. | ||
`opts-map` { | ||
`ctx`: Context of output ndarray, will use default context if not specified. | ||
`out`: Output place holder} | ||
returns: The result ndarray with generated result. | ||
Ex: | ||
(normal 0 1 [10 10]) | ||
(normal -5 4 [2 3])" | ||
([loc scale shape-vec {:keys [ctx out] :as opts}] | ||
(util/validate! ::normal-opts opts "Incorrect random normal parameters") | ||
(util/validate! ::loc loc "Incorrect random normal parameters") | ||
(util/validate! ::scale scale "Incorrect random normal parameters") | ||
(util/validate! ::shape-vec shape-vec "Incorrect random uniform parameters") | ||
(Random/normal (float loc) (float scale) (mx-shape/->shape shape-vec) ctx out)) | ||
(Random/normal (float loc) | ||
(float scale) | ||
(mx-shape/->shape shape-vec) ctx out)) | ||
([loc scale shape-vec] | ||
(normal loc scale shape-vec {}))) | ||
|
||
(s/def ::seed-state number?) | ||
(defn seed | ||
" Seed the random number generators in mxnet. | ||
This seed will affect behavior of functions in this module, | ||
as well as results from executors that contains Random number | ||
such as Dropout operators. | ||
"Seed the random number generators in mxnet. | ||
This seed will affect behavior of functions in this module, | ||
as well as results from executors that contains Random number | ||
such as Dropout operators. | ||
|
||
seed-state: The random number seed to set to all devices. | ||
`seed-state`: The random number seed to set to all devices. | ||
note: The random number generator of mxnet is by default device specific. | ||
This means if you set the same seed, the random number sequence | ||
generated from GPU0 can be different from CPU." | ||
generated from GPU0 can be different from CPU. | ||
Ex: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😍 |
||
(seed-state 42) | ||
(seed-state 42.0)" | ||
[seed-state] | ||
(util/validate! ::seed-state seed-state "Incorrect seed parameters") | ||
(Random/seed (int seed-state))) | ||
(Random/seed (int seed-state))) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples in the docstring are very nice 💯