Skip to content

Commit 5417fe1

Browse files
docs: improve doctests for ndarray instances in
1 parent 9221bdb commit 5417fe1

File tree

7 files changed

+27
-121
lines changed

7 files changed

+27
-121
lines changed

lib/node_modules/@stdlib/blas/ext/linspace/README.md

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ var linspace = require( '@stdlib/blas/ext/linspace' );
3535
Returns a new [ndarray][@stdlib/ndarray/ctor] filled with linearly spaced values over a specified interval along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
3636

3737
```javascript
38-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
3938

4039
var x = linspace( [ 4 ], 1.0, 4.0 );
41-
// returns <ndarray>
42-
43-
var arr = ndarray2array( x );
44-
// returns [ 1.0, 2.0, 3.0, 4.0 ]
40+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
4541
```
4642

4743
The function has the following parameters:
@@ -63,77 +59,57 @@ The function accepts the following options:
6359
By default, the function always includes the end of the interval in the list of values written to an output [ndarray][@stdlib/ndarray/ctor]. To exclude the end of the interval, provide an `endpoint` argument.
6460

6561
```javascript
66-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
6762

6863
var x = linspace( [ 4 ], 1.0, 5.0, false );
69-
// returns <ndarray>
70-
71-
var arr = ndarray2array( x );
72-
// returns [ 1.0, 2.0, 3.0, 4.0 ]
64+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
7365
```
7466

7567
When provided scalar or zero-dimensional [ndarray][@stdlib/ndarray/ctor] `start`, `stop`, and `endpoint` arguments, the values are broadcast across all elements in the shape defined by the complement of those dimensions specified by `options.dims`. To specify separate sub-array configurations, provide non-zero-dimensional [ndarray][@stdlib/ndarray/ctor] arguments.
7668

7769
```javascript
7870
var array = require( '@stdlib/ndarray/array' );
7971
var BooleanArray = require( '@stdlib/array/bool' );
80-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
8172

8273
var start = array( [ 1.0, 5.0 ] );
8374
var end = array( [ 3.0, 8.0 ] );
8475
var endpoint = array( new BooleanArray( [ true, false ] ) );
8576

8677
var x = linspace( [ 2, 3 ], start, end, endpoint );
87-
// returns <ndarray>
88-
89-
var arr = ndarray2array( x );
90-
// returns [ [ 1.0, 2.0, 3.0 ], [ 5.0, 6.0, 7.0 ] ]
78+
// returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 5.0, 6.0, 7.0 ] ]
9179
```
9280

9381
By default, the function generates linearly spaced values along the last dimension of an output [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option.
9482

9583
```javascript
96-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
9784

9885
var x = linspace( [ 2, 2 ], 1.0, 4.0, {
9986
'dims': [ 0, 1 ]
10087
});
101-
// returns <ndarray>
102-
103-
var arr = ndarray2array( x );
104-
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
88+
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
10589
```
10690

10791
To specify the output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes], provide a `dtype` option.
10892

10993
```javascript
110-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
11194

11295
var x = linspace( [ 4 ], 1.0, 4.0, {
11396
'dtype': 'float32'
11497
});
115-
// returns <ndarray>
116-
117-
var arr = ndarray2array( x );
118-
// returns [ 1.0, 2.0, 3.0, 4.0 ]
98+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
11999
```
120100

121101
#### linspace.assign( out, start, stop\[, endpoint]\[, options] )
122102

123103
Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced values over a specified interval along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
124104

