Skip to content

Commit 372443f

Browse files
committed
refactor: more strictly enforce dtype and shape constraints and handle dtype instances
1 parent ff1c6e2 commit 372443f

File tree

7 files changed

+324
-255
lines changed

7 files changed

+324
-255
lines changed

lib/node_modules/@stdlib/ndarray/empty/README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,57 @@ var empty = require( '@stdlib/ndarray/empty' );
4545
Creates an uninitialized [ndarray][@stdlib/ndarray/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes].
4646

4747
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var getDType = require( '@stdlib/ndarray/dtype' );
50+
4851
var arr = empty( [ 2, 2 ] );
4952
// returns <ndarray>
5053

51-
var sh = arr.shape;
54+
var sh = getShape( arr );
5255
// returns [ 2, 2 ]
5356

54-
var dt = arr.dtype;
57+
var dt = String( getDType( arr ) );
5558
// returns 'float64'
5659
```
5760

5861
The specified output [ndarray][@stdlib/ndarray/ctor] `shape` may be either an array-like object or an integer value.
5962

6063
```javascript
64+
var getShape = require( '@stdlib/ndarray/shape' );
65+
var getDType = require( '@stdlib/ndarray/dtype' );
66+
6167
var arr = empty( 2 );
6268
// returns <ndarray>
6369

64-
var sh = arr.shape;
70+
var sh = getShape( arr );
6571
// returns [ 2 ]
6672

67-
var dt = arr.dtype;
73+
var dt = String( getDType( arr ) );
6874
// returns 'float64'
6975
```
7076

71-
The function accepts the following `options`:
77+
The function accepts the following options:
7278

7379
- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Default: `'float64'`.
7480
- **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
75-
- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
76-
- **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 ]`.
81+
- **mode**: specifies how to handle indices which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). Default: `'throw'`.
82+
- **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 ]`.
7783

7884
By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [`float64`][@stdlib/ndarray/dtypes] data type. To specify an alternative [data type][@stdlib/ndarray/dtypes], provide a `dtype` option.
7985

8086
```javascript
87+
var getShape = require( '@stdlib/ndarray/shape' );
88+
var getDType = require( '@stdlib/ndarray/dtype' );
89+
8190
var arr = empty( [ 2, 2 ], {
8291
'dtype': 'float32'
8392
});
8493
// returns <ndarray>
8594

86-
var sh = arr.shape;
95+
var sh = getShape( arr );
8796
// returns [ 2, 2 ]
8897

89-
var dt = arr.dtype;
98+
var dt = String( getDType( arr ) );
9099
// returns 'float32'
91100
```
92101

@@ -117,10 +126,11 @@ var dt = arr.dtype;
117126

118127
```javascript
119128
var dtypes = require( '@stdlib/ndarray/dtypes' );
129+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
120130
var empty = require( '@stdlib/ndarray/empty' );
121131

122132
// Get a list of data types:
123-
var dt = dtypes();
133+
var dt = dtypes( 'integer_and_generic' );
124134

125135
// Generate uninitialized arrays...
126136
var arr;
@@ -129,7 +139,7 @@ for ( i = 0; i < dt.length; i++ ) {
129139
arr = empty( [ 2, 2 ], {
130140
'dtype': dt[ i ]
131141
});
132-
console.log( arr.data );
142+
console.log( ndarray2array( arr ) );
133143
}
134144
```
135145

lib/node_modules/@stdlib/ndarray/empty/docs/repl.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
options: Object (optional)
1818
Options.
1919

20-
options.dtype: string (optional)
20+
options.dtype: string|DataType (optional)
2121
Underlying data type. Default: 'float64'.
2222

2323
options.order: string (optional)
@@ -56,10 +56,6 @@
5656
--------
5757
> var arr = {{alias}}( [ 2, 2 ] )
5858
<ndarray>
59-
> var sh = arr.shape
60-
[ 2, 2 ]
61-
> var dt = arr.dtype
62-
'float64'
6359

6460
See Also
6561
--------

0 commit comments

Comments
 (0)