Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 3032c10

Browse files
author
Nikhil Thorat
authored
Link symbols in the doc generator. (#710)
* Links symbols together in doc generator. * Add @doclink jsdoc tag which allows you to have types with a name link to others. Used to link Tensor1D => Tensor, and other subclasses which will become aliases.
1 parent d1ed661 commit 3032c10

29 files changed

+484
-375
lines changed

src/gradients.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Gradients {
4747
* which when called gives `df/dx`. If `dy` is provided, the gradient of
4848
* `f(x).mul(dy).sum()` w.r.t. `x` is computed instead.
4949
*
50-
* If `f()` takes multiple inputs, use `dl.grads` instead.
50+
* If `f()` takes multiple inputs, use `grads` instead.
5151
*
5252
* @param f The function f(x), to compute gradient for.
5353
*/
@@ -69,7 +69,7 @@ export class Gradients {
6969
* If `dy` is provided, the gradient of `f(x).mul(dy).sum()` w.r.t. each input
7070
* is computed instead.
7171
*
72-
* If `f()` takes a single input, use `dl.grad` instead.
72+
* If `f()` takes a single input, use `grad` instead.
7373
*
7474
* @param f The function `f(x1, x2,...)` to compute gradients for.
7575
*/
@@ -88,8 +88,8 @@ export class Gradients {
8888
* Like `dl.grad`, but returns also the value of `f()`. Useful when `f()`
8989
* returns a metric you want to show. The result is a rich object with
9090
* the following properties:
91-
* - `grad`: The gradient of `f(x)` w.r.t `x` (result of `dl.grad`).
92-
* - `value`: The value returned by `f(x)`.
91+
* - grad: The gradient of `f(x)` w.r.t `x` (result of `grad`).
92+
* - value: The value returned by `f(x)`.
9393
*/
9494
@doc({heading: 'Training', subheading: 'Gradients'})
9595
static valueAndGrad<I extends Tensor, O extends Tensor>(f: (x: I) => O):
@@ -105,11 +105,11 @@ export class Gradients {
105105
}
106106

107107
/**
108-
* Like `dl.grads`, but returns also the value of `f()`. Useful when `f()`
108+
* Like `grads`, but returns also the value of `f()`. Useful when `f()`
109109
* returns a metric you want to show. The result is a rich object with
110110
* the following properties:
111-
* - `grads`: The gradients of `f()` w.r.t each input (result of `dl.grads`).
112-
* - `value`: The value returned by `f(x)`.
111+
* - grads: The gradients of `f()` w.r.t each input (result of `grads`).
112+
* - value: The value returned by `f(x)`.
113113
*/
114114
@doc({heading: 'Training', subheading: 'Gradients'})
115115
static valueAndGrads<O extends Tensor>(f: (...args: Tensor[]) => O):
@@ -130,7 +130,7 @@ export class Gradients {
130130
* defaults to all trainable variables.
131131
* @param f The function to execute. f() should return a scalar.
132132
* @param varList An optional list of variables to provide gradients with
133-
* respect to. Defaults to all trainable variables.
133+
* respect to. Defaults to all trainable variables.
134134
*/
135135
@doc({heading: 'Training', subheading: 'Gradients'})
136136
static variableGrads(f: () => Scalar, varList?: Variable[]):
@@ -169,8 +169,8 @@ export class Gradients {
169169
* using `f().gradFunc`.
170170
*
171171
* @param f The function to evaluate in forward mode, which should return
172-
* `{value: Tensor, gradFunc: (dy) => Tensor[]}`, where gradFunc returns the
173-
* custom gradients of `f` w.r.t. its inputs.
172+
* `{value: Tensor, gradFunc: (dy) => Tensor[]}`, where `gradFunc` returns
173+
* the custom gradients of `f` w.r.t. its inputs.
174174
*/
175175
@doc({heading: 'Training', subheading: 'Gradients'})
176176
static customGrad<T extends Tensor>(f: CustomGradientFunc<T>):

src/ops/array_ops.ts

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class Ops {
7474
}
7575

7676
/**
77-
* Creates rank-0 tensor (scalar) with the provided value and dtype.
77+
* Creates rank-0 `Tensor` (scalar) with the provided value and dtype.
7878
*
7979
* This method is mainly for self documentation and TypeScript typings as the
8080
* same functionality can be achieved with `tensor`. In general, we recommend
@@ -98,7 +98,7 @@ export class Ops {
9898
}
9999

100100
/**
101-
* Creates rank-1 tensor with the provided values, shape and dtype.
101+
* Creates rank-1 `Tensor` with the provided values, shape and dtype.
102102
*
103103
* This method is mainly for self documentation and TypeScript typings as the
104104
* same functionality can be achieved with `tensor`. In general, we recommend
@@ -123,7 +123,7 @@ export class Ops {
123123
}
124124

125125
/**
126-
* Creates rank-2 tensor with the provided values, shape and dtype.
126+
* Creates rank-2 `Tensor` with the provided values, shape and dtype.
127127
*
128128
* This method is mainly for self documentation and TypeScript typings as the
129129
* same functionality can be achieved with `tensor`. In general, we recommend
@@ -137,10 +137,11 @@ export class Ops {
137137
* // Pass a flat array and specify a shape.
138138
* dl.tensor2d([1, 2, 3, 4], [2, 2]).print();
139139
* ```
140+
*
140141
* @param values The values of the tensor. Can be nested array of numbers,
141142
* or a flat array, or a `TypedArray`.
142-
* @param shape The shape of the tensor. Optional. If not provided,
143-
* it is inferred from `values`.
143+
* @param shape The shape of the tensor. If not provided, it is inferred from
144+
* `values`.
144145
* @param dtype The data type.
145146
*/
146147
@doc({heading: 'Tensors', subheading: 'Creation'})
@@ -158,7 +159,7 @@ export class Ops {
158159
}
159160

160161
/**
161-
* Creates rank-3 tensor with the provided values, shape and dtype.
162+
* Creates rank-3 `Tensor` with the provided values, shape and dtype.
162163
*
163164
* This method is mainly for self documentation and TypeScript typings as
164165
* the same functionality can be achieved with `tensor`. In general, we
@@ -172,10 +173,11 @@ export class Ops {
172173
* // Pass a flat array and specify a shape.
173174
* dl.tensor3d([1, 2, 3, 4], [2, 2, 1]).print();
174175
* ```
176+
*
175177
* @param values The values of the tensor. Can be nested array of numbers,
176178
* or a flat array, or a `TypedArray`.
177-
* @param shape The shape of the tensor. Optional. If not provided,
178-
* it is inferred from `values`.
179+
* @param shape The shape of the tensor. If not provided, it is inferred from
180+
* `values`.
179181
* @param dtype The data type.
180182
*/
181183
@doc({heading: 'Tensors', subheading: 'Creation'})
@@ -193,7 +195,7 @@ export class Ops {
193195
}
194196

195197
/**
196-
* Creates rank-4 tensor with the provided values, shape and dtype.
198+
* Creates rank-4 `Tensor` with the provided values, shape and dtype.
197199
* ```js
198200
* // Pass a nested array.
199201
* dl.tensor4d([[[[1], [2]], [[3], [4]]]]).print();
@@ -202,6 +204,7 @@ export class Ops {
202204
* // Pass a flat array and specify a shape.
203205
* dl.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]).print();
204206
* ```
207+
*
205208
* @param values The values of the tensor. Can be nested array of numbers,
206209
* or a flat array, or a `TypedArray`.
207210
* @param shape The shape of the tensor. Optional. If not provided,
@@ -223,11 +226,11 @@ export class Ops {
223226
}
224227

225228
/**
226-
* Creates a tensor with all elements set to 1.
229+
* Creates a `Tensor` with all elements set to 1.
227230
*
228231
* @param shape An array of integers defining the output tensor shape.
229-
* @param dtype The type of an element in the resulting tensor. Can
230-
* be 'float32', 'int32' or 'bool'. Defaults to 'float'.
232+
* @param dtype The type of an element in the resulting tensor. Defaults to
233+
* 'float'.
231234
*/
232235
@doc({heading: 'Tensors', subheading: 'Creation'})
233236
@operation
@@ -238,7 +241,7 @@ export class Ops {
238241
}
239242

240243
/**
241-
* Creates a tensor with all elements set to 0.
244+
* Creates a `Tensor` with all elements set to 0.
242245
* @param shape An array of integers defining the output tensor shape.
243246
* @param dtype The type of an element in the resulting tensor. Can
244247
* be 'float32', 'int32' or 'bool'. Defaults to 'float'.
@@ -252,11 +255,12 @@ export class Ops {
252255
}
253256

254257
/**
255-
* Creates a tensor filled with a scalar value.
258+
* Creates a `Tensor` filled with a scalar value.
259+
*
256260
* @param shape An array of integers defining the output tensor shape.
257261
* @param value The scalar value to fill the tensor with.
258-
* @param dtype The type of an element in the resulting tensor. Can
259-
* be 'float32', 'int32' or 'bool'. Defaults to 'float'.
262+
* @param dtype The type of an element in the resulting tensor. Defaults to
263+
* 'float'.
260264
*/
261265
@doc({heading: 'Tensors', subheading: 'Creation'})
262266
@operation
@@ -270,7 +274,7 @@ export class Ops {
270274
}
271275

272276
/**
273-
* Creates a tensor with all elements set to 1 with the same shape as the
277+
* Creates a `Tensor` with all elements set to 1 with the same shape as the
274278
* given tensor.
275279
* @param x A tensor.
276280
*/
@@ -281,8 +285,9 @@ export class Ops {
281285
}
282286

283287
/**
284-
* Creates a tensor with all elements set to 0 with the same shape as the
288+
* Creates a `Tensor` with all elements set to 0 with the same shape as the
285289
* given tensor.
290+
*
286291
* @param x A tensor.
287292
*/
288293
@doc({heading: 'Tensors', subheading: 'Creation'})
@@ -303,7 +308,8 @@ export class Ops {
303308
}
304309

305310
/**
306-
* Creates a tensor with values sampled from a normal distribution.
311+
* Creates a `Tensor` with values sampled from a normal distribution.
312+
*
307313
* @param shape An array of integers defining the output tensor shape.
308314
* @param mean The mean of the normal distribution.
309315
* @param stdDev The standard deviation of the normal distribution.
@@ -324,7 +330,8 @@ export class Ops {
324330
}
325331

326332
/**
327-
* Creates a tensor with values sampled from a truncated normal distribution.
333+
* Creates a `Tensor` with values sampled from a truncated normal
334+
* distribution.
328335
*
329336
* The generated values follow a normal distribution with specified mean and
330337
* standard deviation, except that values whose magnitude is more than 2
@@ -350,7 +357,7 @@ export class Ops {
350357
}
351358

352359
/**
353-
* Creates a tensor with values sampled from a uniform distribution.
360+
* Creates a `Tensor` with values sampled from a uniform distribution.
354361
*
355362
* The generated values follow a uniform distribution in the range [minval,
356363
* maxval). The lower bound minval is included in the range, while the upper
@@ -372,7 +379,7 @@ export class Ops {
372379
}
373380

374381
/**
375-
* Creates a tensor with values sampled from a random number generator
382+
* Creates a `Tensor` with values sampled from a random number generator
376383
* function defined by the user.
377384
*
378385
* @param shape An array of integers defining the output tensor shape.
@@ -404,7 +411,7 @@ export class Ops {
404411
}
405412

406413
/**
407-
* Draws samples from a multinomial distribution.
414+
* Creates a `Tensor` with values drawn from a multinomial distribution.
408415
*
409416
* @param probabilities 1D array with normalized outcome probabilities, or
410417
* 2D array of shape `[batchSize, numOutcomes]`.
@@ -445,7 +452,7 @@ export class Ops {
445452
}
446453

447454
/**
448-
* Creates a one-hot tensor. The locations represented by `indices` take
455+
* Creates a one-hot `Tensor`. The locations represented by `indices` take
449456
* value `onValue` (defaults to 1), while all other locations take value
450457
* `offValue` (defaults to 0).
451458
*
@@ -468,7 +475,7 @@ export class Ops {
468475
}
469476

470477
/**
471-
* Creates a tensor from an image.
478+
* Creates a `Tensor` from an image.
472479
*
473480
* @param pixels The input image to construct the tensor from. Accepts image
474481
* of type `ImageData`, `HTMLImageElement`, `HTMLCanvasElement`, or
@@ -490,7 +497,7 @@ export class Ops {
490497
}
491498

492499
/**
493-
* Reshapes a tensor to a given shape.
500+
* Reshapes a `Tensor` to a given shape.
494501
*
495502
* Given a input tensor, returns a new tensor with the same values as the
496503
* input tensor with shape `shape`.
@@ -504,6 +511,7 @@ export class Ops {
504511
* shape filled with the values of tensor. In this case, the number of
505512
* elements implied by shape must be the same as the number of elements in
506513
* tensor.
514+
*
507515
* @param x A tensor.
508516
* @param shape An array of integers defining the output tensor shape.
509517
*/
@@ -638,13 +646,10 @@ export class Ops {
638646
/**
639647
* Return an evenly spaced sequence of numbers over the given interval.
640648
*
641-
* The stop value can be optionally excluded by passing setting [endpoint] to
642-
* true.
643-
*
644649
* @param start The start value of the sequence
645650
* @param stop The end value of the sequence
646651
* @param num The number of values to generate
647-
* @param endpoint Optional, determines whether stop is included in the
652+
* @param endpoint Determines whether stop is included in the
648653
* sequence. Defaults to true.
649654
*/
650655
@operation
@@ -666,16 +671,16 @@ export class Ops {
666671
}
667672

668673
/**
669-
* Creates a new Tensor1D filled with the numbers in the range provided.
674+
* Creates a new `Tensor1D` filled with the numbers in the range provided.
670675
*
671676
* The tensor is a is half-open interval meaning it includes start, but
672677
* excludes stop. Decrementing ranges and negative step values are also
673678
* supported.
674679
*
675680
* @param start An integer start value
676681
* @param stop An integer stop value
677-
* @param step An optional integer increment (will default to 1 or -1)
678-
* @param dtype An optional dtype
682+
* @param step An integer increment (will default to 1 or -1)
683+
* @param dtype
679684
*/
680685
@operation
681686
@doc({heading: 'Tensors', subheading: 'Creation'})

src/ops/batchnorm.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class Ops {
3535
* @param scale A scale Tensor.
3636
* @param offset An offset Tensor.
3737
*/
38-
@doc({heading: 'Operations', subheading: 'Normalization'})
3938
@operation
4039
static batchNormalization2d(
4140
x: Tensor2D, mean: Tensor2D|Tensor1D, variance: Tensor2D|Tensor1D,
@@ -81,7 +80,6 @@ export class Ops {
8180
* @param scale A scale Tensor.
8281
* @param offset An offset Tensor.
8382
*/
84-
@doc({heading: 'Operations', subheading: 'Normalization'})
8583
@operation
8684
static batchNormalization3d(
8785
x: Tensor3D, mean: Tensor3D|Tensor1D, variance: Tensor3D|Tensor1D,
@@ -127,7 +125,6 @@ export class Ops {
127125
* @param scale A scale Tensor.
128126
* @param offset An offset Tensor.
129127
*/
130-
@doc({heading: 'Operations', subheading: 'Normalization'})
131128
@operation
132129
static batchNormalization4d(
133130
x: Tensor4D, mean: Tensor4D|Tensor1D, variance: Tensor4D|Tensor1D,
@@ -171,7 +168,7 @@ export class Ops {
171168
* shapes:
172169
* - The same shape as the input.
173170
* - In the common case, the depth dimension is the last dimension of x, so
174-
* the values would be an Tensor1D of shape [depth].
171+
* the values would be an `Tensor1D` of shape [depth].
175172
*
176173
* @param x The input Tensor.
177174
* @param mean A mean Tensor.

0 commit comments

Comments
 (0)