125105
```javascript
126-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
127106
var zeros = require( '@stdlib/ndarray/zeros' );
128107

129108
var x = zeros( [ 4 ] );
130109
// returns <ndarray>
131110

132111
var out = linspace.assign( x, 1.0, 4.0 );
133-
// returns <ndarray>
134-
135-
var arr = ndarray2array( out );
136-
// returns [ 1.0, 2.0, 3.0, 4.0 ]
112+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
137113

138114
var bool = ( x === out );
139115
// returns true

lib/node_modules/@stdlib/blas/ext/linspace/docs/repl.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@
128128

129129
Examples
130130
--------
131-
> var out = {{alias}}( [ 4 ], 1.0, 4.0 );
132-
> {{alias:@stdlib/ndarray/to-array}}( out )
133-
[ 1.0, 2.0, 3.0, 4.0 ]
131+
> var out = {{alias}}( [ 4 ], 1.0, 4.0 )
132+
<ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
134133

135134

136135
{{alias}}.assign( out, start, stop[, endpoint][, options] )
@@ -220,9 +219,8 @@
220219
Examples
221220
--------
222221
> var x = {{alias:@stdlib/ndarray/zeros}}( [ 4 ] );
223-
> var out = {{alias}}.assign( x, 1.0, 4.0 );
224-
> {{alias:@stdlib/ndarray/to-array}}( out )
225-
[ 1.0, 2.0, 3.0, 4.0 ]
222+
> var out = {{alias}}.assign( x, 1.0, 4.0 )
223+
<ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
226224
> var bool = ( out === x )
227225
true
228226

lib/node_modules/@stdlib/blas/ext/linspace/docs/types/index.d.ts

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,11 @@ interface Linspace {
128128
* @returns output ndarray
129129
*
130130
* @example
131-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
132131
*
133132
* var out = linspace( [ 2, 4 ], 0.0, 3.0, {
134133
* 'dtype': 'float64'
135134
* });
136-
* // returns <ndarray>
137-
*
138-
* var arr = ndarray2array( out );
139-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
135+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
140136
*/
141137
<T extends RealStart = RealStart, U extends RealStop = RealStop>( shape: number | ArrayLike<number>, start: T, stop: U, options: OptionsWithDataType ): OutputArray; // TODO: we lose some type specificity here. We could likely improve specificity here by using type maps
142138

@@ -150,13 +146,9 @@ interface Linspace {
150146
* @returns output ndarray
151147
*
152148
* @example
153-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
154149
*
155150
* var out = linspace( [ 2, 4 ], 0.0, 3.0, {} );
156-
* // returns <ndarray>
157-
*
158-
* var arr = ndarray2array( out );
159-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
151+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
160152
*/
161153
<T extends RealStart = RealStart, U extends RealStop = RealStop>( shape: number | ArrayLike<number>, start: T, stop: U, options: Options ): RealOutputArray; // NOTE: we lose some type specificity here, as the output ndarray data type is determined according to type promotion rules
162154

@@ -171,15 +163,11 @@ interface Linspace {
171163
* @returns output ndarray
172164
*
173165
* @example
174-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
175166
*
176167
* var out = linspace( [ 2, 4 ], 0.0, 3.0, true, {
177168
* 'dtype': 'float64'
178169
* });
179-
* // returns <ndarray>
180-
*
181-
* var arr = ndarray2array( out );
182-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
170+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
183171
*/
184172
<T extends RealStart = RealStart, U extends RealStop = RealStop, V extends Endpoint = Endpoint>( shape: number | ArrayLike<number>, start: T, stop: U, endpoint: V, options: OptionsWithDataType ): OutputArray; // TODO: we lose some type specificity here. We could likely improve specificity here by using type maps
185173

@@ -194,13 +182,9 @@ interface Linspace {
194182
* @returns output ndarray
195183
*
196184
* @example
197-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
198185
*
199186
* var out = linspace( [ 2, 4 ], 0.0, 3.0 );
200-
* // returns <ndarray>
201-
*
202-
* var arr = ndarray2array( out );
203-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
187+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
204188
*/
205189
<T extends RealStart = RealStart, U extends RealStop = RealStop, V extends Endpoint = Endpoint>( shape: number | ArrayLike<number>, start: T, stop: U, endpoint?: V, options?: Options ): RealOutputArray; // NOTE: we lose some type specificity here, as the output ndarray data type is determined according to type promotion rules
206190

@@ -214,15 +198,11 @@ interface Linspace {
214198
* @returns output ndarray
215199
*
216200
* @example
217-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
218201
*
219202
* var out = linspace( [ 2, 4 ], 0.0, 3.0, {
220203
* 'dtype': 'float64'
221204
* });
222-
* // returns <ndarray>
223-
*
224-
* var arr = ndarray2array( out );
225-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
205+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
226206
*/
227207
<T extends Start = Start, U extends Stop = Stop>( shape: number | ArrayLike<number>, start: T, stop: U, options: OptionsWithDataType ): ComplexOutputArray; // TODO: we lose some type specificity here. We could likely improve specificity here by using type maps
228208

@@ -236,13 +216,9 @@ interface Linspace {
236216
* @returns output ndarray
237217
*
238218
* @example
239-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
240219
*
241220
* var out = linspace( [ 2, 4 ], 0.0, 3.0, {} );
242-
* // returns <ndarray>
243-
*
244-
* var arr = ndarray2array( out );
245-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
221+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
246222
*/
247223
<T extends Start = Start, U extends Stop = Stop>( shape: number | ArrayLike<number>, start: T, stop: U, options: Options ): ComplexOutputArray; /* eslint-disable-line @typescript-eslint/unified-signatures */ // NOTE: we lose some type specificity here, as the output ndarray data type is determined according to type promotion rules
248224

@@ -257,15 +233,11 @@ interface Linspace {
257233
* @returns output ndarray
258234
*
259235
* @example
260-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
261236
*
262237
* var out = linspace( [ 2, 4 ], 0.0, 3.0, true, {
263238
* 'dtype': 'float64'
264239
* });
265-
* // returns <ndarray>
266-
*
267-
* var arr = ndarray2array( out );
268-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
240+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
269241
*/
270242
<T extends Start = Start, U extends Stop = Stop, V extends Endpoint = Endpoint>( shape: number | ArrayLike<number>, start: T, stop: U, endpoint: V, options: OptionsWithDataType ): ComplexOutputArray; // TODO: we lose some type specificity here. We could likely improve specificity here by using type maps
271243

@@ -280,13 +252,9 @@ interface Linspace {
280252
* @returns output ndarray
281253
*
282254
* @example
283-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
284255
*
285256
* var out = linspace( [ 2, 4 ], 0.0, 3.0, true );
286-
* // returns <ndarray>
287-
*
288-
* var arr = ndarray2array( out );
289-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
257+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
290258
*/
291259
<T extends Start = Start, U extends Stop = Stop, V extends Endpoint = Endpoint>( shape: number | ArrayLike<number>, start: T, stop: U, endpoint?: V, options?: Options ): ComplexOutputArray; // NOTE: we lose some type specificity here, as the output ndarray data type is determined according to type promotion rules
292260

@@ -301,19 +269,15 @@ interface Linspace {
301269
*
302270
* @example
303271
* var zeros = require( '@stdlib/ndarray/zeros' );
304-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
305272
*
306273
* var x = zeros( [ 2, 4 ] );
307274
* // returns <ndarray>
308275
*
309276
* var out = linspace.assign( x, 0.0, 3.0 );
310-
* // returns <ndarray>
277+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
311278
*
312279
* var bool = ( out === x );
313280
* // returns true
314-
*
315-
* var arr = ndarray2array( out );
316-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
317281
*/
318282
assign<T extends OutputArray = OutputArray>( out: T, start: Start, stop: Stop, options: BaseOptions ): T;
319283

@@ -329,19 +293,15 @@ interface Linspace {
329293
*
330294
* @example
331295
* var zeros = require( '@stdlib/ndarray/zeros' );
332-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
333296
*
334297
* var x = zeros( [ 2, 4 ] );
335298
* // returns <ndarray>
336299
*
337300
* var out = linspace.assign( x, 0.0, 3.0 );
338-
* // returns <ndarray>
301+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
339302
*
340303
* var bool = ( out === x );
341304
* // returns true
342-
*
343-
* var arr = ndarray2array( out );
344-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
345305
*/
346306
assign<T extends OutputArray = OutputArray>( out: T, start: Start, stop: Stop, endpoint?: Endpoint, options?: BaseOptions ): T;
347307
}
@@ -356,29 +316,21 @@ interface Linspace {
356316
* @param options - function options
357317
*
358318
* @example
359-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
360319
*
361320
* var out = linspace( [ 2, 4 ], 0.0, 3.0 );
362-
* // returns <ndarray>
363-
*
364-
* var arr = ndarray2array( out );
365-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
321+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
366322
*
367323
* @example
368324
* var zeros = require( '@stdlib/ndarray/zeros' );
369-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
370325
*
371326
* var x = zeros( [ 2, 4 ] );
372327
* // returns <ndarray>
373328
*
374329
* var out = linspace.assign( x, 0.0, 3.0 );
375-
* // returns <ndarray>
330+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
376331
*
377332
* var bool = ( out === x );
378333
* // returns true
379-
*
380-
* var arr = ndarray2array( out );
381-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
382334
*/
383335
declare const linspace: Linspace;
384336

lib/node_modules/@stdlib/blas/ext/linspace/lib/assign.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,15 @@ var base = require( './base.js' );
6767
*
6868
* @example
6969
* var zeros = require( '@stdlib/ndarray/zeros' );
70-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
7170
*
7271
* var x = zeros( [ 2, 4 ] );
7372
* // returns <ndarray>
7473
*
7574
* var out = assign( x, 0.0, 3.0 );
76-
* // returns <ndarray>
75+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
7776
*
7877
* var bool = ( out === x );
7978
* // returns true
80-
*
81-
* var arr = ndarray2array( out );
82-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
8379
*/
8480
function assign( x, start, stop ) {
8581
var endpoint;

lib/node_modules/@stdlib/blas/ext/linspace/lib/base.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ var options = {
7373
* var Float64Array = require( '@stdlib/array/float64' );
7474
* var BooleanArray = require( '@stdlib/array/bool' );
7575
* var array = require( '@stdlib/ndarray/array' );
76-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
7776
* var ndarray = require( '@stdlib/ndarray/ctor' );
7877
*
7978
* // Create a data buffer:
@@ -110,10 +109,7 @@ var options = {
110109
* var out = linspace( x, start, end, endpoint, {
111110
* 'dims': [ -1 ]
112111
* });
113-
* // returns <ndarray>
114-
*
115-
* var arr = ndarray2array( out );
116-
* // returns [ [ [ 1.0, 2.0, 3.0 ] ], [ [ 4.0, 5.0, 6.0 ] ] ]
112+
* // returns <ndarray>[ [ [ 1.0, 2.0, 3.0 ] ], [ [ 4.0, 5.0, 6.0 ] ] ]
117113
*/
118114
var linspace = factory( table, [ DTYPES.idtypes0, DTYPES.idtypes1, DTYPES.idtypes2 ], DTYPES.odtypes, options ); // eslint-disable-line max-len
119115

lib/node_modules/@stdlib/blas/ext/linspace/lib/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,23 @@
2424
* @module @stdlib/blas/ext/linspace
2525
*
2626
* @example
27-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
2827
* var linspace = require( '@stdlib/blas/ext/linspace' );
2928
*
3029
* var out = linspace( [ 2, 4 ], 0.0, 3.0 );
31-
* // returns <ndarray>
32-
*
33-
* var arr = ndarray2array( out );
34-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
30+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
3531
*
3632
* @example
3733
* var zeros = require( '@stdlib/ndarray/zeros' );
38-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
3934
* var linspace = require( '@stdlib/blas/ext/linspace' );
4035
*
4136
* var x = zeros( [ 2, 4 ] );
4237
* // returns <ndarray>
4338
*
4439
* var out = linspace.assign( x, 0.0, 3.0 );
45-
* // returns <ndarray>
40+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
4641
*
4742
* var bool = ( out === x );
4843
* // returns true
49-
*
50-
* var arr = ndarray2array( out );
51-
* // returns [ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
5244
*/
5345

5446
// MODULES //

0 commit comments

Comments
 (0)