@stdlib/ndarray-base-empty 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -68,13 +68,16 @@ var empty = require( '@stdlib/ndarray-base-empty' );
68
68
  Creates an uninitialized [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes].
69
69
 
70
70
  ```javascript
71
+ var getShape = require( '@stdlib/ndarray-shape' );
72
+ var getDType = require( '@stdlib/ndarray-dtype' );
73
+
71
74
  var arr = empty( 'float64', [ 2, 2 ], 'row-major' );
72
75
  // returns <ndarray>
73
76
 
74
- var sh = arr.shape;
77
+ var sh = getShape( arr );
75
78
  // returns [ 2, 2 ]
76
79
 
77
- var dt = arr.dtype;
80
+ var dt = String( getDType( arr ) );
78
81
  // returns 'float64'
79
82
  ```
80
83
 
@@ -111,17 +114,18 @@ The function accepts the following arguments:
111
114
 
112
115
  ```javascript
113
116
  var dtypes = require( '@stdlib/ndarray-dtypes' );
117
+ var ndarray2array = require( '@stdlib/ndarray-to-array' );
114
118
  var empty = require( '@stdlib/ndarray-base-empty' );
115
119
 
116
120
  // Get a list of data types:
117
- var dt = dtypes();
121
+ var dt = dtypes( 'integer_and_generic' );
118
122
 
119
123
  // Generate uninitialized arrays...
120
124
  var arr;
121
125
  var i;
122
126
  for ( i = 0; i < dt.length; i++ ) {
123
127
  arr = empty( dt[ i ], [ 2, 2 ], 'row-major' );
124
- console.log( arr.data );
128
+ console.log( ndarray2array( arr ) );
125
129
  }
126
130
  ```
127
131
 
@@ -171,7 +175,7 @@ See [LICENSE][stdlib-license].
171
175
 
172
176
  ## Copyright
173
177
 
174
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
178
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
175
179
 
176
180
  </section>
177
181
 
@@ -184,8 +188,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
184
188
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-empty.svg
185
189
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-empty
186
190
 
187
- [test-image]: https://github.com/stdlib-js/ndarray-base-empty/actions/workflows/test.yml/badge.svg?branch=v0.3.0
188
- [test-url]: https://github.com/stdlib-js/ndarray-base-empty/actions/workflows/test.yml?query=branch:v0.3.0
191
+ [test-image]: https://github.com/stdlib-js/ndarray-base-empty/actions/workflows/test.yml/badge.svg?branch=v0.3.1
192
+ [test-url]: https://github.com/stdlib-js/ndarray-base-empty/actions/workflows/test.yml?query=branch:v0.3.1
189
193
 
190
194
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-empty/main.svg
191
195
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-empty?branch=main
@@ -197,8 +201,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
197
201
 
198
202
  -->
199
203
 
200
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
201
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
204
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
205
+ [chat-url]: https://stdlib.zulipchat.com
202
206
 
203
207
  [stdlib]: https://github.com/stdlib-js/stdlib
204
208
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var v=f(function(g,n){
2
- var l=require('@stdlib/ndarray-base-shape2strides/dist'),q=require('@stdlib/ndarray-base-strides2offset/dist'),m=require('@stdlib/ndarray-base-ctor/dist'),c=require('@stdlib/ndarray-base-numel/dist'),o=require('@stdlib/array-empty/dist'),y=require('@stdlib/buffer-alloc-unsafe/dist');function b(e,r,t){var u,s,i,a;return u=r.length,u>0?(i=c(r),a=l(r,t)):(i=1,a=[0]),e==="binary"?s=y(i):s=o(i,e),new m(e,s,r,a,q(r,a),t)}n.exports=b
3
- });var x=v();module.exports=x;
1
+ "use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=q(function(A,n){
2
+ var f=require('@stdlib/ndarray-base-shape2strides/dist'),m=require('@stdlib/ndarray-base-strides2offset/dist'),o=require('@stdlib/ndarray-base-dtype-resolve-str/dist'),c=require('@stdlib/ndarray-base-ctor/dist'),y=require('@stdlib/ndarray-base-numel/dist'),d=require('@stdlib/array-empty/dist'),b=require('@stdlib/buffer-alloc-unsafe/dist');function x(e,r,u){var v,t,i,a,s;return v=r.length,v>0?(i=y(r),a=f(r,u)):(i=1,a=[0]),s=o(e),s==="binary"?t=b(i):t=d(i,s),new c(e,t,r,a,m(r,a),u)}n.exports=x
3
+ });var g=l();module.exports=g;
4
4
  /** @license Apache-2.0 */
