Skip to content

Commit ae704bb

Browse files
docs: improve doctests for ndarray instances in blas/ext/linspace
PR-URL: #10542 Ref: #9329 Reviewed-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: stdlib-bot <noreply@stdlib.io>
1 parent ae32f26 commit ae704bb

7 files changed

Lines changed: 27 additions & 135 deletions

File tree

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

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ 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' );
39-
4038
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 ]
39+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
4540
```
4641

4742
The function has the following parameters:
@@ -63,77 +58,54 @@ The function accepts the following options:
6358
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.
6459

6560
```javascript
66-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
67-
6861
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 ]
62+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
7363
```
7464

7565
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.
7666

7767
```javascript
7868
var array = require( '@stdlib/ndarray/array' );
7969
var BooleanArray = require( '@stdlib/array/bool' );
80-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
8170

8271
var start = array( [ 1.0, 5.0 ] );
8372
var end = array( [ 3.0, 8.0 ] );
8473
var endpoint = array( new BooleanArray( [ true, false ] ) );
8574

8675
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 ] ]
76+
// returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 5.0, 6.0, 7.0 ] ]
9177
```
9278

9379
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.
9480

9581
```javascript
96-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
97-
9882
var x = linspace( [ 2, 2 ], 1.0, 4.0, {
9983
'dims': [ 0, 1 ]
10084
});
101-
// returns <ndarray>
102-
103-
var arr = ndarray2array( x );
104-
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
85+
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
10586
```
10687

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

10990
```javascript
110-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
111-
11291
var x = linspace( [ 4 ], 1.0, 4.0, {
11392
'dtype': 'float32'
11493
});
115-
// returns <ndarray>
116-
117-
var arr = ndarray2array( x );
118-
// returns [ 1.0, 2.0, 3.0, 4.0 ]
94+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
11995
```
12096

12197
#### linspace.assign( out, start, stop\[, endpoint]\[, options] )
12298

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

125101
```javascript
126-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
127102
var zeros = require( '@stdlib/ndarray/zeros' );
128103

129104
var x = zeros( [ 4 ] );
130105
// returns <ndarray>
131106

132107
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 ]
108+
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0 ]
137109

138110
var bool = ( x === out );
139111
// 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 & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,10 @@ interface Linspace {
128128
* @returns output ndarray
129129
*
130130
* @example
131-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
132-
*
133131
* var out = linspace( [ 2, 4 ], 0.0, 3.0, {
134132
* 'dtype': 'float64'
135133
* });
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 ] ]
134+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
140135
*/
141136
<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
142137

@@ -150,13 +145,8 @@ interface Linspace {
150145
* @returns output ndarray
151146
*
152147
* @example
153-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
154-
*
155148
* 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 ] ]
149+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
160150
*/
161151
<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
162152

@@ -171,15 +161,10 @@ interface Linspace {
171161
* @returns output ndarray
172162
*
173163
* @example
174-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
175-
*
176164
* var out = linspace( [ 2, 4 ], 0.0, 3.0, true, {
177165
* 'dtype': 'float64'
178166
* });
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 ] ]
167+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
183168
*/
184169
<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
185170

@@ -194,13 +179,8 @@ interface Linspace {
194179
* @returns output ndarray
195180
*
196181
* @example
197-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
198-
*
199182
* 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 ] ]
183+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
204184
*/
205185
<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
206186

@@ -214,15 +194,10 @@ interface Linspace {
214194
* @returns output ndarray
215195
*
216196
* @example
217-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
218-
*
219197
* var out = linspace( [ 2, 4 ], 0.0, 3.0, {
220198
* 'dtype': 'float64'
221199
* });
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 ] ]
200+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
226201
*/
227202
<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
228203

@@ -236,13 +211,8 @@ interface Linspace {
236211
* @returns output ndarray
237212
*
238213
* @example
239-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
240-
*
241214
* 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 ] ]
215+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
246216
*/
247217
<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
248218

@@ -257,15 +227,10 @@ interface Linspace {
257227
* @returns output ndarray
258228
*
259229
* @example
260-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
261-
*
262230
* var out = linspace( [ 2, 4 ], 0.0, 3.0, true, {
263231
* 'dtype': 'float64'
264232
* });
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 ] ]
233+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
269234
*/
270235
<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
271236

@@ -280,13 +245,8 @@ interface Linspace {
280245
* @returns output ndarray
281246
*
282247
* @example
283-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
284-
*
285248
* 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 ] ]
249+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
290250
*/
291251
<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
292252

@@ -301,19 +261,15 @@ interface Linspace {
301261
*
302262
* @example
303263
* var zeros = require( '@stdlib/ndarray/zeros' );
304-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
305264
*
306265
* var x = zeros( [ 2, 4 ] );
307266
* // returns <ndarray>
308267
*
309268
* var out = linspace.assign( x, 0.0, 3.0 );
310-
* // returns <ndarray>
269+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
311270
*
312271
* var bool = ( out === x );
313272
* // 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 ] ]
317273
*/
318274
assign<T extends OutputArray = OutputArray>( out: T, start: Start, stop: Stop, options: BaseOptions ): T;
319275

@@ -329,19 +285,15 @@ interface Linspace {
329285
*
330286
* @example
331287
* var zeros = require( '@stdlib/ndarray/zeros' );
332-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
333288
*
334289
* var x = zeros( [ 2, 4 ] );
335290
* // returns <ndarray>
336291
*
337292
* var out = linspace.assign( x, 0.0, 3.0 );
338-
* // returns <ndarray>
293+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
339294
*
340295
* var bool = ( out === x );
341296
* // 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 ] ]
345297
*/
346298
assign<T extends OutputArray = OutputArray>( out: T, start: Start, stop: Stop, endpoint?: Endpoint, options?: BaseOptions ): T;
347299
}
@@ -356,29 +308,20 @@ interface Linspace {
356308
* @param options - function options
357309
*
358310
* @example
359-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
360-
*
361311
* 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 ] ]
312+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
366313
*
367314
* @example
368315
* var zeros = require( '@stdlib/ndarray/zeros' );
369-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
370316
*
371317
* var x = zeros( [ 2, 4 ] );
372318
* // returns <ndarray>
373319
*
374320
* var out = linspace.assign( x, 0.0, 3.0 );
375-
* // returns <ndarray>
321+
* // returns <ndarray>[ [ 0.0, 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0, 3.0 ] ]
376322
*
377323
* var bool = ( out === x );
378324
* // 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 ] ]
382325
*/
383326
declare const linspace: Linspace;
384327

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)