-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.mjs.map
1 lines (1 loc) · 6.25 KB
/
index.mjs.map
1
{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"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\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { primitives as isNonNegativeIntegerArray } from '@stdlib/assert-is-nonnegative-integer-array';\nimport isEmptyCollection from '@stdlib/assert-is-empty-collection';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport numel from '@stdlib/ndarray-base-numel';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getOrder from '@stdlib/ndarray-order';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport emptyArray from '@stdlib/array-empty';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Creates an uninitialized 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* @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* import zeros from '@stdlib/ndarray-zeros';\n*\n* var x = zeros( [ 2, 2 ] );\n* // returns <ndarray>\n*\n* var y = emptyLike( 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 emptyLike( 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( '1dZ5t', 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( '1dZ2V', 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( '1dZDs', '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} 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\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, sh, st, strides2offset( sh, st ), order, opts ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default emptyLike;\n"],"names":["emptyLike","x","options","dtype","order","opts","buf","len","st","sh","isndarrayLike","TypeError","format","arguments","length","isPlainObject","hasOwnProp","getDType","shape","isNumber","isNonNegativeIntegerArray","isEmptyCollection","getShape","getOrder","mode","submode","numel","shape2strides","allocUnsafe","emptyArray","ndarray","strides2offset"],"mappings":";;2gDA2EA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeT,GACpB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAGvC,GADAI,EAAO,CAAA,EACFQ,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNb,EAAUW,UAAW,IAEpB,MAAM,IAAIF,UAAWC,EAAQ,QAASV,IAOvC,GAJCC,EADIa,EAAYd,EAAS,SACjBA,EAAQC,MAERc,EAAUhB,GAEde,EAAYd,EAAS,UAKzB,GAJAO,EAAKP,EAAQgB,MACRC,EAAUV,KACdA,EAAK,CAAEA,KAEFW,EAA2BX,KAASY,EAAmBZ,GAC5D,MAAM,IAAIE,UAAWC,EAAQ,QAAS,QAASH,SAGhDA,EAAKa,EAAUrB,GAGfG,EADIY,EAAYd,EAAS,SACjBA,EAAQE,MAERmB,EAAUtB,GAEde,EAAYd,EAAS,UACzBG,EAAKmB,KAAOtB,EAAQsB,MAEhBR,EAAYd,EAAS,aACzBG,EAAKoB,QAAUvB,EAAQuB,QAE1B,MACEtB,EAAQc,EAAUhB,GAClBQ,EAAKa,EAAUrB,GACfG,EAAQmB,EAAUtB,GAgBnB,OAdQQ,EAAGK,OACE,GACZP,EAAMmB,EAAOjB,GACbD,EAAKmB,EAAelB,EAAIL,KAGxBG,EAAM,EACNC,EAAK,CAAE,IAGPF,EADc,WAAVH,EACEyB,EAAarB,GAEbsB,EAAYtB,EAAKJ,GAEjB,IAAI2B,EAAS3B,EAAOG,EAAKG,EAAID,EAAIuB,EAAgBtB,EAAID,GAAMJ,EAAOC,EAC1E"}