diff --git a/dist/index.js b/dist/index.js index 902c17b..e75cb6a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,18 +1,18 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var E=g(function(De,O){ +"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){ var R=require('@stdlib/constants-float64-pinf/dist'),U=require('@stdlib/math-base-assert-is-integer/dist');function G(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&U(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArrayLikeObject;\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// MODULES //\n\nvar settings = require( '@stdlib/ndarray-defaults' );\n\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'casting': settings.get( 'casting' ),\n\t\t'copy': false,\n\t\t'dtype': settings.get( 'dtypes.default' ),\n\t\t'flatten': true,\n\t\t'mode': settings.get( 'index_mode' ),\n\t\t'ndmin': 0,\n\t\t'order': settings.get( 'order' ),\n\t\t'readonly': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// MAIN //\n\n/**\n* Casts buffer elements by copying those elements to a buffer of another data type.\n*\n* @private\n* @param {(Array|TypedArray|Buffer)} buffer - input buffer\n* @param {NonNegativeInteger} len - number of elements to cast\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output buffer\n*\n* @example\n* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' );\n* // returns [ 1.0, 2.0, 3.0 ]\n*/\nfunction castBuffer( buffer, len, dtype ) {\n\tvar ctor;\n\tvar out;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tif ( dtype === 'generic') {\n\t\tout = [];\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout.push( buffer[ i ] );\n\t\t}\n\t} else if ( dtype === 'binary' ) {\n\t\tout = allocUnsafe( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ];\n\t\t}\n\t} else {\n\t\tout = new ctor( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = castBuffer;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// FUNCTIONS //\n\n/**\n* Copies a \"generic\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction generic( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = [];\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions?\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"binary\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction binary( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = allocUnsafe( len );\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout[ i ] = arr.get( i ); // FIXME: what if `arr` has more than one dimensions?\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"typed\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {Array} output data buffer\n*/\nfunction typed( arr, dtype ) {\n\tvar ctor;\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tlen = arr.length;\n\tout = new ctor( len ); // FIXME: need to account for complex number arrays; in which case, we may want to do something similar to `array/convert`\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout[ i ] = arr.get( i ); // FIXME: what if `arr` has more than one dimensions?\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Copies an ndarray view to a data buffer.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output data buffer\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n*\n* var buffer = [ 1.0, 2.0, 3.0 ];\n* var shape = [ 3 ];\n* var strides = [ -1 ];\n* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' );\n*\n* var b = copyView( vec, 'float64' );\n* // returns [ 3.0, 2.0, 1.0 ]\n*/\nfunction copyView( arr, dtype ) {\n\t// TODO: handle complex number dtypes!!\n\tif ( dtype === 'generic') {\n\t\treturn generic( arr );\n\t}\n\tif ( dtype === 'binary' ) {\n\t\treturn binary( arr );\n\t}\n\treturn typed( arr, dtype );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyView;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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// MAIN //\n\n/**\n* Prepends singleton dimensions in order to satisfy a minimum number of dimensions.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - array dimensions\n* @param {NonNegativeInteger} ndmin - minimum number of dimensions\n* @returns {Array} output shape array\n*/\nfunction expandShape( ndims, shape, ndmin ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < ndmin-ndims; i++ ) {\n\t\tout.push( 1 );\n\t}\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tout.push( shape[ i ] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = expandShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions).\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - expanded array shape\n* @param {Array} strides - strides array\n* @param {string} order - memory layout order\n* @returns {Array} output strides array\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' );\n* // returns [ 1, 1, 1, 2 ]\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' );\n* // returns [ 4, 4, 2, 1 ]\n*/\nfunction expandStrides( ndims, shape, strides, order ) {\n\tvar out;\n\tvar N;\n\tvar s;\n\tvar i;\n\tvar j;\n\n\tN = strides.length;\n\tj = ndims - N;\n\tout = [];\n\tif ( order === 'row-major' ) {\n\t\ts = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( s );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t} else { // column-major\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( 1 );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = expandStrides;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar strides2order = require( '@stdlib/ndarray-base-strides2order' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' );\nvar isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' );\nvar createBuffer = require( '@stdlib/ndarray-base-buffer' );\nvar getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getStrides = require( '@stdlib/ndarray-strides' );\nvar getOffset = require( '@stdlib/ndarray-offset' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar getData = require( '@stdlib/ndarray-data-buffer' );\nvar arrayShape = require( '@stdlib/array-shape' );\nvar flatten = require( '@stdlib/array-base-flatten' );\nvar format = require( '@stdlib/string-format' );\nvar isArrayLikeObject = require( './is_array_like_object.js' );\nvar getDefaults = require( './defaults.js' );\nvar castBuffer = require( './cast_buffer.js' );\nvar copyView = require( './copy_view.js' );\nvar expandShape = require( './expand_shape.js' );\nvar expandStrides = require( './expand_strides.js' );\n\n\n// VARIABLES //\n\nvar defaults = getDefaults();\n\n\n// MAIN //\n\n/**\n* Returns a multidimensional array.\n*\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source\n* @param {Options} [options] - function options\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source\n* @param {string} [options.dtype=\"float64\"] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data)\n* @param {string} [options.order=\"row-major\"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style)\n* @param {NonNegativeIntegerArray} [options.shape] - array 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.copy=false] - boolean indicating whether to copy source data to a new data buffer\n* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources\n* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions\n* @param {string} [options.casting=\"safe\"] - casting rule used to determine what constitutes an acceptable cast\n* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide either an array shape, data source, or both\n* @throws {Error} invalid cast\n* @throws {RangeError} data source must be compatible with specified meta data\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\n*/\nfunction array() {\n\tvar options;\n\tvar strides;\n\tvar buffer;\n\tvar offset;\n\tvar order;\n\tvar dtype;\n\tvar btype;\n\tvar shape;\n\tvar ndims;\n\tvar nopts;\n\tvar opts;\n\tvar osh;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\n\tif ( arguments.length === 1 ) {\n\t\tif ( isArrayLikeObject( arguments[ 0 ] ) ) {\n\t\t\tbuffer = arguments[ 0 ];\n\t\t\toptions = {};\n\t\t} else {\n\t\t\toptions = arguments[ 0 ];\n\t\t\tif ( !isObject( options ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( options, 'buffer' ) ) {\n\t\t\t\tbuffer = options.buffer;\n\t\t\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tbuffer = arguments[ 0 ];\n\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\tthrow new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\t// Note: we ignore whether `options` has a `buffer` property\n\t}\n\tif ( buffer ) {\n\t\tif ( isndarrayLike( buffer ) ) {\n\t\t\tbtype = getDType( buffer );\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getBufferDType( buffer );\n\t\t\tFLG = false;\n\t\t}\n\t}\n\tnopts = {};\n\topts = {};\n\n\t// Validate some options before others...\n\tif ( hasOwnProp( options, 'casting' ) ) {\n\t\topts.casting = options.casting;\n\t\tif ( !isCastingMode( opts.casting ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );\n\t\t}\n\t} else {\n\t\topts.casting = defaults.casting;\n\t}\n\tif ( hasOwnProp( options, 'flatten' ) ) {\n\t\topts.flatten = options.flatten;\n\t\tif ( !isBoolean( opts.flatten ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );\n\t\t}\n\t} else {\n\t\topts.flatten = defaults.flatten;\n\t}\n\tif ( hasOwnProp( options, 'ndmin' ) ) {\n\t\topts.ndmin = options.ndmin;\n\t\tif ( !isNonNegativeInteger( opts.ndmin ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );\n\t\t}\n\t\t// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)\n\t} else {\n\t\topts.ndmin = defaults.ndmin;\n\t}\n\n\t// Validate the remaining options...\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\tdtype = options.dtype;\n\t\tif ( !isDataType( dtype ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) {\n\t\t// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.\n\n\t\t// Only cast generic array data sources when not provided an ndarray...\n\t\tif ( !FLG && btype === 'generic' ) {\n\t\t\tdtype = defaults.dtype;\n\t\t} else {\n\t\t\tdtype = btype;\n\t\t}\n\t} else {\n\t\tdtype = defaults.dtype;\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\torder = options.order;\n\t\tif ( order === 'any' || order === 'same' ) {\n\t\t\tif ( FLG ) {\n\t\t\t\t// If the user indicated that \"any\" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally \"row-major\" or \"column-major\" or configured as such....\n\t\t\t\tif ( order === 'any' ) {\n\t\t\t\t\t// Compute the layout order in order to ascertain whether an ndarray can be considered both \"row-major\" and \"column-major\":\n\t\t\t\t\tord = strides2order( getStrides( buffer ) );\n\n\t\t\t\t\t// If the ndarray can be considered both \"row-major\" and \"column-major\", then use the default order; otherwise, use the ndarray's stated layout order...\n\t\t\t\t\tif ( ord === 3 ) {\n\t\t\t\t\t\torder = defaults.order;\n\t\t\t\t\t} else {\n\t\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Otherwise, use the same order as the provided ndarray...\n\t\t\t\telse if ( order === 'same' ) {\n\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\torder = defaults.order;\n\t\t\t}\n\t\t} else if ( !isOrder( order ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );\n\t\t}\n\t} else {\n\t\torder = defaults.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\tnopts.mode = options.mode;\n\t} else {\n\t\tnopts.mode = defaults.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\tnopts.submode = options.submode;\n\t} else {\n\t\tnopts.submode = [ nopts.mode ];\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\tnopts.readonly = options.readonly;\n\t} else {\n\t\tnopts.readonly = defaults.readonly;\n\t}\n\tif ( hasOwnProp( options, 'copy' ) ) {\n\t\topts.copy = options.copy;\n\t\tif ( !isBoolean( opts.copy ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );\n\t\t}\n\t} else {\n\t\topts.copy = defaults.copy;\n\t}\n\t// If not provided a shape, infer from a provided data source...\n\tif ( hasOwnProp( options, 'shape' ) ) {\n\t\tshape = options.shape;\n\t\tif ( !isArrayLikeObject( shape ) ) { // weak test\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );\n\t\t}\n\t\tndims = shape.length;\n\t\tlen = numel( shape );\n\t} else if ( buffer ) {\n\t\tif ( FLG ) {\n\t\t\tshape = getShape( buffer );\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\n\t\t\tosh = shape; // cache a reference to the inferred shape\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else {\n\t\t\tndims = 1;\n\t\t\tlen = buffer.length;\n\t\t\tshape = [ len ]; // assume a 1-dimensional array (vector)\n\t\t}\n\t} else {\n\t\tthrow new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' );\n\t}\n\t// Adjust the array shape to satisfy the minimum number of dimensions...\n\tif ( ndims < opts.ndmin ) {\n\t\tshape = expandShape( ndims, shape, opts.ndmin );\n\t\tndims = opts.ndmin;\n\t}\n\t// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...\n\tif ( FLG ) {\n\t\tif ( numel( buffer.shape ) !== len ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = copyView( buffer, dtype );\n\t\t} else {\n\t\t\tstrides = getStrides( buffer );\n\t\t\toffset = getOffset( buffer );\n\t\t\tbuffer = getData( buffer );\n\t\t\tif ( strides.length < ndims ) {\n\t\t\t\t// Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset):\n\t\t\t\tstrides = expandStrides( ndims, shape, strides, order );\n\t\t\t}\n\t\t}\n\t} else if ( buffer ) {\n\t\tif ( btype === 'generic' && opts.flatten ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), false );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = castBuffer( buffer, len, dtype );\n\t\t}\n\t} else {\n\t\tbuffer = createBuffer( dtype, len );\n\t}\n\t// If we have yet to determine array strides, we assume that we can compute the strides, along with the index offset, for a **contiguous** data source based solely on the array shape and specified memory layout order...\n\tif ( strides === void 0 ) {\n\t\tstrides = shape2strides( shape, order );\n\t\toffset = strides2offset( shape, strides );\n\t}\n\treturn new ndarray( dtype, buffer, shape, strides, offset, order, nopts );\n}\n\n\n// EXPORTS //\n\nmodule.exports = array;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Multidimensional array.\n*\n* @module @stdlib/ndarray-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EACjDC,EAAY,QAAS,qCAAsC,EAoB/D,SAASC,EAAmBC,EAAQ,CACnC,OACC,OAAOA,GAAU,UACjBA,IAAU,MACV,OAAOA,EAAM,QAAW,UACxBF,EAAWE,EAAM,MAAO,GACxBA,EAAM,QAAU,GAChBA,EAAM,OAASH,CAEjB,CAKAD,EAAO,QAAUG,ICzDjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAenD,SAASC,GAAW,CACnB,MAAO,CACN,QAAWD,EAAS,IAAK,SAAU,EACnC,KAAQ,GACR,MAASA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,EAAO,SAAWU,EACtB,MAAM,IAAI,WAAY,sIAAuI,GAEzJN,IAAUD,GAASK,EAAK,QAC5BR,EAASR,GAAYQ,EAAQU,EAAKP,CAAM,EAE1C,MACCH,EAASrB,GAAcwB,EAAOO,CAAI,EAGnC,OAAKX,IAAY,SAChBA,EAAU7B,GAAemC,EAAOH,CAAM,EACtCD,EAAS9B,GAAgBkC,EAAON,CAAQ,GAElC,IAAIzB,GAAS6B,EAAOH,EAAQK,EAAON,EAASE,EAAQC,EAAOK,CAAM,CACzE,CAKA5C,EAAO,QAAUkC,KCxRjB,IAAIgB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_is_array_like_object", "__commonJSMin", "exports", "module", "PINF", "isInteger", "isArrayLikeObject", "value", "require_defaults", "__commonJSMin", "exports", "module", "settings", "defaults", "require_cast_buffer", "__commonJSMin", "exports", "module", "bufferCtors", "allocUnsafe", "castBuffer", "buffer", "len", "dtype", "ctor", "out", "i", "require_copy_view", "__commonJSMin", "exports", "module", "bufferCtors", "allocUnsafe", "generic", "arr", "len", "out", "i", "binary", "typed", "dtype", "ctor", "copyView", "require_expand_shape", "__commonJSMin", "exports", "module", "expandShape", "ndims", "shape", "ndmin", "out", "require_expand_strides", "__commonJSMin", "exports", "module", "abs", "expandStrides", "ndims", "shape", "strides", "order", "out", "N", "s", "i", "j", "require_main", "__commonJSMin", "exports", "module", "hasOwnProp", "isObject", "isBoolean", "isArray", "isNonNegativeInteger", "isndarrayLike", "shape2strides", "strides2offset", "strides2order", "numel", "ndarray", "isDataType", "isOrder", "isCastingMode", "isAllowedCast", "createBuffer", "getBufferDType", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "arrayShape", "flatten", "format", "isArrayLikeObject", "getDefaults", "castBuffer", "copyView", "expandShape", "expandStrides", "defaults", "array", "options", "strides", "buffer", "offset", "order", "dtype", "btype", "shape", "ndims", "nopts", "opts", "osh", "len", "ord", "FLG", "main"] + "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 PINF = require( '@stdlib/constants-float64-pinf' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests (loosely) if an input value is an array-like object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if an input value is an array-like object\n*\n* @example\n* var bool = isArrayLikeObject( [] );\n* // returns true\n*\n* @example\n* var bool = isArrayLikeObject( '' );\n* // returns false\n*/\nfunction isArrayLikeObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArrayLikeObject;\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// MODULES //\n\nvar settings = require( '@stdlib/ndarray-defaults' );\n\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'casting': settings.get( 'casting' ),\n\t\t'copy': false,\n\t\t'dtype': settings.get( 'dtypes.default' ),\n\t\t'flatten': true,\n\t\t'mode': settings.get( 'index_mode' ),\n\t\t'ndmin': 0,\n\t\t'order': settings.get( 'order' ),\n\t\t'readonly': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// MAIN //\n\n/**\n* Casts buffer elements by copying those elements to a buffer of another data type.\n*\n* @private\n* @param {(Array|TypedArray|Buffer)} buffer - input buffer\n* @param {NonNegativeInteger} len - number of elements to cast\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output buffer\n*\n* @example\n* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' );\n* // returns [ 1.0, 2.0, 3.0 ]\n*/\nfunction castBuffer( buffer, len, dtype ) {\n\tvar ctor;\n\tvar out;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tif ( dtype === 'generic') {\n\t\tout = [];\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout.push( buffer[ i ] );\n\t\t}\n\t} else if ( dtype === 'binary' ) {\n\t\tout = allocUnsafe( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ];\n\t\t}\n\t} else {\n\t\tout = new ctor( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = castBuffer;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getStrides = require( '@stdlib/ndarray-strides' );\nvar getOffset = require( '@stdlib/ndarray-offset' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar getData = require( '@stdlib/ndarray-data-buffer' );\n\n\n// FUNCTIONS //\n\n/**\n* Copies a \"generic\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction generic( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = [];\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"binary\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction binary( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = allocUnsafe( len );\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast a complex-valued ndarray to a \"binary\" ndarray or a double-precision floating-point ndarray to binary, etc)\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"typed\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {Array} output data buffer\n*/\nfunction typed( arr, dtype ) {\n\tvar ctor;\n\tvar len;\n\tvar out;\n\tvar set;\n\tvar fcn;\n\tvar o;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tlen = arr.length;\n\tout = new ctor( len );\n\n\t// If the output data buffer is a complex number array, we need to use accessors...\n\to = arraylike2object( out );\n\tif ( o.accessorProtocol ) {\n\t\tset = o.accessors[ 1 ];\n\t\tfcn = castReturn( wrapper, 1, complexCtors( dtype ) );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tset( out, i, fcn( i ) ); // we're assuming that we're doing something sensible here (e.g., not trying to cast arbitrary objects to complex numbers, etc)\n\t\t}\n\t} else {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast an ndarray containing generic objects to a double-precision floating-point array or a complex-valued ndarray to a real-valued ndarray, etc)\n\t\t}\n\t}\n\treturn out;\n\n\t/**\n\t* Returns the ndarray element specified by a provided linear index.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} i - linear index\n\t* @returns {*} value\n\t*/\n\tfunction wrapper( i ) {\n\t\treturn arr.iget( i );\n\t}\n}\n\n\n// MAIN //\n\n/**\n* Copies an ndarray view to a data buffer.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output data buffer\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n*\n* var buffer = [ 1.0, 2.0, 3.0 ];\n* var shape = [ 3 ];\n* var strides = [ -1 ];\n* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' );\n*\n* var b = copyView( vec, 'float64' );\n* // returns [ 3.0, 2.0, 1.0 ]\n*/\nfunction copyView( arr, dtype ) {\n\tvar x;\n\n\t// Create a new \"base\" view, thus ensuring we have an `.iget` method and associated meta data...\n\tx = new ndarray( getDType( arr ), getData( arr ), getShape( arr ), getStrides( arr ), getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n\n\tif ( dtype === 'generic') {\n\t\treturn generic( x );\n\t}\n\tif ( dtype === 'binary' ) {\n\t\treturn binary( x );\n\t}\n\treturn typed( x, dtype );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyView;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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// MAIN //\n\n/**\n* Prepends singleton dimensions in order to satisfy a minimum number of dimensions.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - array dimensions\n* @param {NonNegativeInteger} ndmin - minimum number of dimensions\n* @returns {Array} output shape array\n*/\nfunction expandShape( ndims, shape, ndmin ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < ndmin-ndims; i++ ) {\n\t\tout.push( 1 );\n\t}\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tout.push( shape[ i ] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = expandShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions).\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - expanded array shape\n* @param {Array} strides - strides array\n* @param {string} order - memory layout order\n* @returns {Array} output strides array\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' );\n* // returns [ 1, 1, 1, 2 ]\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' );\n* // returns [ 4, 4, 2, 1 ]\n*/\nfunction expandStrides( ndims, shape, strides, order ) {\n\tvar out;\n\tvar N;\n\tvar s;\n\tvar i;\n\tvar j;\n\n\tN = strides.length;\n\tj = ndims - N;\n\tout = [];\n\tif ( order === 'row-major' ) {\n\t\ts = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( s );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t} else { // column-major\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( 1 );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = expandStrides;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar strides2order = require( '@stdlib/ndarray-base-strides2order' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' );\nvar isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' );\nvar createBuffer = require( '@stdlib/ndarray-base-buffer' );\nvar getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getStrides = require( '@stdlib/ndarray-strides' );\nvar getOffset = require( '@stdlib/ndarray-offset' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar getData = require( '@stdlib/ndarray-data-buffer' );\nvar arrayShape = require( '@stdlib/array-shape' );\nvar flatten = require( '@stdlib/array-base-flatten' );\nvar format = require( '@stdlib/string-format' );\nvar isArrayLikeObject = require( './is_array_like_object.js' );\nvar getDefaults = require( './defaults.js' );\nvar castBuffer = require( './cast_buffer.js' );\nvar copyView = require( './copy_view.js' );\nvar expandShape = require( './expand_shape.js' );\nvar expandStrides = require( './expand_strides.js' );\n\n\n// VARIABLES //\n\nvar defaults = getDefaults();\n\n\n// MAIN //\n\n/**\n* Returns a multidimensional array.\n*\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source\n* @param {Options} [options] - function options\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source\n* @param {string} [options.dtype=\"float64\"] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data)\n* @param {string} [options.order=\"row-major\"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style)\n* @param {NonNegativeIntegerArray} [options.shape] - array 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.copy=false] - boolean indicating whether to copy source data to a new data buffer\n* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources\n* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions\n* @param {string} [options.casting=\"safe\"] - casting rule used to determine what constitutes an acceptable cast\n* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide either an array shape, data source, or both\n* @throws {Error} invalid cast\n* @throws {RangeError} data source must be compatible with specified meta data\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\n*/\nfunction array() {\n\tvar options;\n\tvar strides;\n\tvar buffer;\n\tvar offset;\n\tvar order;\n\tvar dtype;\n\tvar btype;\n\tvar shape;\n\tvar ndims;\n\tvar nopts;\n\tvar opts;\n\tvar osh;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\n\tif ( arguments.length === 1 ) {\n\t\tif ( isArrayLikeObject( arguments[ 0 ] ) ) {\n\t\t\tbuffer = arguments[ 0 ];\n\t\t\toptions = {};\n\t\t} else {\n\t\t\toptions = arguments[ 0 ];\n\t\t\tif ( !isObject( options ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( options, 'buffer' ) ) {\n\t\t\t\tbuffer = options.buffer;\n\t\t\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tbuffer = arguments[ 0 ];\n\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\tthrow new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\t// Note: we ignore whether `options` has a `buffer` property\n\t}\n\tif ( buffer ) {\n\t\tif ( isndarrayLike( buffer ) ) {\n\t\t\tbtype = getDType( buffer );\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getBufferDType( buffer );\n\t\t\tFLG = false;\n\t\t}\n\t}\n\tnopts = {};\n\topts = {};\n\n\t// Validate some options before others...\n\tif ( hasOwnProp( options, 'casting' ) ) {\n\t\topts.casting = options.casting;\n\t\tif ( !isCastingMode( opts.casting ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );\n\t\t}\n\t} else {\n\t\topts.casting = defaults.casting;\n\t}\n\tif ( hasOwnProp( options, 'flatten' ) ) {\n\t\topts.flatten = options.flatten;\n\t\tif ( !isBoolean( opts.flatten ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );\n\t\t}\n\t} else {\n\t\topts.flatten = defaults.flatten;\n\t}\n\tif ( hasOwnProp( options, 'ndmin' ) ) {\n\t\topts.ndmin = options.ndmin;\n\t\tif ( !isNonNegativeInteger( opts.ndmin ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );\n\t\t}\n\t\t// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)\n\t} else {\n\t\topts.ndmin = defaults.ndmin;\n\t}\n\n\t// Validate the remaining options...\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\tdtype = options.dtype;\n\t\tif ( !isDataType( dtype ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) {\n\t\t// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.\n\n\t\t// Only cast generic array data sources when not provided an ndarray...\n\t\tif ( !FLG && btype === 'generic' ) {\n\t\t\tdtype = defaults.dtype;\n\t\t} else {\n\t\t\tdtype = btype;\n\t\t}\n\t} else {\n\t\tdtype = defaults.dtype;\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\torder = options.order;\n\t\tif ( order === 'any' || order === 'same' ) {\n\t\t\tif ( FLG ) {\n\t\t\t\t// If the user indicated that \"any\" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally \"row-major\" or \"column-major\" or configured as such....\n\t\t\t\tif ( order === 'any' ) {\n\t\t\t\t\t// Compute the layout order in order to ascertain whether an ndarray can be considered both \"row-major\" and \"column-major\":\n\t\t\t\t\tord = strides2order( getStrides( buffer ) );\n\n\t\t\t\t\t// If the ndarray can be considered both \"row-major\" and \"column-major\", then use the default order; otherwise, use the ndarray's stated layout order...\n\t\t\t\t\tif ( ord === 3 ) {\n\t\t\t\t\t\torder = defaults.order;\n\t\t\t\t\t} else {\n\t\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Otherwise, use the same order as the provided ndarray...\n\t\t\t\telse if ( order === 'same' ) {\n\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\torder = defaults.order;\n\t\t\t}\n\t\t} else if ( !isOrder( order ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );\n\t\t}\n\t} else {\n\t\torder = defaults.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\tnopts.mode = options.mode;\n\t} else {\n\t\tnopts.mode = defaults.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\tnopts.submode = options.submode;\n\t} else {\n\t\tnopts.submode = [ nopts.mode ];\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\tnopts.readonly = options.readonly;\n\t} else {\n\t\tnopts.readonly = defaults.readonly;\n\t}\n\tif ( hasOwnProp( options, 'copy' ) ) {\n\t\topts.copy = options.copy;\n\t\tif ( !isBoolean( opts.copy ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );\n\t\t}\n\t} else {\n\t\topts.copy = defaults.copy;\n\t}\n\t// If not provided a shape, infer from a provided data source...\n\tif ( hasOwnProp( options, 'shape' ) ) {\n\t\tshape = options.shape;\n\t\tif ( !isArrayLikeObject( shape ) ) { // weak test\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );\n\t\t}\n\t\tndims = shape.length;\n\t\tlen = numel( shape );\n\t} else if ( buffer ) {\n\t\tif ( FLG ) {\n\t\t\tshape = getShape( buffer );\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\n\t\t\tosh = shape; // cache a reference to the inferred shape\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else {\n\t\t\tndims = 1;\n\t\t\tlen = buffer.length;\n\t\t\tshape = [ len ]; // assume a 1-dimensional array (vector)\n\t\t}\n\t} else {\n\t\tthrow new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' );\n\t}\n\t// Adjust the array shape to satisfy the minimum number of dimensions...\n\tif ( ndims < opts.ndmin ) {\n\t\tshape = expandShape( ndims, shape, opts.ndmin );\n\t\tndims = opts.ndmin;\n\t}\n\t// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...\n\tif ( FLG ) {\n\t\tif ( numel( buffer.shape ) !== len ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = copyView( buffer, dtype );\n\t\t} else {\n\t\t\tstrides = getStrides( buffer );\n\t\t\toffset = getOffset( buffer );\n\t\t\tbuffer = getData( buffer );\n\t\t\tif ( strides.length < ndims ) {\n\t\t\t\t// Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset):\n\t\t\t\tstrides = expandStrides( ndims, shape, strides, order );\n\t\t\t}\n\t\t}\n\t} else if ( buffer ) {\n\t\tif ( btype === 'generic' && opts.flatten ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), false );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = castBuffer( buffer, len, dtype );\n\t\t}\n\t} else {\n\t\tbuffer = createBuffer( dtype, len );\n\t}\n\t// If we have yet to determine array strides, we assume that we can compute the strides, along with the index offset, for a **contiguous** data source based solely on the array shape and specified memory layout order...\n\tif ( strides === void 0 ) {\n\t\tstrides = shape2strides( shape, order );\n\t\toffset = strides2offset( shape, strides );\n\t}\n\treturn new ndarray( dtype, buffer, shape, strides, offset, order, nopts );\n}\n\n\n// EXPORTS //\n\nmodule.exports = array;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Multidimensional array.\n*\n* @module @stdlib/ndarray-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EACjDC,EAAY,QAAS,qCAAsC,EAoB/D,SAASC,EAAmBC,EAAQ,CACnC,OACC,OAAOA,GAAU,UACjBA,IAAU,MACV,OAAOA,EAAM,QAAW,UACxBF,EAAWE,EAAM,MAAO,GACxBA,EAAM,QAAU,GAChBA,EAAM,OAASH,CAEjB,CAKAD,EAAO,QAAUG,ICzDjB,IAAAE,EAAAC,EAAA,SAA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5C,EAAO,QAAUkC,KCxRjB,IAAIgB,GAAO,IAKX,OAAO,QAAUA", + "names": ["require_is_array_like_object", "__commonJSMin", "exports", "module", "PINF", "isInteger", "isArrayLikeObject", "value", "require_defaults", "__commonJSMin", "exports", "module", "settings", "defaults", "require_cast_buffer", "__commonJSMin", "exports", "module", "bufferCtors", "allocUnsafe", "castBuffer", "buffer", "len", "dtype", "ctor", "out", "i", "require_copy_view", "__commonJSMin", "exports", "module", "arraylike2object", "castReturn", "complexCtors", "bufferCtors", "allocUnsafe", "ndarray", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "generic", "arr", "len", "out", "i", "binary", "typed", "dtype", "ctor", "set", "fcn", "o", "wrapper", "copyView", "x", "require_expand_shape", "__commonJSMin", "exports", "module", "expandShape", "ndims", "shape", "ndmin", "out", "require_expand_strides", "__commonJSMin", "exports", "module", "abs", "expandStrides", "ndims", "shape", "strides", "order", "out", "N", "s", "i", "j", "require_main", "__commonJSMin", "exports", "module", "hasOwnProp", "isObject", "isBoolean", "isArray", "isNonNegativeInteger", "isndarrayLike", "shape2strides", "strides2offset", "strides2order", "numel", "ndarray", "isDataType", "isOrder", "isCastingMode", "isAllowedCast", "createBuffer", "getBufferDType", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "arrayShape", "flatten", "format", "isArrayLikeObject", "getDefaults", "castBuffer", "copyView", "expandShape", "expandStrides", "defaults", "array", "options", "strides", "buffer", "offset", "order", "dtype", "btype", "shape", "ndims", "nopts", "opts", "osh", "len", "ord", "FLG", "main"] } diff --git a/lib/copy_view.js b/lib/copy_view.js index b5dd747..4c40a44 100644 --- a/lib/copy_view.js +++ b/lib/copy_view.js @@ -20,8 +20,18 @@ // MODULES // +var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); +var castReturn = require( '@stdlib/complex-base-cast-return' ); +var complexCtors = require( '@stdlib/complex-ctors' ); var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); +var ndarray = require( '@stdlib/ndarray-base-ctor' ); +var getDType = require( '@stdlib/ndarray-dtype' ); +var getShape = require( '@stdlib/ndarray-shape' ); +var getStrides = require( '@stdlib/ndarray-strides' ); +var getOffset = require( '@stdlib/ndarray-offset' ); +var getOrder = require( '@stdlib/ndarray-order' ); +var getData = require( '@stdlib/ndarray-data-buffer' ); // FUNCTIONS // @@ -41,7 +51,7 @@ function generic( arr ) { len = arr.length; out = []; for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? + out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays } return out; } @@ -61,7 +71,7 @@ function binary( arr ) { len = arr.length; out = allocUnsafe( len ); for ( i = 0; i < len; i++ ) { - out[ i ] = arr.get( i ); // FIXME: what if `arr` has more than one dimensions? + out[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) } return out; } @@ -78,15 +88,40 @@ function typed( arr, dtype ) { var ctor; var len; var out; + var set; + var fcn; + var o; var i; ctor = bufferCtors( dtype ); len = arr.length; - out = new ctor( len ); // FIXME: need to account for complex number arrays; in which case, we may want to do something similar to `array/convert` - for ( i = 0; i < len; i++ ) { - out[ i ] = arr.get( i ); // FIXME: what if `arr` has more than one dimensions? + out = new ctor( len ); + + // If the output data buffer is a complex number array, we need to use accessors... + o = arraylike2object( out ); + if ( o.accessorProtocol ) { + set = o.accessors[ 1 ]; + fcn = castReturn( wrapper, 1, complexCtors( dtype ) ); + for ( i = 0; i < len; i++ ) { + set( out, i, fcn( i ) ); // we're assuming that we're doing something sensible here (e.g., not trying to cast arbitrary objects to complex numbers, etc) + } + } else { + for ( i = 0; i < len; i++ ) { + out[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast an ndarray containing generic objects to a double-precision floating-point array or a complex-valued ndarray to a real-valued ndarray, etc) + } } return out; + + /** + * Returns the ndarray element specified by a provided linear index. + * + * @private + * @param {NonNegativeInteger} i - linear index + * @returns {*} value + */ + function wrapper( i ) { + return arr.iget( i ); + } } @@ -112,14 +147,18 @@ function typed( arr, dtype ) { * // returns [ 3.0, 2.0, 1.0 ] */ function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! + var x; + + // Create a new "base" view, thus ensuring we have an `.iget` method and associated meta data... + x = new ndarray( getDType( arr ), getData( arr ), getShape( arr ), getStrides( arr ), getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len + if ( dtype === 'generic') { - return generic( arr ); + return generic( x ); } if ( dtype === 'binary' ) { - return binary( arr ); + return binary( x ); } - return typed( arr, dtype ); + return typed( x, dtype ); } diff --git a/package.json b/package.json index 625db17..cb41c67 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "url": "https://github.com/stdlib-js/stdlib/issues" }, "dependencies": { + "@stdlib/array-base-arraylike2object": "^0.1.0", "@stdlib/array-base-flatten": "^0.1.0", "@stdlib/array-shape": "^0.1.0", "@stdlib/assert-has-own-property": "^0.1.1", @@ -46,6 +47,8 @@ "@stdlib/assert-is-nonnegative-integer": "^0.1.0", "@stdlib/assert-is-plain-object": "^0.1.1", "@stdlib/buffer-alloc-unsafe": "^0.1.0", + "@stdlib/complex-base-cast-return": "^0.1.0", + "@stdlib/complex-ctors": "^0.1.1", "@stdlib/constants-float64-pinf": "^0.1.1", "@stdlib/math-base-assert-is-integer": "^0.1.1", "@stdlib/math-base-special-abs": "^0.1.1", @@ -56,6 +59,7 @@ "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-buffer-ctors": "^0.1.0", "@stdlib/ndarray-base-buffer-dtype": "^0.1.0", + "@stdlib/ndarray-base-ctor": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-strides2offset": "^0.1.1",