Skip to content

Commit d28f1af

Browse files
committed
Auto-generated commit
1 parent 821ed4a commit d28f1af

10 files changed

Lines changed: 335 additions & 259 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ A total of 44 issues were closed in this release:
807807

808808
<details>
809809

810+
- [`bbd8f0e`](https://github.com/stdlib-js/stdlib/commit/bbd8f0eec8d6d52201d7706a349fdb9cac737d9c) - **refactor:** avoid unnecessary offset calculation _(by Athan Reines)_
811+
- [`8d3124d`](https://github.com/stdlib-js/stdlib/commit/8d3124d525abb511f0257649bfc4e0bf6c0ce87b) - **docs:** add comment _(by Athan Reines)_
812+
- [`372443f`](https://github.com/stdlib-js/stdlib/commit/372443fe38ff5fac2c1a5214593e4aecbf7e3096) - **refactor:** more strictly enforce dtype and shape constraints and handle dtype instances _(by Athan Reines)_
810813
- [`ff1c6e2`](https://github.com/stdlib-js/stdlib/commit/ff1c6e2ff7d740b54dab525047eb5d7786854276) - **docs:** update docs and examples to accommodate dtype instances _(by Athan Reines)_
811814
- [`8112cea`](https://github.com/stdlib-js/stdlib/commit/8112cea1ed134b3070555a08d76ffb7b334f58ef) - **refactor:** remove overloads and use generic _(by Athan Reines)_
812815
- [`8b2b591`](https://github.com/stdlib-js/stdlib/commit/8b2b591c7511b405d069d9c4361ea3cfd796c4c6) - **refactor:** remove unnecessary offset calculation _(by Athan Reines)_

base/empty-like/lib/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var shape2strides = require( './../../../base/shape2strides' );
24-
var strides2offset = require( './../../../base/strides2offset' );
2524
var resolveStr = require( './../../../base/dtype-resolve-str' );
2625
var numel = require( './../../../base/numel' );
2726
var getDType = require( './../../../base/dtype' );
@@ -89,7 +88,7 @@ function emptyLike( x ) {
8988
}
9089
// FIXME: add support for struct dtypes. Will need to do something similar to `array/empty` in so far as allocating an uninitialized array buffer, performing byte alignment, and creating a StructArray view atop the buffer.
9190

92-
return new x.constructor( dt, buf, sh, st, strides2offset( sh, st ), ord );
91+
return new x.constructor( dt, buf, sh, st, 0, ord );
9392
}
9493

9594

empty-like/lib/main.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isPlainObject = require( '@stdlib/assert/is-plain-object' );
2626
var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives;
2727
var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' );
2828
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
29+
var resolveStr = require( './../../base/dtype-resolve-str' );
2930
var shape2strides = require( './../../base/shape2strides' );
3031
var numel = require( './../../base/numel' );
3132
var getDType = require( './../../dtype' );
@@ -82,6 +83,7 @@ function emptyLike( x ) {
8283
var opts;
8384
var buf;
8485
var len;
86+
var dt;
8587
var st;
8688
var sh;
8789

@@ -135,11 +137,14 @@ function emptyLike( x ) {
135137
len = 1;
136138
st = [ 0 ];
137139
}
138-
if ( dtype === 'binary' ) {
140+
dt = resolveStr( dtype );
141+
if ( dt === 'binary' ) {
139142
buf = allocUnsafe( len );
140143
} else {
141-
buf = emptyArray( len, dtype );
144+
buf = emptyArray( len, dt );
142145
}
146+
// FIXME: add support for struct dtypes. Will need to do something similar to `array/empty` in so far as allocating an uninitialized array buffer, performing byte alignment, and creating a StructArray view atop the buffer.
147+
143148
return new ndarray( dtype, buf, sh, st, 0, order, opts );
144149
}
145150

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

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)