5
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar emptyArray = require( '@stdlib/array-empty' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// MAIN //\n\n/**\n* Creates an uninitialized ndarray having a specified shape and data type.\n*\n* @param {string} dtype - data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - array order\n* @throws {TypeError} first argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var arr = empty( 'float32', [ 2, 2 ], 'row-major' );\n* // returns <ndarray>\n*\n* var sh = arr.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = arr.dtype;\n* // returns 'float32'\n*/\nfunction empty( dtype, shape, order ) {\n\tvar ndims;\n\tvar buf;\n\tvar len;\n\tvar st;\n\n\tndims = shape.length;\n\tif ( ndims > 0 ) {\n\t\tlen = numel( shape );\n\t\tst = shape2strides( shape, order );\n\t} else {\n\t\t// For 0-dimensional arrays, the buffer should contain a single element...\n\t\tlen = 1;\n\t\tst = [ 0 ];\n\t}\n\tif ( dtype === 'binary' ) {\n\t\tbuf = allocUnsafe( len );\n\t} else {\n\t\tbuf = emptyArray( len, dtype );\n\t}\n\treturn new ndarray( dtype, buf, shape, st, strides2offset( shape, st ), order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an uninitialized ndarray having a specified shape and data type.\n*\n* @module @stdlib/ndarray-base-empty\n*\n* @example\n* var empty = require( '@stdlib/ndarray-base-empty' );\n*\n* var arr = empty( 'float32', [ 2, 2 ], 'row-major' );\n* // returns <ndarray>\n*\n* var sh = arr.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = arr.dtype;\n* // returns 'float32'\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAiB,QAAS,qCAAsC,EAChEC,EAAU,QAAS,2BAA4B,EAC/CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAc,QAAS,6BAA8B,EAwBzD,SAASC,EAAOC,EAAOC,EAAOC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EAEJ,OAAAH,EAAQF,EAAM,OACTE,EAAQ,GACZE,EAAMT,EAAOK,CAAM,EACnBK,EAAKb,EAAeQ,EAAOC,CAAM,IAGjCG,EAAM,EACNC,EAAK,CAAE,CAAE,GAELN,IAAU,SACdI,EAAMN,EAAaO,CAAI,EAEvBD,EAAMP,EAAYQ,EAAKL,CAAM,EAEvB,IAAIL,EAASK,EAAOI,EAAKH,EAAOK,EAAIZ,EAAgBO,EAAOK,CAAG,EAAGJ,CAAM,CAC/E,CAKAV,EAAO,QAAUO,ICrCjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "shape2strides", "strides2offset", "ndarray", "numel", "emptyArray", "allocUnsafe", "empty", "dtype", "shape", "order", "ndims", "buf", "len", "st", "main"]
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar emptyArray = require( '@stdlib/array-empty' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// MAIN //\n\n/**\n* Creates an uninitialized ndarray having a specified shape and data type.\n*\n* @param {*} dtype - data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - array order\n* @throws {TypeError} first argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var getShape = require( '@stdlib/ndarray-shape' );\n* var getDType = require( '@stdlib/ndarray-dtype' );\n*\n* var arr = empty( 'float32', [ 2, 2 ], 'row-major' );\n* // returns <ndarray>\n*\n* var sh = getShape( arr );\n* // returns [ 2, 2 ]\n*\n* var dt = String( getDType( arr ) );\n* // returns 'float32'\n*/\nfunction empty( dtype, shape, order ) {\n\tvar ndims;\n\tvar buf;\n\tvar len;\n\tvar st;\n\tvar dt;\n\n\tndims = shape.length;\n\tif ( ndims > 0 ) {\n\t\tlen = numel( shape );\n\t\tst = shape2strides( shape, order );\n\t} else {\n\t\t// For 0-dimensional arrays, the buffer should contain a single element...\n\t\tlen = 1;\n\t\tst = [ 0 ];\n\t}\n\tdt = resolveStr( dtype );\n\tif ( dt === 'binary' ) {\n\t\tbuf = allocUnsafe( len );\n\t} else {\n\t\tbuf = emptyArray( len, dt );\n\t}\n\t// 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.\n\n\treturn new ndarray( dtype, buf, shape, st, strides2offset( shape, st ), order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an uninitialized ndarray having a specified shape and data type.\n*\n* @module @stdlib/ndarray-base-empty\n*\n* @example\n* var getShape = require( '@stdlib/ndarray-shape' );\n* var getDType = require( '@stdlib/ndarray-dtype' );\n* var empty = require( '@stdlib/ndarray-base-empty' );\n*\n* var arr = empty( 'float32', [ 2, 2 ], 'row-major' );\n* // returns <ndarray>\n*\n* var sh = getShape( arr );\n* // returns [ 2, 2 ]\n*\n* var dt = String( getDType( arr ) );\n* // returns 'float32'\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAiB,QAAS,qCAAsC,EAChEC,EAAa,QAAS,wCAAyC,EAC/DC,EAAU,QAAS,2BAA4B,EAC/CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAc,QAAS,6BAA8B,EA2BzD,SAASC,EAAOC,EAAOC,EAAOC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,OAAAJ,EAAQF,EAAM,OACTE,EAAQ,GACZE,EAAMT,EAAOK,CAAM,EACnBK,EAAKd,EAAeS,EAAOC,CAAM,IAGjCG,EAAM,EACNC,EAAK,CAAE,CAAE,GAEVC,EAAKb,EAAYM,CAAM,EAClBO,IAAO,SACXH,EAAMN,EAAaO,CAAI,EAEvBD,EAAMP,EAAYQ,EAAKE,CAAG,EAIpB,IAAIZ,EAASK,EAAOI,EAAKH,EAAOK,EAAIb,EAAgBQ,EAAOK,CAAG,EAAGJ,CAAM,CAC/E,CAKAX,EAAO,QAAUQ,IC3CjB,IAAIS,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "shape2strides", "strides2offset", "resolveStr", "ndarray", "numel", "emptyArray", "allocUnsafe", "empty", "dtype", "shape", "order", "ndims", "buf", "len", "st", "dt", "main"]
7
7
  }
package/lib/index.js CHANGED
@@ -24,15 +24,17 @@
24
24
  * @module @stdlib/ndarray-base-empty
25
25
  *
26
26
  * @example
27
+ * var getShape = require( '@stdlib/ndarray-shape' );
28
+ * var getDType = require( '@stdlib/ndarray-dtype' );
27
29
  * var empty = require( '@stdlib/ndarray-base-empty' );
28
30
  *
29
31
  * var arr = empty( 'float32', [ 2, 2 ], 'row-major' );
30
32
  * // returns <ndarray>
31
33
  *
32
- * var sh = arr.shape;
34
+ * var sh = getShape( arr );
33
35
  * // returns [ 2, 2 ]
34
36
  *
35
- * var dt = arr.dtype;
37
+ * var dt = String( getDType( arr ) );
36
38
  * // returns 'float32'
37
39
  */
38
40
 
package/lib/main.js CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
24
24
  var strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
25
+ var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );
25
26
  var ndarray = require( '@stdlib/ndarray-base-ctor' );
