Skip to content

Commit 7d9c0c0

Browse files
committed
docs: update docs and examples to accommodate dtype instances
1 parent 77ef712 commit 7d9c0c0

6 files changed

Lines changed: 401 additions & 345 deletions

File tree

lib/node_modules/@stdlib/ndarray/zeros-like/README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,50 +45,54 @@ var zerosLike = require( '@stdlib/ndarray/zeros-like' );
4545
Creates a zero-filled [ndarray][@stdlib/ndarray/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray.
4646

4747
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var getDType = require( '@stdlib/ndarray/dtype' );
4850
var zeros = require( '@stdlib/ndarray/zeros' );
4951

5052
var x = zeros( [ 2, 2 ] );
51-
// returns <ndarray>
53+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
5254

5355
var y = zerosLike( x );
54-
// returns <ndarray>
56+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
5557

56-
var sh = y.shape;
58+
var sh = getShape( y );
5759
// returns [ 2, 2 ]
5860

59-
var dt = y.dtype;
61+
var dt = String( getDType( y ) );
6062
// returns 'float64'
6163
```
6264

63-
The function supports the following `options`:
65+
The function supports the following options:
6466

65-
- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Must be a numeric [data type][@stdlib/ndarray/dtypes] or "generic". Overrides the input ndarray's inferred [data type][@stdlib/ndarray/dtypes].
67+
- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Must be a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. Overrides the input ndarray's inferred [data type][@stdlib/ndarray/dtypes].
6668
- **shape**: output [ndarray][@stdlib/ndarray/ctor] shape. Overrides the input ndarray's inferred shape.
6769
- **order**: specifies whether the output [ndarray][@stdlib/ndarray/ctor] should be `'row-major'` (C-style) or `'column-major'` (Fortran-style). Overrides the input ndarray's inferred order.
68-
- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
69-
- **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default: `[ options.mode ]`.
70-
- **readonly**: `boolean` indicating whether an array should be **read-only**. Default: `false`.
70+
- **mode**: specifies how to handle indices which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). Default: `'throw'`.
71+
- **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default: `[ options.mode ]`.
72+
- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`.
7173

7274
To override either the `dtype`, `shape`, or `order`, specify the corresponding option. For example, to override the inferred [data type][@stdlib/ndarray/dtypes],
7375

7476
```javascript
77+
var getShape = require( '@stdlib/ndarray/shape' );
78+
var getDType = require( '@stdlib/ndarray/dtype' );
7579
var zeros = require( '@stdlib/ndarray/zeros' );
7680

7781
var x = zeros( [ 2, 2 ] );
78-
// returns <ndarray>
82+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
7983

80-
var dt = x.dtype;
84+
var dt = String( getDType( x ) );
8185
// returns 'float64'
8286

8387
var y = zerosLike( x, {
8488
'dtype': 'int32'
8589
});
86-
// returns <ndarray>
90+
// returns <ndarray>[ [ 0, 0 ], [ 0, 0 ] ]
8791

88-
var sh = y.shape;
92+
var sh = getShape( y );
8993
// returns [ 2, 2 ]
9094

91-
dt = y.dtype;
95+
dt = String( getDType( y ) );
9296
// returns 'int32'
9397
```
9498

@@ -115,10 +119,11 @@ dt = y.dtype;
115119
```javascript
116120
var dtypes = require( '@stdlib/ndarray/dtypes' );
117121
var zeros = require( '@stdlib/ndarray/zeros' );
122+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
118123
var zerosLike = require( '@stdlib/ndarray/zeros-like' );
119124

120125
// Get a list of data types:
121-
var dt = dtypes( 'numeric' );
126+
var dt = dtypes( 'integer_and_generic' );
122127

123128
// Generate zero-filled arrays...
124129
var x;
@@ -129,7 +134,7 @@ for ( i = 0; i < dt.length; i++ ) {
129134
'dtype': dt[ i ]
130135
});
131136
y = zerosLike( x );
132-
console.log( y.data );
137+
console.log( ndarray2array( y ) );
133138
}
134139
```
135140

lib/node_modules/@stdlib/ndarray/zeros-like/docs/repl.txt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- shape: array shape.
99
- dtype: underlying array data type.
1010
- order: whether the array order is row-major (C-style) or column-major
11-
(Fortran-style).
11+
(Fortran-style).
1212

1313
Parameters
1414
----------
@@ -21,8 +21,9 @@
2121
options.shape: ArrayLikeObject<integer>|integer (optional)
2222
Array shape. Overrides the input array's inferred shape.
2323

24-
options.dtype: string (optional)
25-
Array data type. Overrides the input array's inferred data type.
24+
options.dtype: string|DataType (optional)
25+
Array data type. Must be a numeric or "generic" data type. Overrides the
26+
input array's inferred data type.
2627

2728
options.order: string (optional)
2829
Array order (either 'row-major' (C-style) or 'column-major' (Fortran-
@@ -61,18 +62,10 @@
6162

6263
Examples
6364
--------
64-
> var x = {{alias:@stdlib/ndarray/base/zeros}}( 'float64', [ 2, 2 ], 'row-major' )
65-
<ndarray>
66-
> var sh = x.shape
67-
[ 2, 2 ]
68-
> var dt = x.dtype
69-
'float64'
65+
> var x = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] )
66+
<ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
7067
> var y = {{alias}}( x )
71-
<ndarray>
72-
> sh = y.shape
73-
[ 2, 2 ]
74-
> dt = y.dtype
75-
'float64'
68+
<ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
7669

7770
See Also
7871
--------

0 commit comments

Comments
 (0)