@stdlib/ndarray-zeros-like 0.2.1 → 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 +1 -1
- package/README.md +8 -8
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +95 -4
- package/lib/main.js +4 -2
- package/package.json +17 -15
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -85,14 +85,14 @@ var dt = y.dtype;
|
|
|
85
85
|
|
|
86
86
|
The function supports the following `options`:
|
|
87
87
|
|
|
88
|
-
- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Overrides the input ndarray's inferred [data type][@stdlib/ndarray/dtypes].
|
|
88
|
+
- **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].
|
|
89
89
|
- **shape**: output [ndarray][@stdlib/ndarray/ctor] shape. Overrides the input ndarray's inferred shape.
|
|
90
90
|
- **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.
|
|
91
91
|
- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
|
|
92
92
|
- **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 ]`.
|
|
93
93
|
- **readonly**: `boolean` indicating whether an array should be **read-only**. Default: `false`.
|
|
94
94
|
|
|
95
|
-
To override either the `dtype`, `shape`, or `order`, specify the corresponding option. For example, to override the inferred [data type][@stdlib/ndarray/dtypes],
|
|
95
|
+
To override either the `dtype`, `shape`, or `order`, specify the corresponding option. For example, to override the inferred [data type][@stdlib/ndarray/dtypes],
|
|
96
96
|
|
|
97
97
|
```javascript
|
|
98
98
|
var zeros = require( '@stdlib/ndarray-zeros' );
|
|
@@ -141,7 +141,7 @@ var zeros = require( '@stdlib/ndarray-zeros' );
|
|
|
141
141
|
var zerosLike = require( '@stdlib/ndarray-zeros-like' );
|
|
142
142
|
|
|
143
143
|
// Get a list of data types:
|
|
144
|
-
var dt = dtypes();
|
|
144
|
+
var dt = dtypes( 'numeric' );
|
|
145
145
|
|
|
146
146
|
// Generate zero-filled arrays...
|
|
147
147
|
var x;
|
|
@@ -209,7 +209,7 @@ See [LICENSE][stdlib-license].
|
|
|
209
209
|
|
|
210
210
|
## Copyright
|
|
211
211
|
|
|
212
|
-
Copyright © 2016-
|
|
212
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
213
213
|
|
|
214
214
|
</section>
|
|
215
215
|
|
|
@@ -222,8 +222,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
222
222
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-zeros-like.svg
|
|
223
223
|
[npm-url]: https://npmjs.org/package/@stdlib/ndarray-zeros-like
|
|
224
224
|
|
|
225
|
-
[test-image]: https://github.com/stdlib-js/ndarray-zeros-like/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
226
|
-
[test-url]: https://github.com/stdlib-js/ndarray-zeros-like/actions/workflows/test.yml?query=branch:v0.
|
|
225
|
+
[test-image]: https://github.com/stdlib-js/ndarray-zeros-like/actions/workflows/test.yml/badge.svg?branch=v0.3.1
|
|
226
|
+
[test-url]: https://github.com/stdlib-js/ndarray-zeros-like/actions/workflows/test.yml?query=branch:v0.3.1
|
|
227
227
|
|
|
228
228
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-zeros-like/main.svg
|
|
229
229
|
[coverage-url]: https://codecov.io/github/stdlib-js/ndarray-zeros-like?branch=main
|
|
@@ -235,8 +235,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
235
235
|
|
|
236
236
|
-->
|
|
237
237
|
|
|
238
|
-
[chat-image]: https://img.shields.io/
|
|
239
|
-
[chat-url]: https://
|
|
238
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
239
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
240
240
|
|
|
241
241
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
242
242
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
1
|
+
"use strict";var q=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var y=q(function(F,g){
|
|
2
|
+
var h=require('@stdlib/assert-is-number/dist').isPrimitive,b=require('@stdlib/assert-is-ndarray-like/dist'),w=require('@stdlib/assert-is-plain-object/dist'),c=require('@stdlib/assert-is-nonnegative-integer-array/dist').primitives,E=require('@stdlib/assert-is-empty-collection/dist'),t=require('@stdlib/assert-has-own-property/dist'),O=require('@stdlib/ndarray-base-shape2strides/dist'),T=require('@stdlib/ndarray-base-strides2offset/dist'),j=require('@stdlib/ndarray-base-buffer/dist'),k=require('@stdlib/ndarray-base-numel/dist'),l=require('@stdlib/ndarray-dtype/dist'),p=require('@stdlib/ndarray-shape/dist'),f=require('@stdlib/ndarray-order/dist'),N=require('@stdlib/ndarray-ctor/dist'),u=require('@stdlib/error-tools-fmtprodmsg/dist');function P(i){var e,a,n,m,s,v,d,o,r;if(!b(i))throw new TypeError(u('0kH5t',i));if(s={},arguments.length>1){if(e=arguments[1],!w(e))throw new TypeError(u('0kH2V',e));if(t(e,"dtype")?a=e.dtype:a=l(i),t(e,"shape")){if(r=e.shape,h(r)&&(r=[r]),!c(r)&&!E(r))throw new TypeError(u('0kHDs',"shape",r))}else r=p(i);t(e,"order")?n=e.order:n=f(i),t(e,"mode")&&(s.mode=e.mode),t(e,"submode")&&(s.submode=e.submode),t(e,"readonly")&&(s.readonly=e.readonly)}else a=l(i),r=p(i),n=f(i);if(m=r.length,m>0?(d=k(r),o=O(r,n)):(d=1,o=[0]),v=j(a,d),v===null)throw new TypeError(u('0kH5L',a));return new N(a,v,r,o,T(r,o),n,s)}g.exports=P
|
|
3
3
|
});var V=y();module.exports=V;
|
|
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) 2022 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Creates a zero-filled ndarray having the same shape and data type as a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output array data type (overrides the input array's inferred data type)\n* @param {string} [options.order] - specifies whether the output array should be 'row-major' (C-style) or 'column-major' (Fortran-style) (overrides the input array's inferred order)\n* @param {(NonNegativeIntegerArray|NonNegativeInteger)} [options.shape] - output array shape (overrides the input array's inferred shape)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only\n* @throws {TypeError} first argument must have a recognized data type\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} `dtype` option must be a supported ndarray data type\n* @throws {TypeError} `order` option must be a supported order\n* @throws {TypeError} `shape` option must be either a nonnegative integer or an array of nonnegative integers\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} ndarray\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns <ndarray>\n*\n* var y = zerosLike( x );\n* // returns <ndarray>\n*\n* var sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = y.dtype;\n* // returns 'float64'\n*/\nfunction zerosLike( x ) {\n\tvar options;\n\tvar dtype;\n\tvar order;\n\tvar ndims;\n\tvar opts;\n\tvar buf;\n\tvar len;\n\tvar st;\n\tvar sh;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\t\tdtype = options.dtype;\n\t\t} else {\n\t\t\tdtype = getDType( x );\n\t\t}\n\t\tif ( hasOwnProp( options, 'shape' ) ) {\n\t\t\tsh = options.shape;\n\t\t\tif (
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAa,QAAS,iCAAkC,EACxDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAiB,QAAS,qCAAsC,EAChEC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAU,QAAS,sBAAuB,EAC1CC,EAAS,QAAS,uBAAwB,EAuC9C,SAASC,EAAWC,EAAI,CACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,
|
|
6
|
-
"names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isPlainObject", "isNonNegativeIntegerArray", "hasOwnProp", "shape2strides", "strides2offset", "buffer", "numel", "getDType", "getShape", "getOrder", "ndarray", "format", "zerosLike", "x", "options", "dtype", "order", "ndims", "opts", "buf", "len", "st", "sh", "main"]
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Creates a zero-filled ndarray having the same shape and data type as a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output array data type (overrides the input array's inferred data type)\n* @param {string} [options.order] - specifies whether the output array should be 'row-major' (C-style) or 'column-major' (Fortran-style) (overrides the input array's inferred order)\n* @param {(NonNegativeIntegerArray|NonNegativeInteger)} [options.shape] - output array shape (overrides the input array's inferred shape)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only\n* @throws {TypeError} first argument must have a recognized data type\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} `dtype` option must be a supported ndarray data type\n* @throws {TypeError} `order` option must be a supported order\n* @throws {TypeError} `shape` option must be either a nonnegative integer or an array of nonnegative integers\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} ndarray\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns <ndarray>\n*\n* var y = zerosLike( x );\n* // returns <ndarray>\n*\n* var sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = y.dtype;\n* // returns 'float64'\n*/\nfunction zerosLike( x ) {\n\tvar options;\n\tvar dtype;\n\tvar order;\n\tvar ndims;\n\tvar opts;\n\tvar buf;\n\tvar len;\n\tvar st;\n\tvar sh;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\t\tdtype = options.dtype;\n\t\t} else {\n\t\t\tdtype = getDType( x );\n\t\t}\n\t\tif ( hasOwnProp( options, 'shape' ) ) {\n\t\t\tsh = options.shape;\n\t\t\tif ( isNumber( sh ) ) {\n\t\t\t\tsh = [ sh ];\n\t\t\t}\n\t\t\tif ( !isNonNegativeIntegerArray( sh ) && !isEmptyCollection( sh ) ) { // eslint-disable-line max-len\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer or an array of nonnegative integers. Option: `%s`.', 'shape', sh ) );\n\t\t\t}\n\t\t} else {\n\t\t\tsh = getShape( x );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\torder = options.order;\n\t\t} else {\n\t\t\torder = getOrder( x );\n\t\t}\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t}\n\t\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\t\topts.submode = options.submode;\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\topts.readonly = options.readonly;\n\t\t}\n\t} else {\n\t\tdtype = getDType( x );\n\t\tsh = getShape( x );\n\t\torder = getOrder( x );\n\t}\n\tndims = sh.length;\n\tif ( ndims > 0 ) {\n\t\tlen = numel( sh );\n\t\tst = shape2strides( sh, 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\tbuf = buffer( dtype, len );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must have a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\treturn new ndarray( dtype, buf, sh, st, strides2offset( sh, st ), order, opts ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = zerosLike;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 a zero-filled ndarray having the same shape and data type as a provided ndarray.\n*\n* @module @stdlib/ndarray-zeros-like\n*\n* @example\n* var zeros = require( '@stdlib/ndarray-zeros' );\n* var zerosLike = require( '@stdlib/ndarray-zeros-like' );\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns <ndarray>\n*\n* var y = zerosLike( x );\n* // returns <ndarray>\n*\n* var sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = y.dtype;\n* // returns 'float64'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAoB,QAAS,oCAAqC,EAClEC,EAAa,QAAS,iCAAkC,EACxDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAiB,QAAS,qCAAsC,EAChEC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAU,QAAS,sBAAuB,EAC1CC,EAAS,QAAS,uBAAwB,EAuC9C,SAASC,EAAWC,EAAI,CACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAee,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,gFAAiFE,CAAE,CAAE,EAGnH,GADAK,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAJ,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAO9G,GALKZ,EAAYY,EAAS,OAAQ,EACjCC,EAAQD,EAAQ,MAEhBC,EAAQR,EAAUM,CAAE,EAEhBX,EAAYY,EAAS,OAAQ,GAKjC,GAJAQ,EAAKR,EAAQ,MACRjB,EAAUyB,CAAG,IACjBA,EAAK,CAAEA,CAAG,GAEN,CAACtB,EAA2BsB,CAAG,GAAK,CAACrB,EAAmBqB,CAAG,EAC/D,MAAM,IAAI,UAAWX,EAAQ,+GAAgH,QAASW,CAAG,CAAE,OAG5JA,EAAKd,EAAUK,CAAE,EAEbX,EAAYY,EAAS,OAAQ,EACjCE,EAAQF,EAAQ,MAEhBE,EAAQP,EAAUI,CAAE,EAEhBX,EAAYY,EAAS,MAAO,IAChCI,EAAK,KAAOJ,EAAQ,MAEhBZ,EAAYY,EAAS,SAAU,IACnCI,EAAK,QAAUJ,EAAQ,SAEnBZ,EAAYY,EAAS,UAAW,IACpCI,EAAK,SAAWJ,EAAQ,SAE1B,MACCC,EAAQR,EAAUM,CAAE,EACpBS,EAAKd,EAAUK,CAAE,EACjBG,EAAQP,EAAUI,CAAE,EAYrB,GAVAI,EAAQK,EAAG,OACNL,EAAQ,GACZG,EAAMd,EAAOgB,CAAG,EAChBD,EAAKlB,EAAemB,EAAIN,CAAM,IAG9BI,EAAM,EACNC,EAAK,CAAE,CAAE,GAEVF,EAAMd,EAAQU,EAAOK,CAAI,EACpBD,IAAQ,KACZ,MAAM,IAAI,UAAWR,EAAQ,kFAAmFI,CAAM,CAAE,EAEzH,OAAO,IAAIL,EAASK,EAAOI,EAAKG,EAAID,EAAIjB,EAAgBkB,EAAID,CAAG,EAAGL,EAAOE,CAAK,CAC/E,CAKAtB,EAAO,QAAUgB,ICzGjB,IAAIW,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isNumber", "isndarrayLike", "isPlainObject", "isNonNegativeIntegerArray", "isEmptyCollection", "hasOwnProp", "shape2strides", "strides2offset", "buffer", "numel", "getDType", "getShape", "getOrder", "ndarray", "format", "zerosLike", "x", "options", "dtype", "order", "ndims", "opts", "buf", "len", "st", "sh", "main"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
/// <reference types="@stdlib/types"/>
|
|
24
24
|
|
|
25
|
-
import { Shape, Order, ndarray, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray,
|
|
25
|
+
import { Shape, Order, ndarray, typedndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, genericndarray, complex128ndarray, complex64ndarray, NumericAndGenericDataType, Mode } from '@stdlib/types/ndarray';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Interface describing function options.
|
|
@@ -216,6 +216,20 @@ interface Uint8COptions extends Options {
|
|
|
216
216
|
dtype: 'uint8c';
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Interface describing function options.
|
|
221
|
+
*/
|
|
222
|
+
interface GenericOptions extends Options {
|
|
223
|
+
/**
|
|
224
|
+
* Underlying data type.
|
|
225
|
+
*
|
|
226
|
+
* ## Notes
|
|
227
|
+
*
|
|
228
|
+
* - This option overrides the input array's inferred data type.
|
|
229
|
+
*/
|
|
230
|
+
dtype: 'generic';
|
|
231
|
+
}
|
|
232
|
+
|
|
219
233
|
/**
|
|
220
234
|
* Interface describing function options.
|
|
221
235
|
*/
|
|
@@ -227,7 +241,7 @@ interface OptionsWithDType extends Options {
|
|
|
227
241
|
*
|
|
228
242
|
* - This option overrides the input array's inferred data type.
|
|
229
243
|
*/
|
|
230
|
-
dtype:
|
|
244
|
+
dtype: NumericAndGenericDataType;
|
|
231
245
|
}
|
|
232
246
|
|
|
233
247
|
/**
|
|
@@ -637,6 +651,43 @@ declare function zerosLike( x: uint8ndarray, options?: Options ): uint8ndarray;
|
|
|
637
651
|
*/
|
|
638
652
|
declare function zerosLike( x: uint8cndarray, options?: Options ): uint8cndarray;
|
|
639
653
|
|
|
654
|
+
/**
|
|
655
|
+
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
656
|
+
*
|
|
657
|
+
* @param x - input array
|
|
658
|
+
* @param options - options
|
|
659
|
+
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
660
|
+
* @param options.shape - output array shape
|
|
661
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
662
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
663
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
664
|
+
* @returns zero-filled array
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
668
|
+
*
|
|
669
|
+
* var x = zeros( [ 2, 2 ], {
|
|
670
|
+
* 'dtype': 'generic'
|
|
671
|
+
* });
|
|
672
|
+
* // returns <ndarray>
|
|
673
|
+
*
|
|
674
|
+
* var sh = x.shape;
|
|
675
|
+
* // returns [ 2, 2 ]
|
|
676
|
+
*
|
|
677
|
+
* var dt = x.dtype;
|
|
678
|
+
* // returns 'generic'
|
|
679
|
+
*
|
|
680
|
+
* var y = zerosLike( x );
|
|
681
|
+
* // returns <ndarray>
|
|
682
|
+
*
|
|
683
|
+
* sh = y.shape;
|
|
684
|
+
* // returns [ 2, 2 ]
|
|
685
|
+
*
|
|
686
|
+
* dt = y.dtype;
|
|
687
|
+
* // returns 'generic'
|
|
688
|
+
*/
|
|
689
|
+
declare function zerosLike( x: genericndarray<any>, options?: Options ): genericndarray<number>;
|
|
690
|
+
|
|
640
691
|
/**
|
|
641
692
|
* Creates a zero-filled double-precision floating-point array having the same shape as a provided input ndarray.
|
|
642
693
|
*
|
|
@@ -1078,7 +1129,7 @@ declare function zerosLike( x: ndarray, options: Uint8Options ): uint8ndarray;
|
|
|
1078
1129
|
declare function zerosLike( x: ndarray, options: Uint8COptions ): uint8cndarray;
|
|
1079
1130
|
|
|
1080
1131
|
/**
|
|
1081
|
-
* Creates a zero-filled array having the same shape
|
|
1132
|
+
* Creates a zero-filled generic array having the same shape as a provided input ndarray.
|
|
1082
1133
|
*
|
|
1083
1134
|
* @param x - input array
|
|
1084
1135
|
* @param options - options
|
|
@@ -1102,7 +1153,47 @@ declare function zerosLike( x: ndarray, options: Uint8COptions ): uint8cndarray;
|
|
|
1102
1153
|
* // returns [ 2, 2 ]
|
|
1103
1154
|
*
|
|
1104
1155
|
* var dt = x.dtype;
|
|
1156
|
+
* // returns 'float64'
|
|
1157
|
+
*
|
|
1158
|
+
* var y = zerosLike( x, {
|
|
1159
|
+
* 'dtype': 'generic'
|
|
1160
|
+
* });
|
|
1161
|
+
* // returns <ndarray>
|
|
1162
|
+
*
|
|
1163
|
+
* sh = y.shape;
|
|
1164
|
+
* // returns [ 2, 2 ]
|
|
1165
|
+
*
|
|
1166
|
+
* dt = y.dtype;
|
|
1105
1167
|
* // returns 'generic'
|
|
1168
|
+
*/
|
|
1169
|
+
declare function zerosLike( x: ndarray, options: GenericOptions ): genericndarray<number>;
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
1173
|
+
*
|
|
1174
|
+
* @param x - input array
|
|
1175
|
+
* @param options - options
|
|
1176
|
+
* @param options.dtype - output array data type
|
|
1177
|
+
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
|
|
1178
|
+
* @param options.shape - output array shape
|
|
1179
|
+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
|
|
1180
|
+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
|
|
1181
|
+
* @param options.readonly - boolean indicating whether an array should be read-only
|
|
1182
|
+
* @returns zero-filled array
|
|
1183
|
+
*
|
|
1184
|
+
* @example
|
|
1185
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1186
|
+
*
|
|
1187
|
+
* var x = zeros( [ 2, 2 ], {
|
|
1188
|
+
* 'dtype': 'float64'
|
|
1189
|
+
* });
|
|
1190
|
+
* // returns <ndarray>
|
|
1191
|
+
*
|
|
1192
|
+
* var sh = x.shape;
|
|
1193
|
+
* // returns [ 2, 2 ]
|
|
1194
|
+
*
|
|
1195
|
+
* var dt = x.dtype;
|
|
1196
|
+
* // returns 'float64'
|
|
1106
1197
|
*
|
|
1107
1198
|
* var y = zerosLike( x );
|
|
1108
1199
|
* // returns <ndarray>
|
|
@@ -1111,7 +1202,7 @@ declare function zerosLike( x: ndarray, options: Uint8COptions ): uint8cndarray;
|
|
|
1111
1202
|
* // returns [ 2, 2 ]
|
|
1112
1203
|
*
|
|
1113
1204
|
* dt = y.dtype;
|
|
1114
|
-
* // returns '
|
|
1205
|
+
* // returns 'float64'
|
|
1115
1206
|
*/
|
|
1116
1207
|
declare function zerosLike( x: ndarray, options?: Options | OptionsWithDType ): typedndarray<number>;
|
|
1117
1208
|
|
package/lib/main.js
CHANGED
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
+
var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
|
|
23
24
|
var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
|
|
24
25
|
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
25
26
|
var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;
|
|
27
|
+
var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );
|
|
26
28
|
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
27
29
|
var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
28
30
|
var strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
|
|
@@ -98,10 +100,10 @@ function zerosLike( x ) {
|
|
|
98
100
|
}
|
|
99
101
|
if ( hasOwnProp( options, 'shape' ) ) {
|
|
100
102
|
sh = options.shape;
|
|
101
|
-
if (
|
|
103
|
+
if ( isNumber( sh ) ) {
|
|
102
104
|
sh = [ sh ];
|
|
103
105
|
}
|
|
104
|
-
if ( !isNonNegativeIntegerArray( sh ) ) {
|
|
106
|
+
if ( !isNonNegativeIntegerArray( sh ) && !isEmptyCollection( sh ) ) { // eslint-disable-line max-len
|
|
105
107
|
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer or an array of nonnegative integers. Option: `%s`.', 'shape', sh ) );
|
|
106
108
|
}
|
|
107
109
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/ndarray-zeros-like",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Create a zero-filled ndarray having the same shape and data type as a provided ndarray.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,20 +30,22 @@
|
|
|
30
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@stdlib/assert-has-own-property": "^0.2.
|
|
34
|
-
"@stdlib/assert-is-
|
|
35
|
-
"@stdlib/assert-is-
|
|
36
|
-
"@stdlib/assert-is-
|
|
37
|
-
"@stdlib/
|
|
38
|
-
"@stdlib/
|
|
39
|
-
"@stdlib/ndarray-base-
|
|
40
|
-
"@stdlib/ndarray-base-
|
|
41
|
-
"@stdlib/ndarray-
|
|
42
|
-
"@stdlib/ndarray-
|
|
43
|
-
"@stdlib/ndarray-
|
|
44
|
-
"@stdlib/ndarray-
|
|
45
|
-
"@stdlib/
|
|
46
|
-
"@stdlib/
|
|
33
|
+
"@stdlib/assert-has-own-property": "^0.2.2",
|
|
34
|
+
"@stdlib/assert-is-empty-collection": "^0.2.3",
|
|
35
|
+
"@stdlib/assert-is-ndarray-like": "^0.2.2",
|
|
36
|
+
"@stdlib/assert-is-nonnegative-integer-array": "^0.2.2",
|
|
37
|
+
"@stdlib/assert-is-number": "^0.2.2",
|
|
38
|
+
"@stdlib/assert-is-plain-object": "^0.2.2",
|
|
39
|
+
"@stdlib/ndarray-base-buffer": "^0.3.0",
|
|
40
|
+
"@stdlib/ndarray-base-numel": "^0.2.2",
|
|
41
|
+
"@stdlib/ndarray-base-shape2strides": "^0.2.2",
|
|
42
|
+
"@stdlib/ndarray-base-strides2offset": "^0.2.2",
|
|
43
|
+
"@stdlib/ndarray-ctor": "^0.2.2",
|
|
44
|
+
"@stdlib/ndarray-dtype": "^0.2.2",
|
|
45
|
+
"@stdlib/ndarray-order": "^0.2.2",
|
|
46
|
+
"@stdlib/ndarray-shape": "^0.2.2",
|
|
47
|
+
"@stdlib/string-format": "^0.2.2",
|
|
48
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.2"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {},
|
|
49
51
|
"engines": {
|