26
27
  var numel = require( '@stdlib/ndarray-base-numel' );
27
28
  var emptyArray = require( '@stdlib/array-empty' );
@@ -33,20 +34,23 @@ var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
33
34
  /**
34
35
  * Creates an uninitialized ndarray having a specified shape and data type.
35
36
  *
36
- * @param {string} dtype - data type
37
+ * @param {*} dtype - data type
37
38
  * @param {NonNegativeIntegerArray} shape - array shape
38
39
  * @param {string} order - array order
39
40
  * @throws {TypeError} first argument must be a recognized data type
40
41
  * @returns {ndarray} ndarray
41
42
  *
42
43
  * @example
44
+ * var getShape = require( '@stdlib/ndarray-shape' );
45
+ * var getDType = require( '@stdlib/ndarray-dtype' );
46
+ *
43
47
  * var arr = empty( 'float32', [ 2, 2 ], 'row-major' );
44
48
  * // returns <ndarray>
45
49
  *
46
- * var sh = arr.shape;
50
+ * var sh = getShape( arr );
47
51
  * // returns [ 2, 2 ]
48
52
  *
49
- * var dt = arr.dtype;
53
+ * var dt = String( getDType( arr ) );
50
54
  * // returns 'float32'
51
55
  */
52
56
  function empty( dtype, shape, order ) {
@@ -54,6 +58,7 @@ function empty( dtype, shape, order ) {
54
58
  var buf;
55
59
  var len;
56
60
  var st;
61
+ var dt;
57
62
 
58
63
  ndims = shape.length;
59
64
  if ( ndims > 0 ) {
@@ -64,11 +69,14 @@ function empty( dtype, shape, order ) {
64
69
  len = 1;
65
70
  st = [ 0 ];
66
71
  }
67
- if ( dtype === 'binary' ) {
72
+ dt = resolveStr( dtype );
73
+ if ( dt === 'binary' ) {
68
74
  buf = allocUnsafe( len );
69
75
  } else {
70
- buf = emptyArray( len, dtype );
76
+ buf = emptyArray( len, dt );
71
77
  }
78
+ // 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.
79
+
72
80
  return new ndarray( dtype, buf, shape, st, strides2offset( shape, st ), order ); // eslint-disable-line max-len
73
81
  }
74
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-empty",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Create an uninitialized ndarray having a specified shape and data type.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,12 +30,13 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/array-empty": "^0.2.1",
34
- "@stdlib/buffer-alloc-unsafe": "^0.2.2",
35
- "@stdlib/ndarray-base-ctor": "^0.2.2",
36
- "@stdlib/ndarray-base-numel": "^0.2.2",
37
- "@stdlib/ndarray-base-shape2strides": "^0.2.2",
38
- "@stdlib/ndarray-base-strides2offset": "^0.2.2"
33
+ "@stdlib/array-empty": "^0.3.1",
34
+ "@stdlib/buffer-alloc-unsafe": "^0.2.3",
35
+ "@stdlib/ndarray-base-ctor": "^0.3.0",
36
+ "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1",
37
+ "@stdlib/ndarray-base-numel": "^0.2.3",
38
+ "@stdlib/ndarray-base-shape2strides": "^0.2.3",
39
+ "@stdlib/ndarray-base-strides2offset": "^0.2.3"
39
40
  },
40
41
  "devDependencies": {},
41
42
  "engines": {